Skip to content

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

misc track + ui cleanup (#499)

bautistaaa56380b74bc27
diff --git a/apps/web/src/app/explore/_components/index.tsx b/apps/web/src/app/explore/_components/index.tsx
index 617ff518..b8c3ef73 100644
--- a/apps/web/src/app/explore/_components/index.tsx
+++ b/apps/web/src/app/explore/_components/index.tsx
@@ -11,9 +11,6 @@ export async function Explore() {
return (
<div className="flex flex-col gap-8 py-8 md:gap-10 md:py-10">
<div className="container">
- <div className="mb-1 text-2xl font-bold tracking-wide text-neutral-900/40 dark:text-white/40">
- Welcome to
- </div>
<h1 className="mb-8 text-4xl font-bold tracking-tight text-neutral-900 dark:text-white">
TypeHero Explore
</h1>
diff --git a/apps/web/src/app/tracks/_components/index.tsx b/apps/web/src/app/tracks/_components/index.tsx
index fe427ecf..40d8eddf 100644
--- a/apps/web/src/app/tracks/_components/index.tsx
+++ b/apps/web/src/app/tracks/_components/index.tsx
@@ -1,6 +1,6 @@
import { getServerAuthSession } from '@repo/auth/server';
import { EnrolledTrackSection } from './track-enrolled-section';
-import { PopularTrackSection } from './track-popular-section';
+import { TrackGrid } from './track-grid';
export async function Tracks() {
const session = await getServerAuthSession();
@@ -8,9 +8,6 @@ export async function Tracks() {
return (
<div className="flex flex-col gap-8 py-8 md:gap-10 md:py-10">
<div className="container">
- <div className="mb-1 text-2xl font-bold tracking-wide text-neutral-900/40 dark:text-white/40">
- Welcome to
- </div>
<h1 className="mb-8 text-4xl font-bold tracking-tight text-neutral-900 dark:text-white">
TypeHero Tracks
</h1>
@@ -20,7 +17,7 @@ export async function Tracks() {
</p>
</div>
{session ? <EnrolledTrackSection /> : null}
- <PopularTrackSection />
+ <TrackGrid />
</div>
);
}
diff --git a/apps/web/src/app/tracks/_components/track-card.tsx b/apps/web/src/app/tracks/_components/track-card.tsx
index fc54ce84..3bd4f3a5 100644
--- a/apps/web/src/app/tracks/_components/track-card.tsx
+++ b/apps/web/src/app/tracks/_components/track-card.tsx
@@ -3,8 +3,8 @@
import { Button } from '@repo/ui';
import clsx from 'clsx';
import { useRouter } from 'next/navigation';
-import type { Tracks } from '~/app/tracks/_components/track-popular-section';
import { TrackChallenge } from './track-challenge-card';
+import type { Tracks } from './track-grid';
interface TrackProps {
track: Tracks[number];
@@ -12,7 +12,6 @@ interface TrackProps {
export function TrackCard({ track }: TrackProps) {
const router = useRouter();
- // todo: help resolve max-md issue on hover.
return (
<div className="relative w-full">
<div className="w-full">
@@ -32,28 +31,15 @@ export function TrackCard({ track }: TrackProps) {
{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}`}
- />
- );
- })}
+ {track.trackChallenges.map((trackChallenge) => {
+ return (
+ <TrackChallenge
+ challenge={trackChallenge.challenge}
+ key={`track-challenge-${trackChallenge.id}-${track.id}`}
+ />
+ );
+ })}
<Button
variant="outline"
onClick={() => {
diff --git a/apps/web/src/app/tracks/_components/track-challenge-card.tsx b/apps/web/src/app/tracks/_components/track-challenge-card.tsx
index 29ea8b8e..d3584373 100644
--- a/apps/web/src/app/tracks/_components/track-challenge-card.tsx
+++ b/apps/web/src/app/tracks/_components/track-challenge-card.tsx
@@ -2,8 +2,8 @@
import { Check } from '@repo/ui/icons';
import clsx from 'clsx';
-import type { Tracks } from '~/app/tracks/_components/track-popular-section';
import { useIsMobile } from '~/utils/useIsMobile';
+import type { Tracks } from './track-grid';
interface TrackChallengeProps {
challenge: Tracks[number]['trackChallenges'][number]['challenge'];
@@ -36,7 +36,7 @@ export function TrackChallenge({ challenge, className, mock }: TrackChallengePro
>
<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 ${
+ `flex w-full 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,
diff --git a/apps/web/src/app/tracks/_components/track-popular-section.tsx b/apps/web/src/app/tracks/_components/track-grid.tsx
similarity index 77%
rename from apps/web/src/app/tracks/_components/track-popular-section.tsx
rename to apps/web/src/app/tracks/_components/track-grid.tsx
index 5aca5759..bfe0f8ef 100644
--- a/apps/web/src/app/tracks/_components/track-popular-section.tsx
+++ b/apps/web/src/app/tracks/_components/track-grid.tsx
@@ -1,13 +1,12 @@
import { prisma } from '@repo/db';
-import { COLORS_BY_TAGS } from '~/app/explore/_components/explore-section';
import { TrackCard } from '~/app/tracks/_components/track-card';
-export async function PopularTrackSection() {
+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={`popular-track-${t.id}`} track={t} />)}
+ {tracks?.map((t) => <TrackCard key={`track-${t.id}`} track={t} />)}
</section>
</div>
);
@@ -25,6 +24,10 @@ function getTracks() {
include: {
challenge: true,
},
+ orderBy: {
+ orderId: 'asc',
+ },
+ take: 3,
},
},
where: {
diff --git a/apps/web/src/components/ui/navigation.tsx b/apps/web/src/components/ui/navigation.tsx
index 9d92e0da..1823388c 100644
--- a/apps/web/src/components/ui/navigation.tsx
+++ b/apps/web/src/components/ui/navigation.tsx
@@ -34,7 +34,7 @@ export function Navigation() {
return (
<header className="z-10 w-full">
<nav
- className={`flex h-14 items-center ${
+ className={`flex h-14 items-center text-sm font-medium ${
pathname?.startsWith('/challenge') ? 'px-4' : 'container'
}`}
>
@@ -78,14 +78,14 @@ export function Navigation() {
{featureFlags?.exploreButton ? (
<Link href="/explore">
- <div className="hover:text-foreground/80 text-foreground ml-4 transition-colors">
+ <div className="hover:text-foreground text-foreground/80 ml-4 transition-colors">
Explore
</div>
</Link>
) : null}
{featureFlags?.tracksButton ? (
<Link href="/tracks">
- <div className="hover:text-foreground/80 text-foreground ml-4 transition-colors">
+ <div className="hover:text-foreground text-foreground/80 ml-4 transition-colors">
Tracks
</div>
</Link>
diff --git a/packages/db/seed/index.ts b/packages/db/seed/index.ts
index 3c416f3f..860dad48 100644
--- a/packages/db/seed/index.ts
+++ b/packages/db/seed/index.ts
@@ -39,13 +39,10 @@ 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();
+ const challenges = await getRandomChallenges(i);
- // Create a track.
const track = await prisma.track.create({
data: {
title: faker.lorem.words(2),
@@ -54,43 +51,13 @@ for (let i = 0; i < TRACK_AMOUNT; i++) {
},
});
- // 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,
- },
- });
- }
- }
+ await prisma.trackChallenge.createMany({
+ data: challenges.map((challenge, index) => ({
+ challengeId: challenge.id,
+ trackId: track.id,
+ orderId: index,
+ })),
+ });
}
try {
@@ -150,12 +117,10 @@ try {
process.exit(1);
}
-async function getRandomChallenges(): Promise<Challenge[]> {
- const challengesCount = await prisma.challenge.count();
- const skip = Math.floor(Math.random() * (challengesCount - 10));
+async function getRandomChallenges(iteration: number): Promise<Challenge[]> {
const challenges = await prisma.challenge.findMany({
take: 10,
- skip,
+ skip: 10 * iteration,
});
return challenges;
}