Skip to content

Commit

Permalink
feat(admin): add patch comment process
Browse files Browse the repository at this point in the history
  • Loading branch information
lizheming committed Dec 5, 2020
1 parent 87dac96 commit bdfabd5
Showing 1 changed file with 61 additions and 27 deletions.
88 changes: 61 additions & 27 deletions packages/admin/src/pages/manage-comments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ export default function() {
return {...state, ...action};
}, {owner: 'all', status: 'approved', keyword: ''});
const [cmtHandler, setCmtHandler] = useState({});
const [actDropStatus, setActDropStatus] = useState(false);
const [commentIds, setCommentIds] = useState([]);

useEffect(() => {
getCommentList({page: list.page, filter}).then(data => setList({...list, ...data}));
getCommentList({page: list.page, filter}).then(data => {
setList({...list, ...data});
setCommentIds([]);
});
}, [filter, list.page]);

const createActions = comment => ([
Expand All @@ -50,6 +55,12 @@ export default function() {
list.data = list.data.filter(({objectId}) => objectId !== comment.objectId);
list.spamCount -= 1;
setList({...list});
} else {
await Promise.all(commentIds.map(objectId => updateComment(objectId, {status: 'approved'})));
getCommentList({page: list.page, filter}).then(data => {
setList({...list, ...data});
setCommentIds([]);
});
}
}
},
Expand All @@ -64,6 +75,12 @@ export default function() {
list.data = list.data.filter(({objectId}) => objectId !== comment.objectId);
list.spamCount += 1;
setList({...list});
} else {
await Promise.all(commentIds.map(objectId => updateComment(objectId, {status: 'spam'})));
getCommentList({page: list.page, filter}).then(data => {
setList({...list, ...data});
setCommentIds([]);
});
}
}
},
Expand Down Expand Up @@ -102,9 +119,18 @@ export default function() {
if(!confirm(text)) {
return;
}
await deleteComment(comment.objectId);
list.data = list.data.filter(({objectId}) => objectId !== comment.objectId);
setList({...list});

if(comment) {
await deleteComment(comment.objectId);
list.data = list.data.filter(({objectId}) => objectId !== comment.objectId);
setList({...list});
} else {
await Promise.all(commentIds.map(deleteComment));
getCommentList({page: list.page, filter}).then(data => {
setList({...list, ...data});
setCommentIds([]);
});
}
}
}
].filter(({show}) => show));
Expand Down Expand Up @@ -134,6 +160,7 @@ export default function() {
setCmtHandler({});
}

const allSelected = list.data.length && list.data.every(({objectId}) => commentIds.includes(objectId));
return (
<>
<Header />
Expand Down Expand Up @@ -167,23 +194,38 @@ export default function() {

<div className="typecho-list-operate clearfix">
<form method="get">
{/* <div className="operate">
<div className="operate">
<label>
<i className="sr-only">全选</i>
<input type="checkbox" className="typecho-table-select-all" />
<input
type="checkbox"
className="typecho-table-select-all"
checked={allSelected}
onChange={_ => setCommentIds(allSelected ? [] : list.data.map(({objectId}) => objectId))}
/>
</label>
<div className="btn-group btn-drop">
<button className="btn dropdown-toggle btn-s" type="button"><i className="sr-only">操作</i>选中项 <i className="i-caret-down"></i></button>
<ul className="dropdown-menu">
<button
className="btn dropdown-toggle btn-s"
type="button" onClick={_ => setActDropStatus(!actDropStatus)}
>
<i className="sr-only">操作</i>选中项 <i className="i-caret-down"></i>
</button>
<ul
className="dropdown-menu"
style={{display: actDropStatus ? 'block' : 'none'}}
onClick={_ => setActDropStatus(false)}
>
{createActions().map(({key, name, action}) =>
<li key={key}><a href="javascript:void(0)" onClick={action}>{name}</a></li>
)}
</ul>
{filter.status === 'spam' ? (
&nbsp;
{/* {filter.status === 'spam' ? (
<button lang="你确认要删除所有垃圾评论吗?" className="btn btn-s btn-warn btn-operate">删除所有垃圾评论</button>
) : null}
) : null} */}
</div>
</div> */}
</div>

<div className="search" role="search">
<input
Expand All @@ -192,6 +234,7 @@ export default function() {
className="text-s"
placeholder="请输入关键字"
/>
&nbsp;
<button
type="submit"
className="btn btn-s"
Expand Down Expand Up @@ -291,7 +334,12 @@ export default function() {
) : (
<tr id={`comment-${objectId}`} key={objectId}>
<td valign="top">
<input type="checkbox" value={objectId} disabled/>
<input
type="checkbox"
value={objectId}
checked={commentIds.includes(objectId)}
onChange={_ => setCommentIds(commentIds.includes(objectId) ? commentIds.filter(id => id !== objectId) : [...commentIds, objectId])}
/>
</td>
<td valign="top">
<div className="comment-avatar">
Expand Down Expand Up @@ -332,7 +380,7 @@ export default function() {
e.preventDefault();
cmtReply({rid, pid: objectId, url, at: nick})
}}
>回复</button>
>回复</button> &nbsp;
<button
type="button"
className="btn btn-s cancel"
Expand Down Expand Up @@ -361,20 +409,6 @@ export default function() {

<div className="typecho-list-operate clearfix">
<form method="get">
{/* <div className="operate">
<label><i className="sr-only">全选</i><input type="checkbox" className="typecho-table-select-all" /></label>
<div className="btn-group btn-drop">
<button className="btn dropdown-toggle btn-s" type="button"><i className="sr-only">操作</i>选中项 <i className="i-caret-down"></i></button>
<ul className="dropdown-menu">
{createActions().map(({key, name, action}) =>
<li key={key}><a href="javascript:void(0)" onClick={action}>{name}</a></li>
)}
</ul>
{filter.status === 'spam' ? (
<button lang="你确认要删除所有垃圾评论吗?" className="btn btn-s btn-warn btn-operate">删除所有垃圾评论</button>
) : null}
</div>
</div> */}
<Paginator
current={list.page}
total={list.totalPages}
Expand Down

0 comments on commit bdfabd5

Please sign in to comment.