Skip to content

Commit

Permalink
Merge pull request #885 from Journaly/suggestions-bug-fix
Browse files Browse the repository at this point in the history
πŸ₯πŸž Fix Post Deletion Bug πŸ’₯
  • Loading branch information
robin-macpherson authored Jan 11, 2024
2 parents 64fa007 + 4fbc3a7 commit 76e3262
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/web/components/Dashboard/Post/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,28 @@ 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 }) => {
const dp = data?.deletePost
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
}
},
},
})
Expand Down

1 comment on commit 76e3262

@vercel
Copy link

@vercel vercel bot commented on 76e3262 Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.