|
1 | 1 | <script lang="ts">
|
| 2 | + import { afterNavigate } from '$app/navigation'; |
2 | 3 | import { storeCurrentUrl } from '$lib/stores/stores';
|
3 |
| -
|
4 | 4 | import type { LayoutData } from './$types';
|
5 | 5 | import ProCourseMark from './ProCourseMark.svelte';
|
6 | 6 | export let data: LayoutData;
|
7 | 7 |
|
| 8 | + // Scroll heading into view |
| 9 | + function scrollLessonIntoView(): void { |
| 10 | + const slug = window.location.href?.split('/').at(-1); |
| 11 | + const child: HTMLElement | null = document.querySelector(`#nav-${slug}`); |
| 12 | + child?.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' }); |
| 13 | + } |
| 14 | +
|
| 15 | + afterNavigate(() => scrollLessonIntoView()); |
| 16 | +
|
8 | 17 | $: classesActive = (href: string) =>
|
9 | 18 | $storeCurrentUrl?.split('/').at(-1) === href ? 'bg-primary-active-token !text-white' : '';
|
10 | 19 | </script>
|
11 | 20 |
|
12 | 21 | {#if data?.course?.lesson}
|
13 |
| - <div class="p-2 card md:p-4"> |
14 |
| - <nav class="nav-list-nav"> |
15 |
| - <ul> |
16 |
| - {#each data.course.lesson as l} |
17 |
| - {#if l?.section} |
18 |
| - <div class="pb-2"> |
19 |
| - <span class="flex py-2 mt-4 text-xl font-bold"> |
20 |
| - {l.section} |
21 |
| - </span> |
22 |
| - <hr /> |
23 |
| - </div> |
24 |
| - {/if} |
25 |
| - <li class="flex justify-between"> |
26 |
| - <a |
27 |
| - href={`/course/${data?.course?.slug}/lesson/${l.slug}`} |
28 |
| - class={`${classesActive(l.slug)} flex gap-1`} |
29 |
| - > |
30 |
| - {l.title} |
31 |
| - </a> |
32 |
| - <div class="flex w-12 gap-1"> |
33 |
| - <ProCourseMark locked={l?.locked} lesson={l} {data} /> |
| 22 | + <div class="relative h-full"> |
| 23 | + <div class="top-0 left-0 flex flex-col w-full h-full shadow-sm lg:absolute"> |
| 24 | + <div class="relative flex-grow"> |
| 25 | + <div class="inset-0 lg:absolute"> |
| 26 | + <div class="w-full h-full"> |
| 27 | + <div class="flex flex-col h-full"> |
| 28 | + <div class="flex-grow overflow-hidden"> |
| 29 | + <div class="h-full overflow-hidden"> |
| 30 | + <div class="overflow-auto h-72 lg:h-full"> |
| 31 | + <div class="p-2 card md:p-4 rounded-none"> |
| 32 | + <nav class="nav-list-nav"> |
| 33 | + <ul> |
| 34 | + {#each data.course.lesson as l} |
| 35 | + {#if l?.section} |
| 36 | + <div class="pb-2"> |
| 37 | + <span class="flex py-2 mt-4 text-xl font-bold"> |
| 38 | + {l.section} |
| 39 | + </span> |
| 40 | + <hr /> |
| 41 | + </div> |
| 42 | + {/if} |
| 43 | + <li class="flex justify-between relative" id={`nav-${l.slug}`}> |
| 44 | + <a |
| 45 | + href={`/course/${data?.course?.slug}/lesson/${l.slug}`} |
| 46 | + class={`${classesActive(l.slug)} flex gap-1`} |
| 47 | + > |
| 48 | + {l.title} |
| 49 | + </a> |
| 50 | + <div class="flex gap-1 absolute right-1 top-1"> |
| 51 | + <ProCourseMark locked={l?.locked} lesson={l} {data} /> |
| 52 | + </div> |
| 53 | + </li> |
| 54 | + {/each} |
| 55 | + </ul> |
| 56 | + </nav> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + </div> |
34 | 61 | </div>
|
35 |
| - </li> |
36 |
| - {/each} |
37 |
| - </ul> |
38 |
| - </nav> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + </div> |
39 | 66 | </div>
|
40 | 67 | {/if}
|
0 commit comments