2026-03-09 11:18:22 +01:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { page } from '$app/state';
|
|
|
|
|
import { resolve } from '$app/paths';
|
2026-05-23 12:24:57 +01:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import type { Component } from 'svelte';
|
2026-03-09 11:18:22 +01:00
|
|
|
import { SvelteSet, SvelteURLSearchParams } from 'svelte/reactivity';
|
|
|
|
|
|
|
|
|
|
import { t } from '$lib/utils/functions/translations';
|
2026-04-12 08:58:41 +01:00
|
|
|
import { user } from '$lib/utils/store/user';
|
|
|
|
|
import { basePath } from '$lib/utils/store/app';
|
2026-03-09 11:18:22 +01:00
|
|
|
|
|
|
|
|
import { PoweredBy } from '$features/ui';
|
|
|
|
|
import LibraryBigIcon from '@lucide/svelte/icons/library-big';
|
2026-04-12 08:58:41 +01:00
|
|
|
import {
|
2026-05-23 12:24:57 +01:00
|
|
|
importThemeCourseCard,
|
|
|
|
|
importThemeNavHero,
|
|
|
|
|
normalizeLandingPageSettings,
|
|
|
|
|
themeCourseGridClass,
|
|
|
|
|
themeHeaderShellClass,
|
|
|
|
|
themeStyle,
|
|
|
|
|
themeRendersNavInsideHero
|
|
|
|
|
} from '$features/org/utils/landing-page';
|
|
|
|
|
|
|
|
|
|
import { LandingButton, OrgLandingPageFooter } from '@cio/ui/custom/org-landing-page';
|
2026-03-09 11:18:22 +01:00
|
|
|
|
|
|
|
|
import { Checkbox } from '@cio/ui/base/checkbox';
|
|
|
|
|
import { Empty } from '@cio/ui/custom/empty';
|
|
|
|
|
import { Separator } from '@cio/ui/base/separator';
|
|
|
|
|
|
|
|
|
|
let { data } = $props();
|
|
|
|
|
|
|
|
|
|
let selectedTags = $derived<string[]>(data.activeTags || []);
|
|
|
|
|
|
2026-04-12 08:58:41 +01:00
|
|
|
const landingSettings = $derived(normalizeLandingPageSettings(data.org.landingpage));
|
|
|
|
|
|
|
|
|
|
const authAction = $derived(
|
|
|
|
|
$user.isLoggedIn
|
|
|
|
|
? {
|
|
|
|
|
label: t.get($basePath === '/lms' || $basePath === '#' ? 'navigation.goto_lms' : 'navigation.goto_dashboard'),
|
|
|
|
|
href: resolve($basePath !== '#' ? $basePath : '/lms', {})
|
|
|
|
|
}
|
|
|
|
|
: {
|
|
|
|
|
label: t.get('navigation.login'),
|
|
|
|
|
href: '/login'
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2026-05-23 12:24:57 +01:00
|
|
|
const shellClass = $derived(`ui:min-h-screen ${themeHeaderShellClass(landingSettings.theme)}`);
|
|
|
|
|
const shellStyle = $derived(themeStyle(landingSettings.theme));
|
|
|
|
|
const navInsideHero = $derived(themeRendersNavInsideHero(landingSettings.theme));
|
|
|
|
|
const courseGridClass = $derived(themeCourseGridClass(landingSettings.theme));
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
let NavComponent = $state<Component<any> | null>(null);
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
let HeroComponent = $state<Component<any> | null>(null);
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
let CourseCardComponent = $state<Component<any> | null>(null);
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
const [navHero, cardComponent] = await Promise.all([
|
|
|
|
|
importThemeNavHero(landingSettings.theme),
|
|
|
|
|
importThemeCourseCard(landingSettings.theme)
|
|
|
|
|
]);
|
|
|
|
|
NavComponent = navHero.NavComponent;
|
|
|
|
|
HeroComponent = navHero.HeroComponent;
|
|
|
|
|
CourseCardComponent = cardComponent;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const heroProps = $derived({
|
|
|
|
|
...landingSettings.hero,
|
|
|
|
|
heading: t.get('public_courses.heading'),
|
|
|
|
|
image: ''
|
|
|
|
|
});
|
2026-04-12 08:58:41 +01:00
|
|
|
|
2026-03-09 11:18:22 +01:00
|
|
|
async function applyTagFilters(nextTags: string[]) {
|
|
|
|
|
const params = new SvelteURLSearchParams(page.url.searchParams);
|
|
|
|
|
|
|
|
|
|
if (nextTags.length > 0) {
|
|
|
|
|
params.set('tags', nextTags.join(','));
|
|
|
|
|
} else {
|
|
|
|
|
params.delete('tags');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const query = params.toString();
|
2026-04-12 08:58:41 +01:00
|
|
|
const suffix = query ? `?${query}` : '';
|
2026-03-09 11:18:22 +01:00
|
|
|
|
2026-04-12 08:58:41 +01:00
|
|
|
await goto(resolve(`/courses${suffix}`, {}), {
|
2026-03-09 11:18:22 +01:00
|
|
|
keepFocus: true,
|
|
|
|
|
noScroll: true,
|
|
|
|
|
invalidateAll: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toggleTag(tagSlug: string, checked: boolean) {
|
|
|
|
|
const next = new SvelteSet(selectedTags);
|
|
|
|
|
if (checked) {
|
|
|
|
|
next.add(tagSlug);
|
|
|
|
|
} else {
|
|
|
|
|
next.delete(tagSlug);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyTagFilters(Array.from(next));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearFilters() {
|
|
|
|
|
if (selectedTags.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyTagFilters([]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isTagSelected(tagSlug: string) {
|
|
|
|
|
return selectedTags.includes(tagSlug);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const displayTagGroups = $derived.by(() => {
|
|
|
|
|
const sourceGroups = data.tagGroups ?? [];
|
|
|
|
|
const tagsByGroupId: Record<string, (typeof sourceGroups)[number]['tags']> = {};
|
|
|
|
|
|
|
|
|
|
for (const group of sourceGroups) {
|
|
|
|
|
for (const tag of group.tags ?? []) {
|
|
|
|
|
const groupId = tag.groupId || group.id;
|
|
|
|
|
const existing = tagsByGroupId[groupId] ?? [];
|
|
|
|
|
|
|
|
|
|
if (!existing.some((item) => item.id === tag.id)) {
|
|
|
|
|
existing.push(tag);
|
|
|
|
|
tagsByGroupId[groupId] = existing;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sourceGroups.map((group) => ({
|
|
|
|
|
...group,
|
|
|
|
|
tags: tagsByGroupId[group.id] ?? []
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<PoweredBy />
|
|
|
|
|
|
2026-05-23 12:24:57 +01:00
|
|
|
<main class={shellClass} style={shellStyle}>
|
|
|
|
|
{#if NavComponent && HeroComponent}
|
|
|
|
|
{#if navInsideHero}
|
|
|
|
|
<HeroComponent hero={heroProps} orgName={data.org.name}>
|
|
|
|
|
{#snippet navigation()}
|
|
|
|
|
<NavComponent
|
|
|
|
|
orgName={data.org.name}
|
|
|
|
|
logoUrl={data.org.avatarUrl ?? undefined}
|
|
|
|
|
navItems={landingSettings.navItems}
|
|
|
|
|
{authAction}
|
|
|
|
|
/>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</HeroComponent>
|
|
|
|
|
{:else}
|
|
|
|
|
<NavComponent
|
|
|
|
|
orgName={data.org.name}
|
|
|
|
|
logoUrl={data.org.avatarUrl ?? undefined}
|
|
|
|
|
navItems={landingSettings.navItems}
|
|
|
|
|
{authAction}
|
|
|
|
|
/>
|
|
|
|
|
<HeroComponent hero={heroProps} orgName={data.org.name} />
|
|
|
|
|
{/if}
|
2026-04-12 08:58:41 +01:00
|
|
|
{/if}
|
2026-03-09 11:18:22 +01:00
|
|
|
|
|
|
|
|
<section class="mx-auto w-full max-w-7xl px-4 py-8 md:px-6">
|
2026-04-12 08:58:41 +01:00
|
|
|
<div class="mb-6 flex items-center justify-end gap-4">
|
2026-05-23 12:24:57 +01:00
|
|
|
<LandingButton variant="secondary" onclick={clearFilters} disabled={selectedTags.length === 0}>
|
2026-03-09 11:18:22 +01:00
|
|
|
{$t('public_courses.clear_filters')}
|
2026-05-23 12:24:57 +01:00
|
|
|
</LandingButton>
|
2026-03-09 11:18:22 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="grid gap-8 lg:grid-cols-[280px_minmax(0,1fr)]">
|
2026-05-23 12:24:57 +01:00
|
|
|
<aside
|
|
|
|
|
class="ui:bg-[var(--landing-card)] ui:text-[var(--landing-fg)] ui:border-[var(--landing-border)] space-y-4 rounded-lg border p-4"
|
|
|
|
|
>
|
2026-03-09 11:18:22 +01:00
|
|
|
<div>
|
|
|
|
|
<h2 class="text-base font-semibold">{$t('public_courses.filters.title')}</h2>
|
2026-05-23 12:24:57 +01:00
|
|
|
<p class="ui:text-[var(--landing-fg-muted)] text-xs">{$t('public_courses.filters.help')}</p>
|
2026-03-09 11:18:22 +01:00
|
|
|
</div>
|
|
|
|
|
|
2026-05-23 12:24:57 +01:00
|
|
|
<Separator class="ui:bg-[var(--landing-border)]" />
|
2026-03-09 11:18:22 +01:00
|
|
|
|
|
|
|
|
{#if displayTagGroups.length === 0}
|
2026-05-23 12:24:57 +01:00
|
|
|
<p class="ui:text-[var(--landing-fg-muted)] text-sm">{$t('public_courses.filters.empty')}</p>
|
2026-03-09 11:18:22 +01:00
|
|
|
{:else}
|
|
|
|
|
<div class="space-y-5">
|
|
|
|
|
{#each displayTagGroups as group (group.id)}
|
|
|
|
|
<div class="space-y-2">
|
|
|
|
|
<div class="space-y-1">
|
|
|
|
|
<h3 class="text-sm font-semibold">{group.name}</h3>
|
|
|
|
|
{#if group.description}
|
2026-05-23 12:24:57 +01:00
|
|
|
<p class="ui:text-[var(--landing-fg-muted)] text-xs">{group.description}</p>
|
2026-03-09 11:18:22 +01:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="space-y-2">
|
|
|
|
|
{#each group.tags as tag (tag.id)}
|
|
|
|
|
<label
|
2026-05-23 12:24:57 +01:00
|
|
|
class="ui:border-[var(--landing-border)] ui:hover:bg-[var(--landing-card-soft)] flex cursor-pointer items-center justify-between rounded-md border px-3 py-2"
|
2026-03-09 11:18:22 +01:00
|
|
|
>
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<Checkbox
|
|
|
|
|
checked={isTagSelected(tag.slug)}
|
|
|
|
|
onCheckedChange={(checked) => toggleTag(tag.slug, Boolean(checked))}
|
|
|
|
|
/>
|
|
|
|
|
<span
|
|
|
|
|
class="inline-block h-2.5 w-2.5 rounded-full border"
|
|
|
|
|
style={`background-color: ${tag.color}`}
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
></span>
|
|
|
|
|
<span class="text-sm">{tag.name}</span>
|
|
|
|
|
</div>
|
2026-05-23 12:24:57 +01:00
|
|
|
<span class="ui:text-[var(--landing-fg-muted)] text-xs">{tag.courseCount}</span>
|
2026-03-09 11:18:22 +01:00
|
|
|
</label>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</aside>
|
|
|
|
|
|
|
|
|
|
<div class="space-y-4">
|
|
|
|
|
{#if data.courses.length === 0}
|
|
|
|
|
<Empty
|
|
|
|
|
icon={LibraryBigIcon}
|
|
|
|
|
title={$t('public_courses.empty.title')}
|
|
|
|
|
description={$t('public_courses.empty.description')}
|
|
|
|
|
variant="page"
|
|
|
|
|
/>
|
2026-05-23 12:24:57 +01:00
|
|
|
{:else if CourseCardComponent}
|
|
|
|
|
<div class={courseGridClass}>
|
|
|
|
|
{#each data.courses as course, index (course.id)}
|
|
|
|
|
<CourseCardComponent {course} {index} />
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
2026-03-09 11:18:22 +01:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
2026-04-12 08:58:41 +01:00
|
|
|
|
|
|
|
|
<OrgLandingPageFooter
|
|
|
|
|
orgName={data.org.name}
|
|
|
|
|
logoUrl={data.org.avatarUrl ?? undefined}
|
2026-05-18 03:47:22 +01:00
|
|
|
footer={landingSettings.footer}
|
2026-04-12 08:58:41 +01:00
|
|
|
variant={landingSettings.theme}
|
|
|
|
|
/>
|
2026-03-09 11:18:22 +01:00
|
|
|
</main>
|