mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
use PostModel
This commit is contained in:
parent
7fbc988211
commit
b7f41019a6
@ -6,6 +6,8 @@ import humanSize from "@tsmx/human-readable"
|
|||||||
|
|
||||||
import { Icons } from "components/Icons"
|
import { Icons } from "components/Icons"
|
||||||
|
|
||||||
|
import PostModel from "models/post"
|
||||||
|
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
|
|
||||||
const DEFAULT_POST_POLICY = {
|
const DEFAULT_POST_POLICY = {
|
||||||
@ -43,7 +45,7 @@ export default (props) => {
|
|||||||
setPostingPolicy(policy)
|
setPostingPolicy(policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
const submit = () => {
|
const submit = async () => {
|
||||||
if (!canSubmit()) return
|
if (!canSubmit()) return
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@ -56,7 +58,7 @@ export default (props) => {
|
|||||||
timestamp: DateTime.local().toISO(),
|
timestamp: DateTime.local().toISO(),
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = api.post.post(payload).catch(error => {
|
const response = await PostModel.create(payload).catch(error => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
antd.message.error(error)
|
antd.message.error(error)
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ import * as antd from "antd"
|
|||||||
import { Icons } from "components/Icons"
|
import { Icons } from "components/Icons"
|
||||||
import { PostCard, LoadMore } from "components"
|
import { PostCard, LoadMore } from "components"
|
||||||
|
|
||||||
|
import PostModel from "models/post"
|
||||||
|
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
|
|
||||||
const LoadingComponent = () => {
|
const LoadingComponent = () => {
|
||||||
@ -26,8 +28,6 @@ export default class PostsLists extends React.Component {
|
|||||||
currentIndex: 0,
|
currentIndex: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
api = window.app.api.withEndpoints()
|
|
||||||
|
|
||||||
listRef = React.createRef()
|
listRef = React.createRef()
|
||||||
|
|
||||||
componentDidMount = async () => {
|
componentDidMount = async () => {
|
||||||
@ -87,7 +87,7 @@ export default class PostsLists extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onLikePost = async (data) => {
|
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")
|
antd.message.error("Failed to like post")
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -97,7 +97,7 @@ export default class PostsLists extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSavePost = async (data) => {
|
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")
|
antd.message.error("Failed to save post")
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -114,7 +114,7 @@ export default class PostsLists extends React.Component {
|
|||||||
okType: "danger",
|
okType: "danger",
|
||||||
cancelText: "No",
|
cancelText: "No",
|
||||||
onOk: async () => {
|
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")
|
antd.message.error("Failed to delete post")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user