forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

course-card.tsx60 lines, 2.7 KiBHistoryRawDownload
1import { Show } from "solid-js";
2import { Link } from "@tanstack/solid-router";
3import type { Course } from "@/api/client";
4import { Badge } from "@/components/ui/badge";
5import { IconChevronRight, IconUsers } from "@/components/ui/icons";
6import { personLabel } from "@/lib/person";
7
8const courseInitials = (title: string) =>
9 title.trim().slice(0, 2).toLocaleUpperCase("tr-TR") || "—";
10
11export function CourseCard(props: {
12 course: Course;
13 /** The şubeler line under the title: "3 sections", or a dash. */
14 sections: string;
15 enrolled?: boolean;
16 labels: {
17 kind: string;
18 enrolled: string;
19 };
20}) {
21 // Teaching staff is per instance now, so a catalog card can only name the
22 // course's owner — the şube pages name who actually teaches it.
23 const teachers = () => [props.course.creator];
24
25 return (
26 <Link
27 to="/courses/$id"
28 params={{ id: props.course.id }}
29 class="group flex h-full min-h-40 flex-col gap-3 rounded-xl border border-border-line bg-surface-base p-4 outline-hidden transition-colors hover:border-primary/35 hover:bg-surface-tint focus-visible:ring-2 focus-visible:ring-ring"
30 >
31 <div class="flex items-start gap-3">
32 <span class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-primary/10 text-xs font-semibold text-primary-text">
33 {courseInitials(props.course.title)}
34 </span>
35 <div class="min-w-0 flex-1">
36 <div class="flex flex-wrap items-center gap-1.5">
37 <h2 class="truncate text-base font-semibold tracking-tight">{props.course.title}</h2>
38 </div>
39 <div class="mt-1 flex flex-wrap items-center gap-1.5">
40 <Badge variant="outline" class="rounded-md text-[11px] font-medium">{props.labels.kind}</Badge>
41 <Show when={props.enrolled}><Badge variant="secondary" class="rounded-md text-[11px]">{props.labels.enrolled}</Badge></Show>
42 </div>
43 </div>
44 <IconChevronRight class="mt-1 h-4 w-4 shrink-0 text-text-subtle transition-transform group-hover:translate-x-0.5 group-hover:text-text-default" />
45 </div>
46
47 <Show when={props.course.description}>
48 <p class="line-clamp-2 text-sm leading-5 text-text-subtle">{props.course.description}</p>
49 </Show>
50
51 <div class="mt-auto flex items-center justify-between gap-3 border-t border-border-hairline pt-3 text-xs text-text-subtle">
52 <span class="min-w-0 flex-1 truncate">{props.sections}</span>
53 <span class="flex min-w-0 items-center gap-1.5">
54 <IconUsers class="h-3.5 w-3.5 shrink-0" />
55 <span class="max-w-32 truncate">{teachers().map(personLabel).join(", ")}</span>
56 </span>
57 </div>
58 </Link>
59 );
60}