|
1 | 1 | <script lang="ts"> |
2 | 2 | import * as Carousel from '$lib/components/shadcn-svelte/ui/carousel/index.js'; |
3 | | - import JobCard from './job-card.svelte'; |
| 3 | + import JobCard from '$lib/components/ui/job-card.svelte'; |
4 | 4 | import { type CarouselAPI } from '$lib/components/shadcn-svelte/ui/carousel/context'; |
5 | | - import Button from '../shadcn-svelte/ui/button/button.svelte'; |
6 | | - import type { Job } from '$lib/server/data/jobs'; |
| 5 | + import { Button } from '$lib/components/shadcn-svelte/ui/button'; |
| 6 | + import type { Job } from '$lib/assets/data/jobs'; |
| 7 | + import { DotIcon } from 'lucide-svelte'; |
7 | 8 |
|
8 | 9 | let api = $state<CarouselAPI>(); |
9 | | - let viewingCurrent = $state(true); |
| 10 | + let current = $state(0); |
| 11 | + const count = $derived(api ? api.scrollSnapList().length : 0); |
10 | 12 |
|
11 | | - let carouselButtonText = $derived(viewingCurrent ? 'View Past Jobs' : 'View Current Jobs'); |
| 13 | + $effect(() => { |
| 14 | + if (api) { |
| 15 | + current = api.selectedScrollSnap(); |
| 16 | + api.on('select', () => { |
| 17 | + current = api!.selectedScrollSnap(); |
| 18 | + }); |
| 19 | + } |
| 20 | + }); |
12 | 21 |
|
13 | 22 | let { jobs }: { jobs: Job[] } = $props(); |
14 | 23 |
|
|
26 | 35 |
|
27 | 36 | <div class="flex flex-col justify-center gap-y-8 text-center"> |
28 | 37 | <Carousel.Root opts={{ loop: true }} setApi={(emblaAPI) => (api = emblaAPI)}> |
29 | | - <Carousel.Content> |
30 | | - <Carousel.Item class="flex flex-col justify-start gap-y-2"> |
| 38 | + <Carousel.Content class=""> |
| 39 | + <Carousel.Item class="flex flex-col gap-y-2"> |
31 | 40 | <h2>Current Jobs</h2> |
32 | | - <div class="flex flex-col gap-y-2"> |
| 41 | + <div class="flex flex-col items-center gap-y-2"> |
33 | 42 | {#each currentJobs as job, i (i)} |
34 | 43 | <JobCard {job} /> |
35 | 44 | {/each} |
36 | 45 | </div> |
37 | 46 | </Carousel.Item> |
38 | | - <Carousel.Item class="flex flex-col justify-center gap-y-2"> |
| 47 | + <Carousel.Item class="flex flex-col items-center gap-y-2"> |
39 | 48 | <h2>Past Jobs</h2> |
40 | 49 | <div class="flex flex-col gap-y-2"> |
41 | 50 | {#each pastJobs as job, i (i)} |
|
45 | 54 | </Carousel.Item> |
46 | 55 | </Carousel.Content> |
47 | 56 | </Carousel.Root> |
48 | | - <Button |
49 | | - onclick={() => { |
50 | | - api?.scrollNext(); |
51 | | - viewingCurrent = !viewingCurrent; |
52 | | - }} |
53 | | - variant="outline" |
54 | | - class="mt-2 max-w-32 place-self-center">{carouselButtonText}</Button |
55 | | - > |
| 57 | + |
| 58 | + <div class="flex flex-row justify-center"> |
| 59 | + <!-- eslint-disable-next-line @typescript-eslint/no-unused-vars --> |
| 60 | + {#each Array(count) as _, i (i)} |
| 61 | + <DotIcon |
| 62 | + onclick={() => api?.scrollTo(i)} |
| 63 | + class={i !== current ? 'text-accent' : ''} |
| 64 | + size={36} |
| 65 | + /> |
| 66 | + {/each} |
| 67 | + </div> |
56 | 68 | </div> |
0 commit comments