diff --git a/packages/app/src/components/PostCard/index.jsx b/packages/app/src/components/PostCard/index.jsx
index f2ed249c..6d294dc0 100644
--- a/packages/app/src/components/PostCard/index.jsx
+++ b/packages/app/src/components/PostCard/index.jsx
@@ -1,17 +1,23 @@
import React from "react"
import * as antd from "antd"
+import { Swiper } from "antd-mobile"
import { Icons } from "components/Icons"
import { LikeButton } from "components"
import moment from "moment"
import classnames from "classnames"
-
-import { User } from "models"
+import loadable from "@loadable/component"
import CSSMotion from "rc-animate/lib/CSSMotion"
import useLayoutEffect from "rc-util/lib/hooks/useLayoutEffect"
import "./index.less"
+const ContentFailed = () => {
+ return
@@ -101,10 +198,25 @@ function PostActions(props) {
- {props.isSelf &&
}
@@ -112,36 +224,59 @@ function PostActions(props) {
export class PostCard extends React.Component {
state = {
loading: true,
- selfId: null,
- data: this.props.data,
+ likes: this.props.data.likes,
+ comments: this.props.data.comments,
}
api = window.app.request
componentDidMount = async () => {
- const selfId = await User.selfUserId()
-
- window.app.ws.listen(`like.post.${this.props.data._id}`, async (data) => {
- await this.setState({ data })
+ window.app.ws.listen(`post.like.${this.props.data._id}`, async (data) => {
+ await this.setState({ likes: data })
})
- window.app.ws.listen(`unlike.post.${this.props.data._id}`, async (data) => {
- await this.setState({ data })
+ window.app.ws.listen(`post.unlike.${this.props.data._id}`, async (data) => {
+ await this.setState({ likes: data })
+ })
+
+ window.app.ws.listen(`post.comment.${this.props.data._id}`, async (data) => {
+ await this.setState({ comments: data })
+ })
+ window.app.ws.listen(`post.uncomment.${this.props.data._id}`, async (data) => {
+ await this.setState({ comments: data })
})
await this.setState({
- selfId,
loading: false
})
}
+ onClickDelete = async () => {
+ const result = await this.api.delete.post({
+ post_id: this.props.data._id,
+ }).catch(error => {
+ console.error(error)
+ antd.message.error(error.message)
+
+ return {
+ success: false,
+ }
+ })
+
+ if (result.success) {
+ if (typeof this.props.close === "function") {
+ this.props.close()
+ }
+ }
+ }
+
onClickLike = async (to) => {
let result = false
if (to) {
- const apiResult = await await this.api.put.like({ post_id: this.props.data._id })
+ const apiResult = await this.api.put.like({ post_id: this.props.data._id })
result = apiResult.success
} else {
- const apiResult = await await this.api.put.unlike({ post_id: this.props.data._id })
+ const apiResult = await this.api.put.unlike({ post_id: this.props.data._id })
result = apiResult.success
}
@@ -149,15 +284,15 @@ export class PostCard extends React.Component {
}
onClickSave = async () => {
- // TODO: save post
+ // TODO
+ }
+
+ onClickEdit = async () => {
+ // TODO
}
hasLiked = () => {
- return this.state.data.likes.some(user_id => user_id === this.state.selfId)
- }
-
- isSelf = () => {
- return this.state.selfId === this.state.data.user._id
+ return this.state.likes.some((user_id) => user_id === this.props.selfId)
}
render() {
@@ -176,13 +311,11 @@ export class PostCard extends React.Component {
this.onClickLike(false)}
- onClickSave={this.onClickSave}
- likes={this.state.data.likes.length}
- comments={this.state.data.comments.length}
+ likes={this.state.likes.length}
+ comments={this.state.comments.length}
/>
@@ -192,26 +325,26 @@ export class PostCard extends React.Component {