all repos — kōi @ main

Minimalist task manager

src/lib/store/tasksStore.ts (view raw)

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