mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-01 13:10:44 -03:00
36 lines
904 B
TypeScript
36 lines
904 B
TypeScript
import { writable } from 'svelte/store';
|
|
import type { Post } from '../../types';
|
|
|
|
export const posts = writable<Post[]>([]);
|
|
export const loadingPosts = writable(false);
|
|
export const page = writable(1);
|
|
|
|
export const PAGE_SIZE = 20;
|
|
|
|
export const setPosts = (newPosts: Post[]) => {
|
|
posts.set(newPosts);
|
|
};
|
|
|
|
export const appendPosts = (newPosts: Post[]) => {
|
|
posts.update((current) => [...current, ...newPosts]);
|
|
};
|
|
|
|
export const addPost = (post: Post) => {
|
|
posts.update((current) => [post, ...current]);
|
|
};
|
|
|
|
export const updatePostStore = (postId: string, updatedData: Partial<Post>) => {
|
|
posts.update((current) =>
|
|
current.map((post) => (post.id === postId ? { ...post, ...updatedData } : post))
|
|
);
|
|
};
|
|
|
|
export const removePost = (postId: string) => {
|
|
posts.update((current) => current.filter((post) => post.id !== postId));
|
|
};
|
|
|
|
export const resetPosts = () => {
|
|
posts.set([]);
|
|
page.set(1);
|
|
};
|