From 3c4af82c52d1bf1c1eb1dd75fba806409d306aaa Mon Sep 17 00:00:00 2001 From: Sahil Garg Date: Wed, 17 Jun 2026 15:58:09 +0530 Subject: [PATCH] fix: comments number not updating is now updating mirroring the pattern of likes. --- platforms/pictique/client/src/lib/stores/comments.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/platforms/pictique/client/src/lib/stores/comments.ts b/platforms/pictique/client/src/lib/stores/comments.ts index d1839bc97..4c3cce20d 100644 --- a/platforms/pictique/client/src/lib/stores/comments.ts +++ b/platforms/pictique/client/src/lib/stores/comments.ts @@ -1,5 +1,6 @@ -import { writable } from 'svelte/store'; +import { writable, get } from 'svelte/store'; import { apiClient } from '$lib/utils/axios'; +import { posts } from '$lib/stores/posts'; export interface Comment { id: string; @@ -37,6 +38,15 @@ export const createComment = async (postId: string, text: string) => { error.set(null); const response = await apiClient.post('/api/comments', { postId, text }); await fetchComments(postId); // Refresh comments after creating + + // Keep the post's comment count (sourced from posts.comments.length) in sync + const updatedComments = get(comments); + posts.update((existingPosts) => + existingPosts.map((post) => + post.id === postId ? { ...post, comments: updatedComments } : post + ) + ); + return response.data; } catch (err) { error.set(err instanceof Error ? err.message : 'Failed to create comment');