From 2da7c2f2d6606da740059e74f6ba36590c3058fa Mon Sep 17 00:00:00 2001 From: Stefano Volpe Date: Fri, 6 Oct 2023 13:06:00 +0200 Subject: [PATCH] Add status page Bold link, nav-start for status and settings Fix build page margins Rimuovi prestito dall'inglese Underline CSUnibo homepage link Stop showing badges for disabled teachings Stop showing badges for disabled teachings 2 build/page.ts Fix Comment out refactor getActiveTeachings chore: create and use filterAsync --- src/config | 2 +- src/lib/filter.ts | 18 ++++ src/lib/teachings.ts | 19 ++++ src/routes/+page.svelte | 7 +- src/routes/build/+page.svelte | 124 +++++++++++--------------- src/routes/build/+page.ts | 11 +++ src/routes/dash/[course]/+page.svelte | 2 +- src/routes/dash/[course]/+page.ts | 28 +----- src/routes/settings/+page.svelte | 11 ++- 9 files changed, 116 insertions(+), 106 deletions(-) create mode 100644 src/lib/filter.ts create mode 100644 src/routes/build/+page.ts diff --git a/src/config b/src/config index 09691aba..175aea64 160000 --- a/src/config +++ b/src/config @@ -1 +1 @@ -Subproject commit 09691abace58365e380336f2c9f26c797dc34cab +Subproject commit 175aea64f21d465f884f7927f63b5fac1840203b diff --git a/src/lib/filter.ts b/src/lib/filter.ts new file mode 100644 index 00000000..3d5fcfbf --- /dev/null +++ b/src/lib/filter.ts @@ -0,0 +1,18 @@ +/** + * Filters an array asynchronously using a predicate function. + * @param arr The array to filter + * @param predicate The predicate function to use + * @returns The filtered array + */ +export async function filterAsync( + arr: T[], + predicate: (t: T) => Promise +): Promise { + const result = Array(arr.length); + for (const item of arr) { + if (await predicate(item)) { + result.push(item); + } + } + return result; +} diff --git a/src/lib/teachings.ts b/src/lib/teachings.ts index c72532a0..8da787d4 100644 --- a/src/lib/teachings.ts +++ b/src/lib/teachings.ts @@ -1,3 +1,6 @@ +import { getManifest } from '$lib/api'; +import { filterAsync } from './filter'; + export type Teaching = { name: string; url: string; @@ -17,5 +20,21 @@ export type Course = { years: TeachingYear[]; }; +export async function isTeachingActive(fetch: typeof window.fetch, teaching: Teaching) { + try { + await getManifest(fetch, teaching.url); + return true; + } catch { + return false; + } +} + +export async function getActiveTeachings(fetch: typeof window.fetch, course: Course) { + const allTeachings = course.years.flatMap((year) => year.teachings); + const activeTeachings = await filterAsync(allTeachings, (t) => isTeachingActive(fetch, t)); + + return activeTeachings; +} + import TEACHINGS from '../config/courses.json' assert { type: 'json' }; export default TEACHINGS as Course[]; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index a77f9242..1a733216 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -20,14 +20,17 @@

Risorse

-

Raccolte di materiali per lo studio da CSUnibo

+

Raccolte di materiali per lo + studio da CSUnibo

diff --git a/src/routes/build/+page.svelte b/src/routes/build/+page.svelte index a3e0d757..bd112f09 100644 --- a/src/routes/build/+page.svelte +++ b/src/routes/build/+page.svelte @@ -1,84 +1,60 @@ -
- {#each TEACHINGS as course, i} - {#if i > 0} -
- {/if} -

{course.name}

- {#each course.years as years} -

{years.year}

-
- {#each years.teachings as teaching} -
-

{teaching.name}

-
- {#each WORKFLOW_NAMES as workflow} - {@const href = WORKFLOW_URL(teaching.url, workflow)} - {@const src = `${href}/badge.svg`} - - Not found - - {/each} -
-
- {/each} -
- {/each} - {/each} + export let data: PageData; + let activeYears: Teaching[][] = []; -
-

Progetti

+ onMount(async () => { + activeYears = (await data.streaming?.activeCourses) ?? []; + console.log(data); + }); + - {#each PROJECTS as category} -

{category.title}

-
- {#each category.projects as proj} -
-

{proj.name}

-
- {#each proj.workflows as workflow} - {@const href = WORKFLOW_URL(proj.url, workflow)} - {@const src = `${href}/badge.svg`} - - Not found - - {/each} -
+
+ +
+ {#each TEACHINGS as course, i} + {#if i > 0} +
+ {/if} +

{course.name}

+ + {#each course.years as years} +

{years.year}

+
+ {#each years.teachings as teaching} + +
+

{teaching.name}

+ +
+ {#each WORKFLOW_NAMES as workflow} + {@const href = WORKFLOW_URL(teaching.url, workflow)} + {@const src = `${href}/badge.svg`} + + Not found + + {/each} +
+ +
+ {/each}
{/each} -
- {/each} -
+ {/each} +
+ diff --git a/src/routes/build/+page.ts b/src/routes/build/+page.ts new file mode 100644 index 00000000..178fec87 --- /dev/null +++ b/src/routes/build/+page.ts @@ -0,0 +1,11 @@ +import type { PageLoad } from './$types'; +import { getActiveTeachings } from '$lib/teachings'; +import TEACHINGS from '$lib/teachings'; + +export const load: PageLoad = async ({ fetch }) => { + const activeTeachings = TEACHINGS.map((c) => getActiveTeachings(fetch, c)); + + return { + activeTeachings: Promise.all(activeTeachings) + }; +}; diff --git a/src/routes/dash/[course]/+page.svelte b/src/routes/dash/[course]/+page.svelte index f007f06c..35372f3d 100644 --- a/src/routes/dash/[course]/+page.svelte +++ b/src/routes/dash/[course]/+page.svelte @@ -66,7 +66,7 @@