src/pages/Home.svelte (view raw)
1<script lang="ts">
2 import {
3 getDefaultSession,
4 handleIncomingRedirect,
5 fetch,
6 } from "@inrupt/solid-client-authn-browser";
7 import { onMount } from "svelte";
8 import TasksFeed from "../lib/components/TasksFeed.svelte";
9 import NewTask from "../lib/components/NewTask.svelte";
10 import tasksStore from "../lib/store/tasksStore";
11 import podInfo from "../lib/store/podInfoStore";
12 import {
13 getPodUrlAll,
14 getSolidDataset,
15 getThingAll,
16 } from "@inrupt/solid-client";
17 import Profile from "../lib/components/Profile.svelte";
18 import { thingToTask } from "../lib/models/task";
19
20 let { navigate }: PageProps = $props();
21 let sessionInfo = $state(getDefaultSession()?.info);
22
23 onMount(async () => {
24 const info = await handleIncomingRedirect({
25 restorePreviousSession: true,
26 });
27 if (!info?.isLoggedIn) navigate("/login");
28 else if (!info?.webId)
29 console.error(`Invalid info received from Pod. No WebId found.`);
30 else {
31 sessionInfo = info;
32
33 // Load pod info
34 const pods = await getPodUrlAll(sessionInfo?.webId, { fetch: fetch });
35 const firstPod = pods?.[0];
36 if (firstPod) $podInfo.podUrl = firstPod;
37
38 // Load tasks dataset from pod
39 const tasksDataset = await getSolidDataset(`${firstPod}/tasks/default`, {
40 fetch: fetch,
41 });
42 $podInfo.tasksDataset = tasksDataset;
43
44 // Init tasks store
45 const things = getThingAll(tasksDataset);
46 const tasks = things.map(thingToTask);
47 tasksStore.set(tasks);
48 }
49 });
50</script>
51
52<main class="w-3xl max-w-full mx-auto p-4 pb-15">
53 <div class="flex justify-between">
54 <h1 class="text-2xl mb-4">kōi</h1>
55 <Profile />
56 </div>
57 <TasksFeed tasks={$tasksStore} />
58</main>
59
60<div class="fixed bottom-0 left-0 right-0 p-4">
61 <div class="w-3xl max-w-full mx-auto bg-white">
62 <NewTask />
63 </div>
64</div>