Started display of posts

This commit is contained in:
Clément Le Bihan
2024-05-04 16:35:25 +02:00
parent 1dab30c13b
commit 55ac67b55c
12 changed files with 281 additions and 12 deletions
+24
View File
@@ -0,0 +1,24 @@
// /home/cbihan/Documents/front_stuff/vex/web/src/lib/stores/post.store.js
import type { Post } from "$lib/types";
import { writable } from 'svelte/store';
// Initial state
const initialState: Post[] = [];
// Create the writable store
export const postStore = writable<Post[]>(initialState);
// Actions
export const addPost = (post: Post) => {
postStore.update((posts) => [...posts, post]);
};
export const removePost = (postId: string) => {
postStore.update((posts) => posts.filter((post) => post.id !== postId));
};
export const updatePost = (postId: string, updatedPost: Post) => {
postStore.update((posts) =>
posts.map((post) => (post.id === postId ? updatedPost : post))
);
};