mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-01 13:10:44 -03:00
29 lines
726 B
TypeScript
29 lines
726 B
TypeScript
import { writable } from 'svelte/store';
|
|
import type { Post } from '../../types';
|
|
|
|
export const posts = writable<Post[]>(undefined);
|
|
|
|
export const setPosts = (newPosts: Post[]) => {
|
|
posts.set(newPosts);
|
|
};
|
|
|
|
export const addPost = (post: Post) => {
|
|
posts.update((currentPosts) => [post, ...currentPosts]);
|
|
};
|
|
|
|
export const updatePostStore = (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) => {
|
|
const a = currentPosts.filter((post) => post.id !== postId);
|
|
console.log(a);
|
|
return a;
|
|
});
|
|
|
|
console.log(postId);
|
|
};
|