Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion platforms/pictique/client/src/lib/stores/comments.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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');
Expand Down
Loading