import './review.css'; import { Component } from 'react'; import UserControl from '../../components/UserControl/UserControl'; import { images } from '../../resources.json'; import { get, post } from '../../helper/axios'; import { apis } from '../../helper/apis'; import { alert, confirmWithClose } from '../../helper/alert'; import { UserContext } from '../../helper/Context'; import Spinner from '../../components/Spinner/Spinner'; export class ReviewContainer extends Component { static contextType = UserContext; fetched = false; constructor(props) { super(props); this.state = { posts: [], fetchingPosts: false, reviewingNow: 0, actionPerforming: 0 }; } componentDidMount() { if (this.context.userData?.role === 2) this.fetchPosts(); } componentDidUpdate() { if (this.context.userData?.role === 2 && !this.fetched) this.fetchPosts(); } fetchPosts() { this.fetched = true; this.setState({ fetchingPosts: true }); get(apis.listNotReviewed).then(({ data, status, networkStatus }) => { this.setState({ fetchingPosts: false }); if (networkStatus !== 200) return; if (!status) return alert('拉取审核列表失败:' + data + ',请刷新重试'); this.setState({ posts: data }); }); } async review(accepted) { // 哇提示语怎么这么生硬啊 if (!await confirmWithClose(`
`)) return; const { posts, reviewingNow } = this.state; const { id } = posts[reviewingNow]; this.setState({ actionPerforming: accepted ? 1 : 2 }); post(apis.setStatus, { id, status: accepted ? 2 : 3 }).then(({ data, status, networkStatus }) => { this.setState({ actionPerforming: 0 }); if (networkStatus !== 200) return; if (!status) return alert('提交审核失败:' + data + ',请稍后重试'); if (this.state.reviewingNow === this.state.posts.length - 1) this.fetchPosts(); else this.setState({ reviewingNow: this.state.reviewingNow + 1 }); }); } render() { return ( ); } }