all repos — kōi @ 13ba0aa72c94f508c54f3862f99e195a4ec73f4c

Minimalist task manager

src/routes/(auth)/+page.svelte (view raw)

 1<script lang="ts">
 2	import NewTask from './NewTask.svelte';
 3	import TaskItem from './TaskItem.svelte';
 4	import type { PageData } from './$types';
 5	import tasksStore from './tasksStore';
 6	import { browser } from '$app/environment';
 7	import { createSolidDataset, saveSolidDatasetAt, setThing } from '@inrupt/solid-client';
 8	import { taskToThing } from '$lib/models/task';
 9	import { fetchPod } from '$lib/solid';
10
11	let { data }: { data: PageData } = $props();
12	tasksStore.set(
13		data?.tasks?.map((task) => ({
14			...task,
15			dueDate: task.dueDate ? new Date(task.dueDate) : null
16		})) || []
17	);
18
19	// Sync with SOLID pod
20	if (browser)
21		tasksStore.subscribe(async (tasks) => {
22			let dataset = createSolidDataset();
23			for (const task of tasks) {
24				const taskThing = taskToThing(task);
25				dataset = setThing(dataset, taskThing);
26			}
27			const savedSolidDataset = await saveSolidDatasetAt(data.iri, dataset, {
28				fetch: fetchPod
29			});
30			console.log({ savedSolidDataset });
31		});
32</script>
33
34<div class="flex flex-col gap-4 py-4">
35	{#each $tasksStore as task (task.id)}
36		<TaskItem {task} />
37	{:else}
38		<p class="text-center">Aucune tâche actuellement</p>
39	{/each}
40</div>
41
42<NewTask />