From 4fbc3a743290fde54057ec279b50be4f0078af56 Mon Sep 17 00:00:00 2001 From: Robin MacPherson Date: Thu, 11 Jan 2024 07:48:08 -0800 Subject: [PATCH] FIx post deletion --- .../web/components/Dashboard/Post/Post.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/web/components/Dashboard/Post/Post.tsx b/packages/web/components/Dashboard/Post/Post.tsx index cf923616..2e2dd4d7 100644 --- a/packages/web/components/Dashboard/Post/Post.tsx +++ b/packages/web/components/Dashboard/Post/Post.tsx @@ -255,7 +255,8 @@ const Post = ({ post, currentUser, refetch }: PostProps) => { toast.success(t('deletePostSuccess')) Router.push('/my-posts') }, - onError: () => { + onError: (err) => { + console.error(err) toast.error(t('deletePostError')) }, update: (cache, { data }) => { @@ -263,8 +264,19 @@ const Post = ({ post, currentUser, refetch }: PostProps) => { if (dp?.id && dp?.__typename) { cache.modify({ fields: { - posts(existingPosts = []): PostModel[] { - return existingPosts.filter((p: any) => p.__ref !== `${dp.__typename}:${dp.id}`) + posts(existingPosts) { + if (existingPosts?.posts) { + const filteredPosts = existingPosts.posts.filter( + (p: any) => p.__ref !== `${dp.__typename}:${dp.id}`, + ) + return { + ...existingPosts, + posts: filteredPosts, + count: filteredPosts.length, + } + } else { + return existingPosts + } }, }, })