use PostModel

This commit is contained in:
SrGooglo 2022-12-09 12:27:31 +00:00
parent 7fbc988211
commit b7f41019a6
2 changed files with 9 additions and 7 deletions

View File

@ -6,6 +6,8 @@ import humanSize from "@tsmx/human-readable"
import { Icons } from "components/Icons"
import PostModel from "models/post"
import "./index.less"
const DEFAULT_POST_POLICY = {
@ -43,7 +45,7 @@ export default (props) => {
setPostingPolicy(policy)
}
const submit = () => {
const submit = async () => {
if (!canSubmit()) return
setLoading(true)
@ -56,7 +58,7 @@ export default (props) => {
timestamp: DateTime.local().toISO(),
}
const response = api.post.post(payload).catch(error => {
const response = await PostModel.create(payload).catch(error => {
console.error(error)
antd.message.error(error)

View File

@ -3,6 +3,8 @@ import * as antd from "antd"
import { Icons } from "components/Icons"
import { PostCard, LoadMore } from "components"
import PostModel from "models/post"
import "./index.less"
const LoadingComponent = () => {
@ -26,8 +28,6 @@ export default class PostsLists extends React.Component {
currentIndex: 0,
}
api = window.app.api.withEndpoints()
listRef = React.createRef()
componentDidMount = async () => {
@ -87,7 +87,7 @@ export default class PostsLists extends React.Component {
}
onLikePost = async (data) => {
let result = await this.api.post.toogleLike({ post_id: data._id }).catch(() => {
let result = await PostModel.toogleLike({ post_id: data._id }).catch(() => {
antd.message.error("Failed to like post")
return false
@ -97,7 +97,7 @@ export default class PostsLists extends React.Component {
}
onSavePost = async (data) => {
let result = await this.api.post.postToogleSave({ post_id: data._id }).catch(() => {
let result = await PostModel.toogleSave({ post_id: data._id }).catch(() => {
antd.message.error("Failed to save post")
return false
@ -114,7 +114,7 @@ export default class PostsLists extends React.Component {
okType: "danger",
cancelText: "No",
onOk: async () => {
await this.api.delete.post({ post_id: data._id }).catch(() => {
await PostModel.deletePost({ post_id: data._id }).catch(() => {
antd.message.error("Failed to delete post")
})
},