mirror of
https://github.com/zoriya/vex.git
synced 2026-08-16 02:44:55 +00:00
Started display of posts
This commit is contained in:
@@ -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))
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user