Skip to content

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

feat: tracks (#451)

Ayush6c1f3045c179
diff --git a/apps/web/src/app/explore/_components/section-skeleton.tsx b/apps/web/src/app/explore/_components/explore-section-skeleton.tsx
similarity index 100%
rename from apps/web/src/app/explore/_components/section-skeleton.tsx
rename to apps/web/src/app/explore/_components/explore-section-skeleton.tsx
diff --git a/apps/web/src/app/explore/_components/section.tsx b/apps/web/src/app/explore/_components/explore-section.tsx
similarity index 50%
rename from apps/web/src/app/explore/_components/section.tsx
rename to apps/web/src/app/explore/_components/explore-section.tsx
index 32cd8bea..b7942850 100644
--- a/apps/web/src/app/explore/_components/section.tsx
+++ b/apps/web/src/app/explore/_components/explore-section.tsx
@@ -1,21 +1,33 @@
-import { Diamond } from '@repo/ui/icons';
import type { Difficulty, Tags } from '@repo/db/types';
+import Link from 'next/link';
+import { ExploreCard } from './explore-card';
import type { ExploreChallengeData } from './explore.action';
-import { ExploreCarousel } from './section-carousel';
import { ViewMoreButton } from './view-more-button';
+import { Carousel } from '~/components/ui/carousel';
-interface Props {
+interface SectionProps {
title: string;
fetcher: (tagOrDifficulty: string, take: number) => ExploreChallengeData;
/**
- * Slug for querying challenges on `/explore/<slug>`.
- * - Make sure it's either a `DIFFICULTY` or `TAGS`. Anything else will return in not found.
- * - Case doesn't matter since we trim & uppercase before querying db.
+ * This is used by UI to apply the right colors. You still need to manually specify the
+ * `redirectRoute` for view-more button to work.
*/
- moreRoute: Difficulty | Tags;
+ tag: Difficulty | Tags;
+ /**
+ * The route view-more button takes.
+ */
+ redirectRoute: string;
}
-const TITLES_BY_DIFFICULTY = {
+const difficultyToNumber = {
+ BEGINNER: 0,
+ EASY: 1,
+ MEDIUM: 2,
+ HARD: 3,
+ EXTREME: 4,
+} as const;
+
+const TITLES_BY_TAG = {
POPULAR: '',
NEWEST: '',
BEGINNER:
@@ -28,7 +40,7 @@ const TITLES_BY_DIFFICULTY = {
'bg-clip-text text-transparent bg-gradient-to-r from-orange-600 to-orange-500 dark:from-orange-400 dark:to-orange-100',
};
-const COLORS_BY_DIFFICULTY = {
+export const COLORS_BY_TAGS = {
POPULAR: 'dark:bg-pink-300 bg-pink-600/50',
NEWEST: 'dark:bg-orange-300 bg-orange-500/50',
BEGINNER: 'dark:bg-pink-300 bg-pink-600/50',
@@ -36,25 +48,39 @@ const COLORS_BY_DIFFICULTY = {
MEDIUM: 'dark:bg-yellow-300 bg-yellow-600/50',
HARD: 'dark:bg-red-300 bg-red-600/50',
EXTREME: 'dark:bg-orange-300 bg-orange-600/50',
-};
+} as const;
-export async function ExploreSection({ title, fetcher, moreRoute }: Props) {
- const challenges = await fetcher(moreRoute.trim().toUpperCase(), 6);
+export async function ExploreSection({ title, fetcher, tag, redirectRoute }: SectionProps) {
+ const challenges = await fetcher(tag.trim().toUpperCase(), 6);
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 ${TITLES_BY_DIFFICULTY[moreRoute]}`}
- >
+ <h2 className={`relative text-3xl font-bold tracking-tight ${TITLES_BY_TAG[tag]}`}>
<div
- className={`absolute -left-8 -z-10 h-12 w-32 rounded-full bg-pink-300/50 blur-3xl ${COLORS_BY_DIFFICULTY[moreRoute]}`}
+ className={`absolute -left-8 -z-10 h-12 w-32 rounded-full bg-pink-300/50 blur-3xl ${COLORS_BY_TAGS[tag]}`}
/>
{title}
</h2>
- <ViewMoreButton challenges={challenges} moreRoute={moreRoute} />
+ <ViewMoreButton redirectRoute={redirectRoute} tag={tag} />
</div>
<section className="relative flex w-full flex-col overflow-hidden rounded-[2.5rem]">
- <ExploreCarousel challenges={challenges} />
+ <Carousel>
+ {challenges
+ .sort((a, b) =>
+ difficultyToNumber[a.difficulty] !== difficultyToNumber[b.difficulty]
+ ? difficultyToNumber[a.difficulty] - difficultyToNumber[b.difficulty]
+ : a.name.localeCompare(b.name),
+ )
+ .map((challenge) => (
+ <Link
+ className="group snap-center focus:outline-none sm:w-[330px] xl:w-[333px]"
+ href={`/challenge/${challenge.id}`}
+ key={challenge.id}
+ >
+ <ExploreCard challenge={challenge} key={`challenge-${challenge.id}`} />
+ </Link>
+ ))}
+ </Carousel>
</section>
</div>
);
diff --git a/apps/web/src/app/explore/_components/explore-slug-skeleton.tsx b/apps/web/src/app/explore/_components/explore-slug-skeleton.tsx
index c103ca78..1d493682 100644
--- a/apps/web/src/app/explore/_components/explore-slug-skeleton.tsx
+++ b/apps/web/src/app/explore/_components/explore-slug-skeleton.tsx
@@ -1,4 +1,4 @@
-import { ExploreSectionSkeleton } from './section-skeleton';
+import { ExploreSectionSkeleton } from './explore-section-skeleton';
export function ExploreSlugSkeleton() {
return (
diff --git a/apps/web/src/app/explore/_components/index.tsx b/apps/web/src/app/explore/_components/index.tsx
index 0b60e3bc..070b4098 100644
--- a/apps/web/src/app/explore/_components/index.tsx
+++ b/apps/web/src/app/explore/_components/index.tsx
@@ -1,7 +1,7 @@
import { Suspense } from 'react';
+import { ExploreSection } from './explore-section';
+import { ExploreSectionSkeleton } from './explore-section-skeleton';
import { getChallengesByTagOrDifficulty } from './explore.action';
-import { ExploreSection } from './section';
-import { ExploreSectionSkeleton } from './section-skeleton';
import { Footsies } from '~/components/ui/footsies';
// CI fails without this
@@ -27,28 +27,32 @@ export async function Explore() {
<ExploreSection
title="πŸ’• Most Popular"
fetcher={getChallengesByTagOrDifficulty}
- moreRoute="POPULAR"
+ tag="POPULAR"
+ redirectRoute="/explore/popular"
/>
</Suspense>
<Suspense fallback={<ExploreSectionSkeleton />}>
<ExploreSection
title="πŸ”₯ Newest"
fetcher={getChallengesByTagOrDifficulty}
- moreRoute="NEWEST"
+ tag="NEWEST"
+ redirectRoute="/explore/newest"
/>
</Suspense>
<Suspense fallback={<ExploreSectionSkeleton />}>
<ExploreSection
title="Great for Beginners"
fetcher={getChallengesByTagOrDifficulty}
- moreRoute="EASY"
+ tag="EASY"
+ redirectRoute="/explore/easy"
/>
</Suspense>
<Suspense fallback={<ExploreSectionSkeleton />}>
<ExploreSection
title="Great for Enthusiasts"
fetcher={getChallengesByTagOrDifficulty}
- moreRoute="MEDIUM"
+ tag="MEDIUM"
+ redirectRoute="/explore/medium"
/>
</Suspense>
@@ -56,7 +60,8 @@ export async function Explore() {
<ExploreSection
title="For the Experts"
fetcher={getChallengesByTagOrDifficulty}
- moreRoute="HARD"
+ tag="HARD"
+ redirectRoute="/explore/hard"
/>
</Suspense>
<Footsies />
diff --git a/apps/web/src/app/explore/_components/view-more-button.tsx b/apps/web/src/app/explore/_components/view-more-button.tsx
index ec275385..14c9dc68 100644
--- a/apps/web/src/app/explore/_components/view-more-button.tsx
+++ b/apps/web/src/app/explore/_components/view-more-button.tsx
@@ -3,9 +3,8 @@
import { Button } from '@repo/ui';
import { ChevronRight } from 'lucide-react';
import { useRouter } from 'next/navigation';
-import type { ExploreChallengeData } from './explore.action';
-const BUTTONS_BY_DIFFICULTY = {
+export const BUTTON_BY_TAGS = {
POPULAR:
'bg-neutral-500/10 text-neutral-700 hover:text-neutral-700 dark:text-neutral-300 dark:bg-neutral-300/10 hover:bg-neutral-500/20 dark:hover:bg-neutral-300/20',
NEWEST:
@@ -18,21 +17,21 @@ const BUTTONS_BY_DIFFICULTY = {
HARD: 'bg-red-500/10 text-red-700 hover:text-red-700 dark:text-red-300 dark:bg-red-300/10 hover:bg-red-500/20 dark:hover:bg-red-300/20',
EXTREME:
'bg-orange-500/10 text-orange-700 hover:text-orange-700 dark:text-orange-300 dark:bg-orange-300/10 hover:bg-orange-500/20 dark:hover:bg-orange-300/20',
-};
+} as const;
interface ViewMoreButtonProps {
- challenges: Awaited<ExploreChallengeData>;
- moreRoute: keyof typeof BUTTONS_BY_DIFFICULTY;
+ redirectRoute: string;
+ tag: keyof typeof BUTTON_BY_TAGS;
}
-export function ViewMoreButton({ challenges, moreRoute }: ViewMoreButtonProps) {
+export function ViewMoreButton({ redirectRoute, tag }: ViewMoreButtonProps) {
const router = useRouter();
return (
<Button
className={`group items-center whitespace-nowrap rounded-full py-2 pl-4 pr-3 backdrop-blur-sm
- ${BUTTONS_BY_DIFFICULTY[moreRoute]}`}
+ ${BUTTON_BY_TAGS[tag]}`}
onClick={() => {
- router.push(`/explore/${moreRoute}`);
+ router.push(redirectRoute);
}}
variant="ghost"
>
diff --git a/apps/web/src/app/tracks/[slug]/page.tsx b/apps/web/src/app/tracks/[slug]/page.tsx
new file mode 100644
index 00000000..087dcd2f
--- /dev/null
+++ b/apps/web/src/app/tracks/[slug]/page.tsx
@@ -0,0 +1,14 @@
+import { TrackDetail } from '../_components/track-details';
+
+export const dynamic = 'force-dynamic';
+
+interface Props {
+ params: {
+ slug: string;
+ };
+}
+
+// todo: write a suspense skeleton...
+export default function Page({ params }: Props) {
+ return <TrackDetail slug={params.slug} />;
+}
diff --git a/apps/web/src/app/tracks/_components/enroll-button.tsx b/apps/web/src/app/tracks/_components/enroll-button.tsx
new file mode 100644
index 00000000..eea7ba25
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/enroll-button.tsx
@@ -0,0 +1,43 @@
+'use client';
+
+import { Button, toast } from '@repo/ui';
+import { useRouter } from 'next/navigation';
+import type { enrollUserInTrack, unenrollUserFromTrack } from './track.action';
+
+interface EnrollButtonProps {
+ action: typeof enrollUserInTrack | typeof unenrollUserFromTrack;
+ text: string;
+ trackId: number;
+}
+
+export function EnrollButton({ action, text, trackId }: EnrollButtonProps) {
+ const router = useRouter();
+ return (
+ <Button
+ onClick={async () => {
+ try {
+ await action(trackId);
+ router.refresh();
+ toast({
+ title: 'Success',
+ variant: 'success',
+ description: <p>You're now successfully {text.toLowerCase()}ed the track.</p>,
+ });
+ } catch (e) {
+ if (process.env.NODE_ENV === 'development') {
+ console.log(e);
+ }
+ toast({
+ title: 'Error',
+ variant: 'destructive',
+ description: (
+ <p>There was an error trying to {text.toLowerCase()} you from the track.</p>
+ ),
+ });
+ }
+ }}
+ >
+ {text}
+ </Button>
+ );
+}
diff --git a/apps/web/src/app/tracks/_components/index.tsx b/apps/web/src/app/tracks/_components/index.tsx
index cb209f3c..748595a2 100644
--- a/apps/web/src/app/tracks/_components/index.tsx
+++ b/apps/web/src/app/tracks/_components/index.tsx
@@ -1,5 +1,7 @@
import { getServerAuthSession, type Session } from '@repo/auth/server';
import { prisma } from '@repo/db';
+import { EnrolledTrackSection } from './track-enrolled-section';
+import { PopularTrackSection } from './track-popular-section';
export async function Tracks() {
const session = await getServerAuthSession();
@@ -8,48 +10,89 @@ export async function Tracks() {
const tracks = await getTracks();
return (
- <div>
- <div>
- {enrolledTracks?.tracks.map((et) => {
- return (
- <div key={et.id}>
- <div>{et.title}</div>
- <div>{et.description}</div>
- </div>
- );
- })}
+ <div className="flex flex-col gap-8 py-8 md:gap-10 md:py-10">
+ <div className="container">
+ <h3 className="mb-1 text-2xl font-bold tracking-wide text-neutral-900/40 dark:text-white/40">
+ Welcome to
+ </h3>
+ <h1 className="mb-8 text-4xl font-bold tracking-tight text-neutral-900 dark:text-white">
+ TypeHero Tracks
+ </h1>
+ <p className=" max-w-[69ch] text-lg leading-10 text-neutral-600 dark:text-white/50">
+ TypeHero provides a curated collection of diverse coding challenges grouped into different
+ tracks, offering a dynamic learning path for developers to enhance their skills.
+ </p>
</div>
- {tracks?.map((t) => {
- return (
- <div key={t.id}>
- <div>{t.title}</div>
- <div>{t.description}</div>
- </div>
- );
- })}
+ {session ? (
+ <EnrolledTrackSection
+ key="enrolled-track-section"
+ title="Your Tracks"
+ tracks={enrolledTracks}
+ />
+ ) : null}
+ <PopularTrackSection
+ key="popular-track-section"
+ title="Popular"
+ tag="POPULAR"
+ tracks={tracks}
+ />
</div>
);
}
+export type EnrolledTracks = Awaited<ReturnType<typeof getUserEnrolledTracks>>;
+
+/**
+ * Fetches user enrolled tracks based on current session.
+ */
function getUserEnrolledTracks(session: Session | null) {
- return prisma.user.findFirst({
+ return prisma.track.findMany({
where: {
- id: session?.user.id,
+ enrolledUsers: {
+ some: {
+ id: session?.user.id,
+ },
+ },
},
- select: {
- tracks: {
- orderBy: {
- title: 'asc',
+ include: {
+ trackChallenges: {
+ include: {
+ challenge: {
+ include: {
+ submission: {
+ where: {
+ userId: session?.user.id,
+ },
+ },
+ },
+ },
+ },
+ },
+ _count: {
+ select: {
+ enrolledUsers: true,
},
},
},
+ orderBy: {
+ title: 'asc',
+ },
});
}
+
+export type Tracks = Awaited<ReturnType<typeof getTracks>>;
+
+/**
+ * Fetches all tracks.
+ */
function getTracks() {
return prisma.track.findMany({
include: {
- trackChallenges: true,
- user: true,
+ trackChallenges: {
+ include: {
+ challenge: true,
+ },
+ },
},
where: {
visible: true,
diff --git a/apps/web/src/app/tracks/_components/personal-track-card.tsx b/apps/web/src/app/tracks/_components/personal-track-card.tsx
new file mode 100644
index 00000000..04a5c4e9
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/personal-track-card.tsx
@@ -0,0 +1,54 @@
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@repo/ui';
+import { TrendingUpIcon } from '@repo/ui/icons';
+import clsx from 'clsx';
+import type { EnrolledTracks } from '.';
+import { TrackProgress } from './track-progress';
+
+interface PersonalTrackCardProps {
+ track: EnrolledTracks[number];
+}
+
+export function PersonalTrackCard({ track }: PersonalTrackCardProps) {
+ // Calculates the total number of successful challenges.
+ function calulcateCompletedChallenges(): number {
+ let completedChallenges = 0;
+ for (const trackChallenge of track.trackChallenges) {
+ for (const submission of trackChallenge.challenge.submission) {
+ if (submission.isSuccessful) {
+ completedChallenges++;
+ }
+ }
+ }
+ return completedChallenges;
+ }
+
+ return (
+ <Card
+ className={clsx(
+ 'group/card bg-background hover:bg-card-hovered relative overflow-hidden duration-300 sm:min-w-[300px] xl:min-w-[333px]',
+ 'dark:group-focus:blue-blue-300 hover:border-blue-500 group-focus:border-blue-500 dark:hover:border-blue-300',
+ 'hover:shadow-[0_0_1rem_-0.15rem_#a7d8f9] group-focus:shadow-[0_0_1rem_-0.15rem_#a7d8f9]',
+ )}
+ >
+ <CardHeader className="relative flex flex-col items-start gap-1 pb-0">
+ <CardTitle className="max-w-[75%] truncate text-2xl duration-300">{track.title}</CardTitle>
+ <div className="flex items-center gap-6 text-center duration-300">
+ <div className="flex items-center gap-2 text-sm">
+ <TrendingUpIcon size={18} />
+ {track._count.enrolledUsers}
+ </div>
+ </div>
+ <TrackProgress
+ completedChallenges={calulcateCompletedChallenges()}
+ totalChallenges={track.trackChallenges.length}
+ />
+ </CardHeader>
+ <CardContent className="relative flex flex-col justify-between gap-2 rounded-xl p-6 pb-0 duration-300">
+ <CardDescription className="relative h-20 w-fit overflow-hidden pb-4">
+ <div className="pointer-events-none absolute inset-0 h-full w-full shadow-[inset_0_-1.5rem_1rem_-0.5rem_hsl(var(--card))] duration-300 group-hover/card:shadow-[inset_0_-1.5rem_1rem_-0.5rem_hsl(var(--card-hovered))] group-focus:shadow-[inset_0_-1.5rem_1rem_-0.5rem_hsl(var(--card-hovered))]" />
+ {track.description}
+ </CardDescription>
+ </CardContent>
+ </Card>
+ );
+}
diff --git a/apps/web/src/app/tracks/_components/track-card.tsx b/apps/web/src/app/tracks/_components/track-card.tsx
new file mode 100644
index 00000000..469fd006
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/track-card.tsx
@@ -0,0 +1,70 @@
+'use client';
+
+import { Button } from '@repo/ui';
+import clsx from 'clsx';
+import { useRouter } from 'next/navigation';
+import type { Tracks } from '~/app/tracks/_components';
+import { TrackChallenge } from './track-challenge-card';
+
+interface TrackProps {
+ track: Tracks[number];
+}
+
+export function TrackCard({ track }: TrackProps) {
+ const router = useRouter();
+ // todo: help resolve max-md issue on hover.
+ return (
+ <div className="relative w-full">
+ <div className="m-2 w-full">
+ <div
+ className={clsx(
+ 'relative inset-0 flex max-w-[400px] flex-col justify-start space-y-4 p-6',
+ '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>
+ </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>
+ {/** If you want to show any other statistics at a glance. This might be a good section. Uncomment & remove the children within it before using it. */}
+ {/* <div className="flex w-full flex-row justify-start gap-3 rounded-b-lg rounded-t-xl bg-neutral-500/10 p-2 pl-3">
+ <TrendingUpIcon size={18} />
+ <span className="text-muted-foreground flex items-center gap-1 text-sm font-semibold tracking-wide">
+ {`${prettifyNumbers(track._count.enrolledUsers)}`}
+ </span>
+ </div> */}
+ <div className="flex flex-col gap-2">
+ {track.trackChallenges
+ // get the first 3
+ .slice(0, 3)
+ .sort((a, b) => {
+ return a.orderId - b.orderId;
+ })
+ .map((trackChallenge, idx) => {
+ return (
+ <TrackChallenge
+ challenge={trackChallenge.challenge}
+ key={`track-challenge-${trackChallenge.id}-${track.id}`}
+ />
+ );
+ })}
+ <Button
+ variant="outline"
+ onClick={() => {
+ router.push(`/tracks/${track.id}`);
+ }}
+ >
+ View
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/tracks/_components/track-challenge-card.tsx b/apps/web/src/app/tracks/_components/track-challenge-card.tsx
new file mode 100644
index 00000000..90d831fe
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/track-challenge-card.tsx
@@ -0,0 +1,77 @@
+'use client';
+
+import { Check } from '@repo/ui/icons';
+import clsx from 'clsx';
+import type { Tracks } from '~/app/tracks/_components';
+import { useIsMobile } from '~/utils/useIsMobile';
+
+interface TrackChallengeProps {
+ challenge: Tracks[number]['trackChallenges'][number]['challenge'];
+ className?: string;
+ mock?: boolean;
+}
+
+const COLORS_BY_DIFFICULTY = {
+ BEGINNER: 'text-pink-600 dark:text-pink-300',
+ EASY: 'text-emerald-600 dark:text-emerald-300',
+ MEDIUM: 'text-yellow-600 dark:text-yellow-300',
+ HARD: 'text-red-600 dark:text-red-300',
+ EXTREME: 'text-orange-600 dark:text-orange-300',
+} as const;
+
+const BGS_BY_DIFFICULTY = {
+ BEGINNER: 'to-pink-600/20 dark:to-pink-300/20',
+ EASY: 'to-emerald-600/20 dark:to-emerald-300/20',
+ MEDIUM: 'to-yellow-600/20 dark:to-yellow-300/20',
+ HARD: 'to-red-600/20 dark:to-red-300/20',
+ EXTREME: 'to-orange-600/20 dark:to-orange-300/20',
+} as const;
+
+export function TrackChallenge({ challenge, className, mock }: TrackChallengeProps) {
+ const isMobile = useIsMobile();
+ return (
+ <label
+ htmlFor={challenge.id.toString()}
+ className="group/challenge flex cursor-pointer flex-col items-center pt-2"
+ >
+ <div
+ className={clsx(
+ `flex w-full cursor-pointer items-center justify-between gap-3 overflow-hidden rounded-lg bg-gradient-to-r from-neutral-500/10 ${
+ BGS_BY_DIFFICULTY[challenge.difficulty]
+ } from-75% to-100% p-4 py-2 text-black/90 duration-300 group-active/challenge:bg-neutral-500/40 group-active/challenge:duration-75 dark:text-white/90 sm:py-4`,
+ className,
+ !isMobile &&
+ 'group-hover/challenge:scale-105 group-hover/challenge:rounded-xl group-hover/challenge:bg-neutral-500/20',
+ )}
+ >
+ <div className="relative flex items-center gap-3 text-xs sm:text-base">
+ {mock == true && (
+ <>
+ <input
+ className="peer hidden appearance-none"
+ type="checkbox"
+ id={challenge.id.toString()}
+ />
+ <div className="h-5 w-5 rounded-full border border-black/70 bg-black/10 duration-75 peer-checked:border-transparent peer-checked:bg-green-600/80 dark:border-white/50 dark:bg-white/10 peer-checked:dark:bg-green-300/80" />
+ <Check className="absolute left-1 my-auto h-3 w-3 scale-0 stroke-[4] text-white duration-300 peer-checked:scale-100 dark:text-black" />
+ </>
+ )}
+ {challenge.name}
+ </div>
+ <div
+ className={`relative text-xs font-medium tracking-wide ${
+ COLORS_BY_DIFFICULTY[challenge.difficulty]
+ }`}
+ >
+ <div
+ className={`absolute right-0 top-1/2 h-12 w-12 -translate-y-1/2 blur-3xl ${
+ BGS_BY_DIFFICULTY[challenge.difficulty]
+ }`}
+ />
+ {challenge.difficulty[0]}
+ {challenge.difficulty.substring(1, challenge.difficulty.length).toLowerCase()}
+ </div>
+ </div>
+ </label>
+ );
+}
diff --git a/apps/web/src/app/tracks/_components/track-details.tsx b/apps/web/src/app/tracks/_components/track-details.tsx
new file mode 100644
index 00000000..3a3aae44
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/track-details.tsx
@@ -0,0 +1,41 @@
+import { getServerAuthSession } from '@repo/auth/server';
+import { EnrollButton } from './enroll-button';
+import { enrollUserInTrack, getTrackDetails, unenrollUserFromTrack } from './track.action';
+
+interface TrackDetailProps {
+ // trackid
+ slug: string;
+}
+
+export async function TrackDetail({ slug }: TrackDetailProps) {
+ const session = await getServerAuthSession();
+ const trackId = parseInt(slug);
+ const trackChallenge = await getTrackDetails(trackId);
+ const isEnrolled = trackChallenge?.enrolledUsers.findIndex(
+ (user) => user.id === session?.user.id,
+ );
+
+ return (
+ <div className="container flex flex-col gap-8 py-5 md:gap-16 md:pb-20">
+ <div className="container">
+ <h3 className="mb-1 text-2xl font-bold tracking-wide text-neutral-900/40 dark:text-white/40">
+ Track
+ </h3>
+ <h1 className="mb-8 text-4xl font-bold tracking-tight text-neutral-900 dark:text-white">
+ {trackChallenge?.title}
+ </h1>
+ <p className=" max-w-[69ch] text-lg leading-10 text-neutral-600 dark:text-white/50">
+ {trackChallenge?.description}
+ </p>
+ </div>
+
+ <div className="flex flex-row">
+ {isEnrolled === -1 ? (
+ <EnrollButton action={enrollUserInTrack} trackId={trackId} text="Enroll" />
+ ) : (
+ <EnrollButton action={unenrollUserFromTrack} trackId={trackId} text="Unenroll" />
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/tracks/_components/track-enrolled-section.tsx b/apps/web/src/app/tracks/_components/track-enrolled-section.tsx
new file mode 100644
index 00000000..0de88fd2
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/track-enrolled-section.tsx
@@ -0,0 +1,43 @@
+import Link from 'next/link';
+import { PersonalTrackCard } from './personal-track-card';
+import type { EnrolledTracks } from '.';
+import { Carousel } from '~/components/ui/carousel';
+
+interface EnrolledTrackSectionProps {
+ title: string;
+ tracks: EnrolledTracks;
+}
+
+export function EnrolledTrackSection({ title, tracks }: EnrolledTrackSectionProps) {
+ 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" />
+ {title}
+ </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>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/tracks/_components/track-popular-section.tsx b/apps/web/src/app/tracks/_components/track-popular-section.tsx
new file mode 100644
index 00000000..368f2381
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/track-popular-section.tsx
@@ -0,0 +1,28 @@
+import type { Difficulty, Tags } from '@repo/db/types';
+import { COLORS_BY_TAGS } from '~/app/explore/_components/explore-section';
+import { TrackCard } from '~/app/tracks/_components/track-card';
+import type { Tracks } from '.';
+
+interface PopularTrackSectionProps {
+ title: string;
+ tracks: Tracks;
+ tag: Difficulty | Tags;
+}
+
+export function PopularTrackSection({ title, tracks, tag }: PopularTrackSectionProps) {
+ 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-neutral-300/50 blur-3xl ${COLORS_BY_TAGS[tag]}`}
+ />
+ {title}
+ </h2>
+ </div>
+ <section className="grid w-full grid-flow-row grid-cols-1 gap-4 overflow-hidden rounded-[2.5rem] p-8 md:grid-cols-2 lg:grid-cols-3">
+ {tracks?.map((t) => <TrackCard key={`popular-track-${t.id}`} track={t} />)}
+ </section>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/tracks/_components/track-progress.tsx b/apps/web/src/app/tracks/_components/track-progress.tsx
new file mode 100644
index 00000000..c9c387c1
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/track-progress.tsx
@@ -0,0 +1,20 @@
+import { Progress } from '@repo/ui';
+
+interface TrackProgressProps {
+ totalChallenges: number;
+ completedChallenges: number;
+}
+
+export function TrackProgress({ completedChallenges, totalChallenges }: TrackProgressProps) {
+ return (
+ <div className="flex w-full flex-col">
+ <div className="mb-2 flex flex-row items-center justify-between">
+ <span className="text-muted-foreground text-sm">Progress</span>
+ <span className="text-muted-foreground text-sm">
+ {completedChallenges}/{totalChallenges}
+ </span>
+ </div>
+ <Progress value={(completedChallenges / totalChallenges) * 100} />
+ </div>
+ );
+}
diff --git a/apps/web/src/app/tracks/_components/track.action.ts b/apps/web/src/app/tracks/_components/track.action.ts
new file mode 100644
index 00000000..7bfc612f
--- /dev/null
+++ b/apps/web/src/app/tracks/_components/track.action.ts
@@ -0,0 +1,75 @@
+'use server';
+
+import { getServerAuthSession } from '@repo/auth/server';
+import { prisma } from '@repo/db';
+
+/**
+ * Enrolls the session user in the track given a track id.
+ * @param id The track id.
+ */
+export async function enrollUserInTrack(id: number) {
+ const session = await getServerAuthSession();
+ return prisma.track.update({
+ where: {
+ id,
+ },
+ data: {
+ enrolledUsers: {
+ connect: {
+ id: session?.user.id,
+ },
+ },
+ },
+ });
+}
+
+/**
+ * Un-enrolls the session user in the track given a track id.
+ * @param id The track id.
+ */
+export async function unenrollUserFromTrack(id: number) {
+ const session = await getServerAuthSession();
+ return prisma.track.update({
+ where: {
+ id,
+ },
+ data: {
+ enrolledUsers: {
+ disconnect: {
+ id: session?.user.id,
+ },
+ },
+ },
+ });
+}
+
+/**
+ * Fetches the track details given a track id.
+ * @param id The track id.
+ */
+export async function getTrackDetails(id: number) {
+ const session = await getServerAuthSession();
+
+ return prisma.track.findUnique({
+ where: {
+ id,
+ },
+ include: {
+ _count: {
+ select: {
+ enrolledUsers: true,
+ },
+ },
+ trackChallenges: true,
+ enrolledUsers: {
+ where: {
+ id: session?.user.id,
+ },
+ // ensure's we don't leak user data other than the necessary parameters.
+ select: {
+ id: true,
+ },
+ },
+ },
+ });
+}
diff --git a/apps/web/src/components/landing/feature-card.tsx b/apps/web/src/components/landing/feature-card.tsx
index 4071b715..82a0738b 100644
--- a/apps/web/src/components/landing/feature-card.tsx
+++ b/apps/web/src/components/landing/feature-card.tsx
@@ -1,6 +1,6 @@
'use client';
-import type { Difficulty } from '@repo/db/types';
+import type { Challenge, Difficulty } from '@repo/db/types';
import { Button } from '@repo/ui';
import clsx from 'clsx';
import {
@@ -10,15 +10,16 @@ import {
type MotionStyle,
type MotionValue,
} from 'framer-motion';
-import { Check, Reply } from 'lucide-react';
+import { Reply } from 'lucide-react';
import { useTheme } from 'next-themes';
import Image, { type StaticImageData } from 'next/image';
import { useEffect, useState, type MouseEvent } from 'react';
import { useInView } from 'react-intersection-observer';
import { z } from 'zod';
+import { TrackChallenge } from '~/app/tracks/_components/track-challenge-card';
+import { useIsMobile } from '~/utils/useIsMobile';
import { Markdown } from '../ui/markdown';
import { Steps } from '../wizard/Steps';
-import { useIsMobile } from '~/utils/useIsMobile';
type WrapperStyle = MotionStyle & {
'--x': MotionValue<string>;
@@ -454,98 +455,55 @@ export function CuratedTracksCard(props: CardProps) {
Typescript Foundations
</span>
</div>
-
- {tracks.map((track) => (
- <Track key={track.id} {...track} />
- ))}
+ <div className="flex w-[69%] flex-col">
+ {mockChallenges.map((mockChallenge) => (
+ <TrackChallenge
+ key={`mock-${mockChallenge.id}`}
+ challenge={mockChallenge as Challenge}
+ mock
+ />
+ ))}
+ </div>
</div>
</FeatureCard>
);
}
-interface Track {
- className?: string;
+// note: should always be a subset of Challenge Type
+interface MockTrackChallenge {
difficulty: Difficulty;
- id: string;
- label: string;
+ id: number;
+ name: string;
}
-const COLORS_BY_DIFFICULTY = {
- BEGINNER: 'text-pink-600 dark:text-pink-300',
- EASY: 'text-emerald-600 dark:text-emerald-300',
- MEDIUM: 'text-yellow-600 dark:text-yellow-300',
- HARD: 'text-red-600 dark:text-red-300',
- EXTREME: 'text-orange-600 dark:text-orange-300',
-};
-
-const BGS_BY_DIFFICULTY = {
- BEGINNER: 'to-pink-600/20 dark:to-pink-300/20',
- EASY: 'to-emerald-600/20 dark:to-emerald-300/20',
- MEDIUM: 'to-yellow-600/20 dark:to-yellow-300/20',
- HARD: 'to-red-600/20 dark:to-red-300/20',
- EXTREME: 'to-orange-600/20 dark:to-orange-300/20',
-};
-
-const tracks: Track[] = [
+const mockChallenges: MockTrackChallenge[] = [
{
- id: '2',
- label: 'Infer',
+ id: 2,
+ name: 'Infer',
difficulty: 'EASY',
},
{
- id: '3',
- label: 'Map Types',
+ id: 3,
+ name: 'Map Types',
difficulty: 'MEDIUM',
},
{
- id: '5',
- label: 'Classes',
+ id: 5,
+ name: 'Classes',
difficulty: 'EXTREME',
},
{
- id: '4',
- label: 'Array/Object',
+ id: 4,
+ name: 'Array/Object',
difficulty: 'HARD',
},
{
- id: '1',
- label: 'Generics',
+ id: 1,
+ name: 'Generics',
difficulty: 'BEGINNER',
},
];
-function Track({ className, difficulty, id, label }: Track) {
- const isMobile = useIsMobile();
- return (
- <label
- htmlFor={id}
- className="group/challenge flex w-[69%] cursor-pointer flex-col items-center pt-2"
- >
- <div
- className={clsx(
- `flex w-full cursor-pointer items-center justify-between gap-3 overflow-hidden rounded-lg bg-gradient-to-r from-neutral-500/10 ${BGS_BY_DIFFICULTY[difficulty]} from-75% to-100% p-4 py-2 text-black/90 duration-300 group-active/challenge:bg-neutral-500/40 group-active/challenge:duration-75 dark:text-white/90 sm:py-4`,
- className,
- !isMobile &&
- 'group-hover/challenge:scale-105 group-hover/challenge:rounded-xl group-hover/challenge:bg-neutral-500/20',
- )}
- >
- <div className="relative flex items-center gap-3 text-xs sm:text-base">
- <input className="peer hidden appearance-none" type="checkbox" id={id} />
- <div className="h-5 w-5 rounded-full border border-black/70 bg-black/10 duration-75 peer-checked:border-transparent peer-checked:bg-green-600/80 dark:border-white/50 dark:bg-white/10 peer-checked:dark:bg-green-300/80" />
- <Check className="absolute left-1 my-auto h-3 w-3 scale-0 stroke-[4] text-white duration-300 peer-checked:scale-100 dark:text-black" />
- {label}
- </div>
- <div
- className={`relative text-xs font-medium tracking-wide ${COLORS_BY_DIFFICULTY[difficulty]}`}
- >
- {difficulty[0]}
- {difficulty.substring(1, difficulty.length).toLowerCase()}
- </div>
- </div>
- </label>
- );
-}
-
function useNumberCycler() {
const [currentNumber, setCurrentNumber] = useState(0);
const [dummy, setDummy] = useState(0);
diff --git a/apps/web/src/app/explore/_components/section-carousel.tsx b/apps/web/src/components/ui/carousel.tsx
similarity index 71%
rename from apps/web/src/app/explore/_components/section-carousel.tsx
rename to apps/web/src/components/ui/carousel.tsx
index bce5d663..b4f95504 100644
--- a/apps/web/src/app/explore/_components/section-carousel.tsx
+++ b/apps/web/src/components/ui/carousel.tsx
@@ -1,24 +1,12 @@
'use client';
-import type { Difficulty } from '@repo/db/types';
import { ChevronRight } from '@repo/ui/icons';
-import Link from 'next/link';
-import { useEffect, useRef, useState } from 'react';
-import { ExploreCard } from './explore-card';
-import type { ExploreChallengeData } from './explore.action';
+import { useEffect, useRef, useState, type ReactNode } from 'react';
interface Props {
- challenges: Awaited<ExploreChallengeData>;
+ children: ReactNode;
}
-const difficultyToNumber: Record<Difficulty, number> = {
- BEGINNER: 0,
- EASY: 1,
- MEDIUM: 2,
- HARD: 3,
- EXTREME: 4,
-};
-
-export function ExploreCarousel({ challenges }: Props) {
+export function Carousel({ children }: Props) {
const containerRef = useRef<HTMLDivElement>(null);
const [showLeftButton, setShowLeftButton] = useState(false);
const [showRightButton, setShowRightButton] = useState(true);
@@ -83,21 +71,7 @@ export function ExploreCarousel({ challenges }: Props) {
id="container"
ref={containerRef}
>
- {challenges
- .sort((a, b) =>
- difficultyToNumber[a.difficulty] !== difficultyToNumber[b.difficulty]
- ? difficultyToNumber[a.difficulty] - difficultyToNumber[b.difficulty]
- : a.name.localeCompare(b.name),
- )
- .map((challenge) => (
- <Link
- className="group snap-center focus:outline-none sm:w-[330px] xl:w-[333px]"
- href={`/challenge/${challenge.id}`}
- key={challenge.id}
- >
- <ExploreCard challenge={challenge} key={`challenge-${challenge.id}`} />
- </Link>
- ))}
+ {children}
<button
className="absolute right-5 top-1/2 hidden -translate-y-1/2 rounded-[5rem] border border-neutral-400 bg-neutral-200/50 px-2 py-4 backdrop-blur-sm duration-300 active:scale-75 dark:border-neutral-600 dark:bg-neutral-700/50 sm:block"
id="slideRight"
diff --git a/apps/web/src/components/ui/navigation.tsx b/apps/web/src/components/ui/navigation.tsx
index c24f418d..9d92e0da 100644
--- a/apps/web/src/components/ui/navigation.tsx
+++ b/apps/web/src/components/ui/navigation.tsx
@@ -13,7 +13,7 @@ import {
import { Loader2, LogIn, Moon, Plus, Settings, Settings2, Sun, User } from '@repo/ui/icons';
import { useTheme } from 'next-themes';
import Link from 'next/link';
-import { usePathname } from 'next/navigation';
+import { usePathname, useRouter } from 'next/navigation';
import { useContext, useEffect, useState } from 'react';
import { FeatureFlagContext } from '~/app/feature-flag-provider';
@@ -83,6 +83,13 @@ export function Navigation() {
</div>
</Link>
) : null}
+ {featureFlags?.tracksButton ? (
+ <Link href="/tracks">
+ <div className="hover:text-foreground/80 text-foreground ml-4 transition-colors">
+ Tracks
+ </div>
+ </Link>
+ ) : null}
</div>
<div className="flex">
<div className="flex items-center justify-end gap-2">
@@ -125,6 +132,7 @@ function ThemeButton() {
function LoginButton() {
const [loading, setLoading] = useState(false);
const { data: session, status } = useSession();
+ const router = useRouter();
const isAdmin = session?.user.role.includes(RoleTypes.ADMIN);
const isMod = session?.user.role.includes(RoleTypes.MODERATOR);
@@ -143,6 +151,7 @@ function LoginButton() {
};
const handleSignOut = async () => {
await signOut({ redirect: false });
+ router.refresh();
};
return session ? (
diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.ts
index fb08d52d..d0637b62 100644
--- a/apps/web/src/middleware.ts
+++ b/apps/web/src/middleware.ts
@@ -1,4 +1,4 @@
-import { type NextRequest, NextResponse } from 'next/server';
+import { NextResponse, type NextRequest } from 'next/server';
export function middleware(req: NextRequest) {
if (!process.env.VERCEL_ENV) {
@@ -7,7 +7,7 @@ export function middleware(req: NextRequest) {
const path = req.nextUrl.pathname;
// if path is /explore or /challenge/* and redirect to /waitlist
- if (path === '/explore' || path.startsWith('/challenge/')) {
+ if (path === '/explore' || path.startsWith('/challenge/') || path.startsWith('/tracks/')) {
return NextResponse.redirect(new URL('/waitlist', req.url));
}
diff --git a/apps/web/src/utils/stringUtils.ts b/apps/web/src/utils/stringUtils.ts
index 2899a040..bca11fbd 100644
--- a/apps/web/src/utils/stringUtils.ts
+++ b/apps/web/src/utils/stringUtils.ts
@@ -6,3 +6,15 @@
export const stripProtocolAndWWW = (url: string) => {
return url.replace(/(?:^\w+:|^)\/\//, '').replace(/^www\./, '');
};
+
+/**
+ * Prettifies a number using Web Intl into compact form.
+ * @example
+ * [in] 10000 => [out] 10k
+ * @param n A number you wanna prettify.
+ * @returns string
+ */
+export const prettifyNumbers = (n: number): string => {
+ const formatter = new Intl.NumberFormat('en', { notation: 'compact', compactDisplay: 'short' });
+ return formatter.format(n);
+};
diff --git a/package.json b/package.json
index 8d37fdc3..ce9a9d2f 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
"checks:fix": "turbo format:fix lint:fix typecheck --continue",
"clean": "turbo clean && rm -rf node_modules",
"db:push": "turbo db:push",
+ "db:reset": "turbo db:reset",
"db:seed": "turbo db:seed",
"db:studio": "turbo db:studio",
"dev": "turbo dev --concurrency=1000",
diff --git a/packages/db/schema.prisma b/packages/db/schema.prisma
index 12a443df..1d60c8b1 100644
--- a/packages/db/schema.prisma
+++ b/packages/db/schema.prisma
@@ -156,7 +156,7 @@ model Challenge {
description String @db.MediumText
/// this is a short blue thats shown on the explore card
shortDescription String
- /// Starter code for the challenge
+ /// Starter code for the challenge
code String @db.MediumText
/// Test cases that need to be passed in order have the submission be accepted.
tests String @db.MediumText
@@ -399,6 +399,7 @@ model TrackChallenge {
Track Track? @relation(fields: [trackId], references: [id])
trackId Int?
+ @@unique([challengeId, orderId])
@@index([challengeId])
@@index([trackId])
}
@@ -409,8 +410,5 @@ model Track {
description String
visible Boolean @default(true)
trackChallenges TrackChallenge[]
- user User? @relation(fields: [userId], references: [id])
- userId String?
-
- @@index([userId])
+ enrolledUsers User[]
}
diff --git a/packages/db/seed/index.ts b/packages/db/seed/index.ts
index 4972a35e..3c416f3f 100644
--- a/packages/db/seed/index.ts
+++ b/packages/db/seed/index.ts
@@ -1,5 +1,5 @@
import { faker } from '@faker-js/faker';
-import { PrismaClient, type Prisma } from '@prisma/client';
+import { PrismaClient, type Challenge, type Prisma } from '@prisma/client';
import uuidByString from 'uuid-by-string';
import { loadChallengesFromTypeChallenge } from '../mocks/challenges.mock';
import CommentMock from '../mocks/comment.mock';
@@ -39,6 +39,60 @@ await prisma.challenge.createMany({
export const trashId = uuidByString('trash');
export const gId = uuidByString('g');
+// Seed Tracks
+const TRACK_AMOUNT = 10;
+for (let i = 0; i < TRACK_AMOUNT; i++) {
+ // Get random challenges.
+ const challenges = await getRandomChallenges();
+
+ // Create a track.
+ const track = await prisma.track.create({
+ data: {
+ title: faker.lorem.words(2),
+ description: faker.lorem.sentences(1),
+ visible: true,
+ },
+ });
+
+ // Create/Connect a Track Challenge.
+ for (const challenge of challenges) {
+ // Check if track challenge already exists with the orderId & challengeId.
+ const orderId = faker.number.int({ max: 10, min: 0 });
+ try {
+ const trackChallenge = await prisma.trackChallenge.findUnique({
+ where: {
+ challengeId_orderId: {
+ challengeId: challenge.id,
+ orderId,
+ },
+ },
+ });
+
+ await prisma.track.update({
+ where: {
+ id: track.id,
+ },
+ data: {
+ trackChallenges: {
+ connect: {
+ id: trackChallenge?.id,
+ },
+ },
+ },
+ });
+ } catch (_e) {
+ // Assume does not exist.
+ await prisma.trackChallenge.create({
+ data: {
+ challengeId: challenge.id,
+ trackId: track.id,
+ orderId,
+ },
+ });
+ }
+ }
+}
+
try {
const someChallenge = await prisma.challenge.findFirst({
where: {
@@ -95,3 +149,13 @@ try {
await prisma.$disconnect();
process.exit(1);
}
+
+async function getRandomChallenges(): Promise<Challenge[]> {
+ const challengesCount = await prisma.challenge.count();
+ const skip = Math.floor(Math.random() * (challengesCount - 10));
+ const challenges = await prisma.challenge.findMany({
+ take: 10,
+ skip,
+ });
+ return challenges;
+}
diff --git a/packages/ui/package.json b/packages/ui/package.json
index eb30646b..e0736527 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -35,6 +35,7 @@
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-navigation-menu": "^1.1.3",
"@radix-ui/react-popover": "^1.0.6",
+ "@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-scroll-area": "^1.0.4",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-separator": "^1.0.3",
diff --git a/packages/ui/src/components/progress.tsx b/packages/ui/src/components/progress.tsx
new file mode 100644
index 00000000..853595f0
--- /dev/null
+++ b/packages/ui/src/components/progress.tsx
@@ -0,0 +1,24 @@
+'use client';
+
+import * as ProgressPrimitive from '@radix-ui/react-progress';
+import * as React from 'react';
+import { cn } from '../cn';
+
+const Progress = React.forwardRef<
+ React.ElementRef<typeof ProgressPrimitive.Root>,
+ React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
+>(({ className, value, ...props }, ref) => (
+ <ProgressPrimitive.Root
+ ref={ref}
+ className={cn('bg-secondary relative h-4 w-full overflow-hidden rounded-full', className)}
+ {...props}
+ >
+ <ProgressPrimitive.Indicator
+ className="bg-primary h-full w-full flex-1 transition-all"
+ style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
+ />
+ </ProgressPrimitive.Root>
+));
+Progress.displayName = ProgressPrimitive.Root.displayName;
+
+export { Progress };
diff --git a/packages/ui/src/icons.ts b/packages/ui/src/icons.ts
index da444a3c..0e22ffb2 100644
--- a/packages/ui/src/icons.ts
+++ b/packages/ui/src/icons.ts
@@ -32,11 +32,12 @@ export {
Settings,
Settings2,
Share,
- Sparkle,
Sun,
ThumbsUp,
Trash2,
Triangle,
+ Sparkle,
+ TrendingUpIcon,
Unlock,
User,
X,
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index 7c6dc764..301da5af 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -24,6 +24,7 @@ export * from './components/navigation-menu';
export * from './components/pagination';
export * from './components/paragraph';
export * from './components/popover';
+export * from './components/progress';
export * from './components/scroll-area';
export * from './components/select';
export * from './components/separator';
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a71a6fa0..baf80d8e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -568,6 +568,9 @@ importers:
'@radix-ui/react-popover':
specifier: ^1.0.6
+ '@radix-ui/react-progress':
+ specifier: ^1.0.3
'@radix-ui/react-scroll-area':
specifier: ^1.0.4
@@ -1725,6 +1728,7 @@ packages:
glob: 7.1.7
dev: true
+
resolution: {integrity: sha512-lEXi0QLWUuXlMQRLSk/6JUUoOcjACOKbJYPKe0R1XyF5Kf7/Czdm072UJb3betXqiWw5v54GoOOmyDaUDCn5Rw==}
dependencies:
@@ -2863,6 +2867,27 @@ packages:
react-dom: 18.2.0([email protected])
dev: false
+ resolution: {integrity: sha512-5G6Om/tYSxjSeEdrb1VfKkfZfn/1IlPWd731h2RfPuSbIfNUgfqAwbKfJCg/PP6nuUCTrYzalwHSpSinoWoCag==}
+ peerDependencies:
+ '@types/react': '*'
+ '@types/react-dom': '*'
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ '@types/react-dom':
+ optional: true
+ dependencies:
+ '@babel/runtime': 7.22.6
+ '@radix-ui/react-context': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@types/react': 18.2.20
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-2mUg5Mgcu001VkGy+FfzZyzbmuUWzgWkj3rvv4yu+mLw03+mTzbxZHvfcGyFp2b8EkQeMkpRQ5FiA2Vr2O6TeQ==}
peerDependencies: