From 7ba41a30859f3e539cebdb5098bb43f6c4618110 Mon Sep 17 00:00:00 2001 From: Snowykami Date: Thu, 25 Sep 2025 12:46:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=B8=96=E5=AD=90?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=A0=E9=99=A4=E5=B8=96=E5=AD=90=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=B8=96=E5=AD=90=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/console/post-manage/index.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/web/src/components/console/post-manage/index.tsx b/web/src/components/console/post-manage/index.tsx index 3de8e75..a8064eb 100644 --- a/web/src/components/console/post-manage/index.tsx +++ b/web/src/components/console/post-manage/index.tsx @@ -58,6 +58,10 @@ export function PostManage() { setPosts((prev) => prev.map((p) => (p.id === post.id ? { ...p, ...post } : p))); }, [setPosts]); + const onPostDelete = useCallback(({ postId }: { postId: number }) => { + setPosts((prev) => prev.filter((p) => p.id !== postId)); + }, [setPosts]); + const onOrderChange = useCallback(({ orderBy, desc }: { orderBy: OrderBy; desc: boolean }) => { setOrderBy(orderBy); setDesc(desc); @@ -82,7 +86,7 @@ export function PostManage() { {posts.map(post =>
- +
)}
@@ -92,7 +96,7 @@ export function PostManage() {
; } -function PostItem({ post, onPostUpdate }: { post: Post, onPostUpdate?: ({ post }: { post: Partial & Pick }) => void }) { +function PostItem({ post, onPostUpdate, onPostDelete }: { post: Post, onPostUpdate: ({ post }: { post: Partial & Pick }) => void ,onPostDelete: ({ postId }: { postId: number }) => void}) { const commonT = useTranslations("Common"); const postT = useTranslations("Metrics"); const stateT = useTranslations("State"); @@ -120,14 +124,14 @@ function PostItem({ post, onPostUpdate }: { post: Post, onPostUpdate?: ({ post } - + ) } -function PostDropdownMenu({ post, onPostUpdate }: { post: Post, onPostUpdate?: ({ post }: { post: Partial & Pick }) => void }) { +function PostDropdownMenu({ post, onPostUpdate, onPostDelete }: { post: Post, onPostUpdate: ({ post }: { post: Partial & Pick }) => void, onPostDelete: ({ postId }: { postId: number }) => void }) { const operationT = useTranslations("Operation"); const clickToPostEdit = useToEditPost(); const clickToPost = useToPost(); @@ -137,7 +141,7 @@ function PostDropdownMenu({ post, onPostUpdate }: { post: Post, onPostUpdate?: ( updatePost({ post: { ...post, isPrivate: !post.isPrivate } }) .then(() => { toast.success(operationT("update_success")); - onPostUpdate?.({ post: { id: post.id, isPrivate: !post.isPrivate } }); + onPostUpdate({ post: { id: post.id, isPrivate: !post.isPrivate } }); }) .catch(() => { toast.error(operationT("update_failed")); @@ -148,7 +152,7 @@ function PostDropdownMenu({ post, onPostUpdate }: { post: Post, onPostUpdate?: ( deletePost({ id: post.id }) .then(() => { toast.success(operationT("delete_success")); - onPostUpdate?.({ post: { id: post.id } }); + onPostDelete({ postId: post.id }); }) .catch(() => { toast.error(operationT("delete_failed"));