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 Tasks from "../lib/components/Tasks.svelte";
9 import NewTask from "../lib/components/NewTask.svelte";
10 import { getPodTasks } from "../lib/solid";
11 import tasks from "../lib/store/tasksStore";
12 import podInfo from "../lib/store/podInfoStore";
13 import { getPodUrlAll } from "@inrupt/solid-client";
14 import Profile from "../lib/components/Profile.svelte";
15
16 let { navigate }: PageProps = $props();
17 let sessionInfo = $state(getDefaultSession()?.info);
18
19 onMount(async () => {
20 const info = await handleIncomingRedirect({
21 restorePreviousSession: true,
22 });
23 if (!info?.isLoggedIn) navigate("/login");
24 else if (!info?.webId)
25 console.error(`Invalid info received from Pod. No WebId found.`);
26 else {
27 sessionInfo = info;
28
29 // Load pod info
30 const pods = await getPodUrlAll(sessionInfo?.webId, { fetch: fetch });
31 const firstPod = pods?.[0];
32 if (firstPod) $podInfo.podUrl = firstPod;
33
34 // Load tasks from pod
35 const podTasks = await getPodTasks(firstPod);
36 tasks.set(podTasks);
37 }
38 });
39</script>
40
41<main class="w-xl max-w-full mx-auto p-4">
42 {#if sessionInfo.isLoggedIn}
43 <div class="flex justify-between">
44 <h1 class="text-2xl mb-4">kōi</h1>
45 <Profile />
46 </div>
47 <Tasks tasks={$tasks} />
48 <NewTask />
49 {:else}
50 <span class="loading loading-spinner loading-xl"></span>
51 {/if}
52</main>