mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-09 14:30:44 -03:00
arreglado path /timeline y añadida logica crearpost al fetch
This commit is contained in:
22
src/lib/stores/posts.ts
Normal file
22
src/lib/stores/posts.ts
Normal 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));
|
||||
};
|
||||
Reference in New Issue
Block a user