all repos — kōi @ 6552cde48bf0f293b876864af2aff29c013e24f5

Minimalist task manager

Parse tasks from rdf
Tim Izzo tim@5ika.ch
Fri, 10 Jan 2025 18:54:19 +0100
commit

6552cde48bf0f293b876864af2aff29c013e24f5

parent

06d6c343bb7f758261d0ed471cf4711ef5310723

M src/app.d.tssrc/app.d.ts

@@ -3,7 +3,9 @@ // for information about these interfaces

declare global { namespace App { // interface Error {} - // interface Locals {} + interface Locals { + getSession: () => Promise<Session | undefined>; + } // interface PageData {} // interface PageState {} // interface Platform {}
A src/lib/models/task.ts

@@ -0,0 +1,36 @@

+import { getStringNoLocale, getUrl, getDatetime, type Thing } from '@inrupt/solid-client'; +import { SCHEMA_INRUPT } from '@inrupt/vocab-common-rdf'; + +const SCHEMA_CUSTOM = { + // Types + ScheduleAction: 'http://schema.org/ScheduleAction', + + // Properties + scheduledTime: 'http://schema.org/scheduledTime', + actionStatus: 'http://schema.org/actionStatus', + + // Enumeration types + ActionStatusType: { + active: 'http://schema.org/ActiveActionStatus', + done: 'http://schema.org/CompletedActionStatus' + } +}; + +export class Task { + type = SCHEMA_CUSTOM.ScheduleAction; + done: boolean; + name: string | null; + datetime: Date | null; + + constructor(taskInput: Thing) { + this.name = getStringNoLocale(taskInput, SCHEMA_INRUPT.name); + this.done = + getUrl(taskInput, SCHEMA_CUSTOM.actionStatus) === SCHEMA_CUSTOM.ActionStatusType.done; + this.datetime = getDatetime(taskInput, SCHEMA_CUSTOM.scheduledTime); + } + + serialize() { + // TODO could be improved + return JSON.parse(JSON.stringify(this)); + } +}
M src/routes/(auth)/+page.server.tssrc/routes/(auth)/+page.server.ts

@@ -1,11 +1,17 @@

import { getSolidDataset, getThingAll } from '@inrupt/solid-client'; import type { PageServerLoad } from './$types'; +import { Task } from '$lib/models/task'; export const load: PageServerLoad = async (event) => { const session = await event.locals.getSession(); - const dataset = await getSolidDataset('https://pod.5ika.ch/tasks/default', { + const iri = 'https://pod.5ika.ch/tasks/default'; + const dataset = await getSolidDataset(iri, { fetch: session.fetch }); - const taskSubjects = getThingAll(dataset); - return { taskSubjects }; + const taskThings = getThingAll(dataset); + const tasks = taskThings.map((thing) => new Task(thing)).map((task) => task.serialize()); + + console.log(tasks); + + return { tasks }; };
M src/routes/(auth)/+page.sveltesrc/routes/(auth)/+page.svelte

@@ -3,8 +3,6 @@ import { db } from '$lib/db';

import { liveQuery } from 'dexie'; import NewTask from './NewTask.svelte'; import Task from './Task.svelte'; - import { getStringNoLocale } from '@inrupt/solid-client'; - import { SCHEMA_INRUPT } from '@inrupt/vocab-common-rdf'; import type { PageData } from './$types'; let { data }: { data: PageData } = $props();

@@ -20,8 +18,8 @@ {/each}

</div> <ul> - {#each data.taskSubjects as taskSubject} - <li>{getStringNoLocale(taskSubject, SCHEMA_INRUPT.name)}</li> + {#each data.tasks as task} + <li>{task.name} {task.done} {task.datetime}</li> {/each} </ul>