arreglado path /timeline y añadida logica crearpost al fetch

This commit is contained in:
2025-11-23 19:49:07 -03:00
parent 3fbacce3fe
commit 5159ebffd4
4 changed files with 134 additions and 52 deletions

22
src/lib/stores/posts.ts Normal file
View File

@@ -0,0 +1,22 @@
import { writable } from 'svelte/store';
import type { Post } from '../../types';
export const posts = writable<Post[]>([]);
export const setPosts = (newPosts: Post[]) => {
posts.set(newPosts);
};
export const addPost = (post: Post) => {
posts.update((currentPosts) => [post, ...currentPosts]);
};
export const updatePost = (postId: string, updatedData: Partial<Post>) => {
posts.update((currentPosts) =>
currentPosts.map((post) => (post._id === postId ? { ...post, ...updatedData } : post))
);
};
export const removePost = (postId: string) => {
posts.update((currentPosts) => currentPosts.filter((post) => post._id !== postId));
};