Skip to content

Commit

Permalink
fix: remove recursion for optional courses + throw error for non exis…
Browse files Browse the repository at this point in the history
…tant dashes
  • Loading branch information
VaiTon committed Oct 5, 2023
1 parent 6ba6a02 commit e685cee
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 65 deletions.
19 changes: 14 additions & 5 deletions src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<script lang="ts">
import { page } from '$app/stores';
$: error = $page.error;
</script>

<div class="flex justify-center">
<div class="flex justify-center h-screen items-center">
<div class="text-center">
<h1 class="text-5xl my-12">404</h1>
<p class="text-xl my-8">Pagina non trovata</p>
<h1 class="text-5xl mb-6 font-mono">{$page.status}</h1>

<button class="btn btn-ghost" on:click|preventDefault={() => history.back()}>
Torna indietro
<p class="text-xl font-mono text-base-content">
{#if error == null}
Unknown error!
{:else}
{error.message}
{/if}
</p>

<button class="btn btn-ghost mt-10" on:click|preventDefault={() => history.back()}>
Go back to previous page
</button>
</div>
</div>
38 changes: 0 additions & 38 deletions src/routes/ListTeaching.svelte

This file was deleted.

4 changes: 2 additions & 2 deletions src/routes/[...dir]/[zfile=dir]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PageLoad } from './$types';
import { getManifest, getFuzzy } from '$lib/api';

export const load = (async ({ fetch, params }) => {
export const load: PageLoad = async ({ fetch, params }) => {
// Get the relative path using params
const path = params.dir ? params.dir + '/' + params.zfile : params.zfile;

Expand All @@ -16,4 +16,4 @@ export const load = (async ({ fetch, params }) => {
manifest,
fuzzy
};
}) satisfies PageLoad;
};
35 changes: 17 additions & 18 deletions src/routes/dash/[course]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script lang="ts">
import { base } from '$app/paths';
import type { PageData } from './$types';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import type { Teaching, TeachingYear } from '$lib/teachings';
import type { Course, Teaching } from '$lib/teachings';
import { getLoginUrl, getWhoAmI } from '$lib/upld';
import ListTeaching from "../../ListTeaching.svelte";
import ListTeaching from './ListTeaching.svelte';
export let data: PageData;
let activeYears: Teaching[] = [];
Expand All @@ -18,23 +17,23 @@
activeYears = (await data.streaming?.activeCourses) ?? [];
login = getWhoAmI(fetch);
});
function filterCoursesOptional(data: PageData, currentIndex = 0, result: {mandatory: TeachingYear[], optional: TeachingYear[]} = { mandatory: [], optional: [] }) {
if (currentIndex >= data.course?.years.length!) {
return result;
function filterCoursesOptional(course: Course) {
const mandatory = [];
const optional = [];
for (const year of course.years) {
const optionalTeachings = year.teachings.filter((teaching: Teaching) => teaching.optional);
const mandatoryTeachings = year.teachings.filter((teaching: Teaching) => !teaching.optional);
mandatory.push({ year: year.year, teachings: mandatoryTeachings });
optional.push({ year: year.year, teachings: optionalTeachings });
}
const year = data.course?.years[currentIndex];
const optionalTeachings = year?.teachings.filter((teaching: Teaching) => teaching.optional);
const mandatoryTeachings = year?.teachings.filter((teaching: Teaching) => !teaching.optional);
result.mandatory.push({ year: year?.year!, teachings: mandatoryTeachings! });
result.optional.push({ year: year?.year!, teachings: optionalTeachings! });
return filterCoursesOptional(data, currentIndex + 1, result);
return { mandatory, optional };
}
$: filteredCourses = filterCoursesOptional(data)
$: filteredCourses = filterCoursesOptional(data.course);
</script>

<svelte:head>
Expand Down Expand Up @@ -74,7 +73,7 @@
<a class="btn btn-square btn-ghost" title="Indietro" href="/"> ⬆️ </a>
</div>
</nav>
<ListTeaching years={filteredCourses.mandatory} activeYears={activeYears} title={""}/>
<ListTeaching years={filteredCourses.optional} activeYears={activeYears} title={"facoltativi"}/>
<ListTeaching years={filteredCourses.mandatory} {activeYears} title={''} />
<ListTeaching years={filteredCourses.optional} {activeYears} title={'facoltativi'} />
</div>
{/if}
5 changes: 3 additions & 2 deletions src/routes/dash/[course]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { PageLoad } from './$types';
import type { Course, Teaching, TeachingYear } from '$lib/teachings';
import { getManifest } from '$lib/api';
import TEACHINGS from '$lib/teachings';
import { error } from '@sveltejs/kit';

async function getActiveCourse(fetch: typeof window.fetch, teaching: Teaching) {
try {
Expand Down Expand Up @@ -31,8 +32,8 @@ async function getActiveCourses(fetch: typeof window.fetch, course: Course) {
export const load = (async ({ fetch, params }) => {
const course = TEACHINGS.find((c) => c.id === params.course);

if (!course) {
return { course: null };
if (course == null) {
throw error(404, `Course '${params.course}' not found`);
}

// Filter out inactive teachings
Expand Down
41 changes: 41 additions & 0 deletions src/routes/dash/[course]/ListTeaching.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script lang="ts">
import type { Teaching, TeachingYear } from '$lib/teachings';
import { base } from '$app/paths';
export let years: TeachingYear[];
export let activeYears: Teaching[];
export let title: string;
</script>

<ul class="menu p-2">
{#each years as year}
{#if year.teachings.length > 0}
<li class="menu-title">
<span class="text-2xl mt-5 italic">{year.year} anno {title}</span>
</li>
<div class="divider mt-0"></div>
<div class="flex flex-row flex-wrap">
{#each year.teachings as teaching}
{@const disabled = !activeYears.includes(teaching)}
{@const href = base + '/' + teaching.url}
<a href={disabled ? null : href} class="text-center text-lg">
<li
class:disabled
class="flex flex-row xs:flex-1 justify-center border-base-content items-center m-2 border-2 rounded-md join"
>
<a href={disabled ? null : href} class="text-center text-lg join-item">
{teaching.name ? teaching.name : teaching.url}
</a>
{#if teaching.telegram != null && teaching.telegram !== ''}
<a
href="https://t.me/{teaching.telegram}"
class="text-center text-lg join-item border-l-2">👥</a
>
{/if}
</li>
</a>
{/each}
</div>
{/if}
{/each}
</ul>

1 comment on commit e685cee

@vercel
Copy link

@vercel vercel bot commented on e685cee Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dynamik – ./

dynamik-csunibo.vercel.app
dynamik-git-main-csunibo.vercel.app
dynamik.vercel.app

Please sign in to comment.