all repos — kōi @ 13ba0aa72c94f508c54f3862f99e195a4ec73f4c

Minimalist task manager

src/routes/(auth)/tasksStore.ts (view raw)

 1import { writable } from 'svelte/store';
 2
 3const { set, update, subscribe } = writable<Task[]>([]);
 4
 5const addTask = (task: Task) => {
 6	update((tasks) => [...tasks, { ...task, id: `https://pod.5ika.ch/tasks/default#${Date.now()}` }]);
 7};
 8
 9const updateTask = (taskId: string, taskUpdate: Partial<Task>) => {
10	update((tasks) =>
11		tasks.map((task) => {
12			if (task.id === taskId) return { ...task, ...taskUpdate };
13			return task;
14		})
15	);
16};
17
18const deleteTask = (taskId: string) => {
19	update((tasks) => tasks.filter((task) => task.id !== taskId));
20};
21
22export default { set, update, subscribe, addTask, updateTask, deleteTask };