Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

New Tracks UI (#645)

Subham Bhattacharya4e630c7499f5
diff --git a/apps/web/src/app/[locale]/tracks/_components/personal-track-card.tsx b/apps/web/src/app/[locale]/tracks/_components/personal-track-card.tsx
index 5965ae60..bb642ff2 100644
--- a/apps/web/src/app/[locale]/tracks/_components/personal-track-card.tsx
+++ b/apps/web/src/app/[locale]/tracks/_components/personal-track-card.tsx
@@ -16,7 +16,7 @@ interface PersonalTrackCardProps {
export function PersonalTrackCard({ track }: PersonalTrackCardProps) {
// Calculates the total number of successful challenges.
- function calulcateCompletedChallenges(): number {
+ function calculateCompletedChallenges(): number {
let completedChallenges = 0;
for (const trackChallenge of track.trackChallenges) {
for (const submission of trackChallenge.challenge.submission) {
@@ -45,7 +45,7 @@ export function PersonalTrackCard({ track }: PersonalTrackCardProps) {
</div>
</div>
<TrackProgress
- completedChallenges={calulcateCompletedChallenges()}
+ completedChallenges={calculateCompletedChallenges()}
totalChallenges={track.trackChallenges.length}
/>
</CardHeader>
diff --git a/apps/web/src/app/[locale]/tracks/_components/track-card.tsx b/apps/web/src/app/[locale]/tracks/_components/track-card.tsx
index cc275f41..ad2b7b96 100644
--- a/apps/web/src/app/[locale]/tracks/_components/track-card.tsx
+++ b/apps/web/src/app/[locale]/tracks/_components/track-card.tsx
@@ -1,56 +1,86 @@
'use client';
-import clsx from 'clsx';
-import { useRouter } from 'next/navigation';
-import { TrackChallenge } from './track-challenge-card';
import type { Tracks } from './track-grid';
-import { Button } from '@repo/ui/components/button';
+import { Card, CardContent } from '@repo/ui/components/card';
+import { Badge } from '@repo/ui/components/badge';
+import Link from 'next/link';
+import { clsx } from 'clsx';
+import { Swords } from '@repo/ui/icons';
interface TrackProps {
+ index: number;
track: Tracks[number];
}
-export function TrackCard({ track }: TrackProps) {
- const router = useRouter();
+const BGS_BY_TRACK: Record<number, string> = {
+ 0: 'to-difficulty-beginner/30 dark:to-difficulty-beginner-dark/20',
+ 1: 'to-difficulty-easy/30 dark:to-difficulty-easy-dark/20',
+ 2: 'to-difficulty-medium/30 dark:to-difficulty-medium-dark/20',
+ 3: 'to-difficulty-hard/30 dark:to-difficulty-hard-dark/20',
+ 4: 'to-difficulty-extreme/30 dark:to-difficulty-extreme-dark/20',
+ 5: 'to-difficulty-hard/10 dark:to-difficulty-hard-dark/10',
+ 6: 'to-difficulty-medium/10 dark:to-difficulty-medium-dark/10',
+ 7: 'to-difficulty-easy/10 dark:to-difficulty-easy-dark/10',
+ 8: 'to-difficulty-beginner/10 dark:to-difficulty-beginner-dark/10',
+ 9: 'to-difficulty-extreme/10 dark:to-difficulty-extreme-dark/10',
+} as const;
+
+const EnrolledBadge = ({ text = 'Enrolled' }: { text?: string }) => (
+ <div
+ className={clsx(
+ 'absolute -right-[1px] -top-[20px] z-[-1] rounded rounded-tl-lg rounded-tr-xl px-5 pb-10 pt-[3px] text-[10px]',
+ 'border border-blue-400 bg-blue-400 text-white',
+ )}
+ >
+ {text}
+ </div>
+);
+
+export function TrackCard({ track, index }: TrackProps) {
+ const isEnrolled = Boolean(track.enrolledUsers?.length);
+
return (
- <div className="relative w-full">
- <div className="w-full">
- <div
- className={clsx(
- 'relative inset-0 flex max-w-[400px] flex-col justify-start space-y-4',
- 'max-md:scale-110',
- )}
- >
- <div className="flex w-[69%] items-center justify-between gap-3 rounded-b-lg rounded-t-xl bg-neutral-500/10 p-2 pl-3">
- <span className="flex items-center gap-1 text-sm font-semibold tracking-wide">
- {track.title}
- </span>
+ <Link href={`/tracks/${track.id}`} className="group">
+ <Card
+ className={clsx(
+ 'relative transition-colors duration-300',
+ isEnrolled
+ ? 'border-blue-400'
+ : 'group-hover:border-blue-400 group-focus:border-blue-400',
+ )}
+ >
+ {track.enrolledUsers?.length ? <EnrolledBadge /> : null}
+ <CardContent className="flex items-center gap-5 p-2 pr-4">
+ <div
+ className={clsx(
+ `bg-gradient-to-r from-neutral-500/10 from-10% ${BGS_BY_TRACK[index]} relative to-100% dark:from-neutral-500/20`,
+ 'flex h-24 w-24 flex-none items-center justify-center rounded-2xl',
+ )}
+ >
+ <Swords
+ size={50}
+ className={clsx(
+ 'transition-opacity duration-300',
+ !isEnrolled && 'opacity-50 group-hover:opacity-100 group-focus:opacity-100',
+ )}
+ />
</div>
- <div className="flex w-full items-center justify-between gap-3 rounded-b-lg rounded-t-xl bg-neutral-500/10 p-2 pl-3">
- <span className="text-muted-foreground flex h-10 gap-1 overflow-hidden text-sm font-semibold tracking-wide">
- {track.description}
- </span>
- </div>
- <div className="flex flex-col gap-2">
- {track.trackChallenges.map((trackChallenge) => {
- return (
- <TrackChallenge
- challenge={trackChallenge.challenge}
- key={`track-challenge-${trackChallenge.id}-${track.id}`}
- />
- );
- })}
- <Button
- variant="outline"
- onClick={() => {
- router.push(`/tracks/${track.id}`);
- }}
- >
- View
- </Button>
+
+ <div className="flex-1">
+ <div className="flex items-center justify-between gap-2">
+ <span className="line-clamp-2 font-semibold capitalize tracking-wide">
+ {track.title}
+ </span>
+ <Badge className="flex-none">{track._count.trackChallenges} Challenges</Badge>
+ </div>
+ <div className="h-8">
+ <span className="text-muted-foreground mt-3 line-clamp-2 text-xs tracking-wide">
+ {track.description}
+ </span>
+ </div>
</div>
- </div>
- </div>
- </div>
+ </CardContent>
+ </Card>
+ </Link>
);
}
diff --git a/apps/web/src/app/[locale]/tracks/_components/track-challenge-card.tsx b/apps/web/src/app/[locale]/tracks/_components/track-challenge-card.tsx
index e991f421..38f1fa76 100644
--- a/apps/web/src/app/[locale]/tracks/_components/track-challenge-card.tsx
+++ b/apps/web/src/app/[locale]/tracks/_components/track-challenge-card.tsx
@@ -3,10 +3,10 @@
import { Check } from '@repo/ui/icons';
import clsx from 'clsx';
import { useIsMobile } from '~/utils/useIsMobile';
-import type { Tracks } from './track-grid';
+import type { Challenge } from '@repo/db/types';
interface TrackChallengeProps {
- challenge: Tracks[number]['trackChallenges'][number]['challenge'];
+ challenge: Challenge;
className?: string;
mock?: boolean;
}
diff --git a/apps/web/src/app/[locale]/tracks/_components/track-enrolled-section.tsx b/apps/web/src/app/[locale]/tracks/_components/track-enrolled-section.tsx
index 08d57e0b..d388664b 100644
--- a/apps/web/src/app/[locale]/tracks/_components/track-enrolled-section.tsx
+++ b/apps/web/src/app/[locale]/tracks/_components/track-enrolled-section.tsx
@@ -3,38 +3,76 @@ import { prisma } from '@repo/db';
import Link from 'next/link';
import { Carousel } from '~/components/ui/carousel';
import { PersonalTrackCard } from './personal-track-card';
+import { Card } from '@repo/ui/components/card';
+import type { HTMLAttributes } from 'react';
+import clsx from 'clsx';
+
+const SkeletonTrack = ({ className, ...rest }: HTMLAttributes<HTMLDivElement>) => (
+ <Card
+ className={clsx(
+ 'm-auto flex w-[300px] gap-4 bg-white bg-opacity-[.03] p-2 backdrop-blur-xl backdrop-filter md:m-0',
+ className,
+ )}
+ {...rest}
+ >
+ <div className="h-16 w-16 flex-none rounded-2xl bg-white bg-opacity-5" />
+ <div className="flex-1 space-y-3 pt-1">
+ <div className="h-3 w-2/3 rounded-lg bg-white bg-opacity-5" />
+ <div className="h-2 w-full rounded-lg bg-white bg-opacity-5" />
+ <div className="h-2 w-full rounded-lg bg-white bg-opacity-5" />
+ </div>
+ </Card>
+);
export async function EnrolledTrackSection() {
const tracks = await getUserEnrolledTracks();
+
return (
<div>
- <div className="container flex items-center justify-between gap-3 px-4 pt-5">
- <h2 className="relative text-3xl font-bold tracking-tight">
- <div className="absolute -left-8 -z-10 h-12 w-32 rounded-full bg-blue-300/50 blur-3xl" />
- Your Tracks
- </h2>
- </div>
- <section className="relative flex w-full flex-row gap-4 overflow-hidden rounded-[2.5rem]">
- <Carousel>
- {tracks.map((t) => (
- <Link
- className="group snap-center focus:outline-none sm:w-[330px] xl:w-[333px]"
- href={`/tracks/${t.id}`}
- key={t.id}
- >
- <PersonalTrackCard track={t} />
- </Link>
- ))}
- {tracks.length == 0 && (
- <div className="w-full items-center" key="helper-track">
- <div className="flex h-[30vh] flex-col items-center justify-center">
- <h1 className="text-2xl font-bold">No Tracks Yet.</h1>
- <p className="text-xl">Start your journey by enrolling in a track.</p>
- </div>
- </div>
- )}
- </Carousel>
- </section>
+ {tracks.length ? (
+ <>
+ <div className="container flex items-center justify-between gap-3 px-4 pt-5">
+ <h2 className="relative text-3xl font-bold tracking-tight">
+ <div className="absolute -left-8 -z-10 h-12 w-32 rounded-full bg-blue-300/50 blur-3xl" />
+ Your Tracks
+ </h2>
+ </div>
+
+ <section className="relative flex w-full flex-row gap-4 overflow-hidden rounded-[2.5rem]">
+ <Carousel>
+ {tracks.map((t) => (
+ <Link
+ className="group w-[250px] flex-none snap-center focus:outline-none sm:w-[330px] xl:w-[333px]"
+ href={`/tracks/${t.id}`}
+ key={t.id}
+ >
+ <PersonalTrackCard track={t} />
+ </Link>
+ ))}
+ </Carousel>
+ </section>
+ </>
+ ) : (
+ <div
+ className="relative my-10 grid min-h-[246px] w-full items-center gap-2 px-5 md:grid-cols-2 md:gap-10"
+ key="helper-track"
+ >
+ <div className="text-center md:text-right">
+ <h1 className="text-lg font-bold">No Tracks Yet.</h1>
+ <p className="text-muted-foreground mt-2 text-sm">
+ Start your journey by enrolling in a track.
+ </p>
+ </div>
+
+ <div className="absolute left-2/4 hidden h-full w-[1px] -translate-x-2/4 transform bg-white bg-opacity-5 md:block" />
+
+ <div className="row-start-1 md:row-auto">
+ <SkeletonTrack />
+ <SkeletonTrack className="bg-opacity-[.01 -translate-y-4 translate-x-10" />
+ <div className="absolute top-1/3 -z-10 h-12 w-32 rounded-full bg-blue-300/50 blur-3xl" />
+ </div>
+ </div>
+ )}
</div>
);
}
diff --git a/apps/web/src/app/[locale]/tracks/_components/track-grid.tsx b/apps/web/src/app/[locale]/tracks/_components/track-grid.tsx
index efa91c6c..1516684c 100644
--- a/apps/web/src/app/[locale]/tracks/_components/track-grid.tsx
+++ b/apps/web/src/app/[locale]/tracks/_components/track-grid.tsx
@@ -1,12 +1,13 @@
import { prisma } from '@repo/db';
import { TrackCard } from './track-card';
+import { getServerAuthSession } from '@repo/auth/server';
export async function TrackGrid() {
const tracks = await getTracks();
return (
<div className="container flex items-center justify-between gap-3">
- <section className="grid w-full grid-flow-row grid-cols-1 gap-10 md:grid-cols-2 lg:grid-cols-3">
- {tracks?.map((t) => <TrackCard key={`track-${t.id}`} track={t} />)}
+ <section className="grid w-full grid-flow-row grid-cols-1 gap-6 lg:grid-cols-2 xl:grid-cols-3">
+ {tracks?.map((t, i) => <TrackCard key={`track-${t.id}`} index={i} track={t} />)}
</section>
</div>
);
@@ -17,24 +18,25 @@ export type Tracks = Awaited<ReturnType<typeof getTracks>>;
/**
* Fetches all tracks.
*/
-function getTracks() {
+async function getTracks() {
+ const session = await getServerAuthSession();
+ console.log(session?.user.id);
+
return prisma.track.findMany({
include: {
- trackChallenges: {
- include: {
- challenge: true,
+ _count: {
+ select: {
+ trackChallenges: true,
},
- orderBy: {
- orderId: 'asc',
+ },
+ enrolledUsers: {
+ where: {
+ id: session?.user.id ?? '',
},
- take: 3,
},
},
where: {
visible: true,
},
- orderBy: {
- title: 'asc',
- },
});
}
diff --git a/packages/ui/src/icons.ts b/packages/ui/src/icons.ts
index 9d8b970e..06624591 100644
--- a/packages/ui/src/icons.ts
+++ b/packages/ui/src/icons.ts
@@ -53,4 +53,5 @@ export {
ArrowUpNarrowWide,
ChevronRightSquare,
MessagesSquare,
+ Swords,
} from 'lucide-react';