Skip to content

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

Explore page tweaks (#223)

bautistaaac12f4a4f7080
diff --git a/src/app/create/preview/page.tsx b/src/app/create/preview/page.tsx
index 58cab9ff..d647b034 100644
--- a/src/app/create/preview/page.tsx
+++ b/src/app/create/preview/page.tsx
@@ -77,7 +77,6 @@ export default function PreviewCreatedChallenge() {
...createChallengeStore.data,
_count: {
vote: 420,
- submission: 0,
comment: 0,
},
updatedAt: new Date(),
diff --git a/src/app/explore/page.tsx b/src/app/explore/page.tsx
index 550f9847..42e3cd63 100644
--- a/src/app/explore/page.tsx
+++ b/src/app/explore/page.tsx
@@ -1,6 +1,4 @@
-import { Explore } from '~/components/explore';
-
+// CI fails without this
export const dynamic = 'force-dynamic';
-export default function Page() {
- return <Explore />;
-}
+
+export { Explore as default } from '~/components/explore';
diff --git a/src/components/explore/explore-card-skeleton.tsx b/src/components/explore/explore-card-skeleton.tsx
index c1e609f3..dcca2960 100644
--- a/src/components/explore/explore-card-skeleton.tsx
+++ b/src/components/explore/explore-card-skeleton.tsx
@@ -1,21 +1,39 @@
-import { Card, CardDescription, CardHeader, CardTitle } from '../ui/card';
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card';
+import { Skeleton } from '../ui/skeleton';
export function ExploreCardSkeleton() {
return (
- <Card className="group duration-300 hover:bg-card-hovered group-focus:bg-card-hovered">
- <CardHeader className="grid items-start gap-4 space-y-0">
- <div className="space-y-1">
- <CardTitle className="h-5 w-1/2 rounded-lg bg-slate-300 dark:bg-slate-700">
- {''}
+ <Card className="group duration-300">
+ <CardHeader className="relative grid items-start gap-4">
+ <div className="flex flex-col items-start gap-2">
+ <Skeleton className="h-6 w-16 rounded-full bg-zinc-300 dark:bg-zinc-700"></Skeleton>
+ <CardTitle className="h-10 w-full animate-pulse rounded-lg bg-zinc-300 pb-4 text-3xl text-white dark:bg-zinc-700">
+ {' '}
</CardTitle>
- <CardDescription className="relative flex h-48 flex-col space-y-4 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: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))]" />
- <div className="h-3 rounded-lg bg-slate-300 dark:bg-slate-700"></div>
- <div className="h-3 rounded-lg bg-slate-300 dark:bg-slate-700"></div>
- <div className="h-3 w-3/4 rounded-lg bg-slate-300 dark:bg-slate-700"></div>
- </CardDescription>
</div>
</CardHeader>
+ <CardContent className="relative rounded-xl p-6 duration-300 group-hover:bg-card-hovered">
+ <CardDescription className="relative h-14 max-w-[75%] 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: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))]" />
+ <Skeleton className="h-6 w-full rounded-full bg-zinc-300 dark:bg-zinc-700"></Skeleton>
+ </CardDescription>
+
+ <div className="text-muted-foreground">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-6 text-center">
+ <div className="flex items-center gap-2">
+ <Skeleton className="h-6 w-16 rounded-full bg-zinc-300 dark:bg-zinc-700"></Skeleton>
+ </div>
+ <div className="flex items-center gap-2">
+ <Skeleton className="h-6 w-16 rounded-full bg-zinc-300 dark:bg-zinc-700"></Skeleton>
+ </div>
+ </div>
+ <div className="flex items-center gap-2 text-sm">
+ <Skeleton className="h-6 w-16 rounded-full bg-zinc-300 dark:bg-zinc-700"></Skeleton>
+ </div>
+ </div>
+ </div>
+ </CardContent>
</Card>
);
}
diff --git a/src/components/explore/explore-card.tsx b/src/components/explore/explore-card.tsx
index 3eb6fe69..3b7277d2 100644
--- a/src/components/explore/explore-card.tsx
+++ b/src/components/explore/explore-card.tsx
@@ -1,21 +1,22 @@
'use client';
import {
- ThumbsUp,
- PlayCircle,
- Bookmark,
+ Calendar,
Circle,
Diamond,
- Triangle,
+ MessageCircle,
+ PlayCircle,
Plus,
Sparkle,
+ ThumbsUp,
+ Triangle,
} from 'lucide-react';
+import { getRelativeTime } from '~/utils/relativeTime';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card';
-import { DifficultyBadge } from './difficulty-badge';
import { Markdown } from '../ui/markdown';
-import { getRelativeTime } from '~/utils/relativeTime';
import { type ExploreChallengeData } from './';
+import { DifficultyBadge } from './difficulty-badge';
interface ExploreCardProps {
challenge: Pick<
@@ -126,26 +127,22 @@ const ExploreCard = ({ challenge }: ExploreCardProps) => {
<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: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))]" />
<Markdown>{challenge?.shortDescription}</Markdown>
</CardDescription>
- <div className="flex items-end justify-between gap-8 pt-2 text-sm text-muted-foreground">
- <div className="flex flex-col items-center">
- <h1 className="text-4xl font-bold text-black dark:text-white">
- {challenge._count.comment}
- </h1>
- <span>Comments</span>
- </div>
- <div className="mr-auto flex flex-col items-center">
- <h1 className="text-4xl font-bold text-black dark:text-white">
- {challenge._count.submission}
- </h1>
- <span>Solutions</span>
- </div>
- <div className="flex flex-col items-end gap-4">
- <div className="flex items-center justify-center gap-2 text-center">
- <Bookmark size={20} className="mr-2" />
- <ThumbsUp size={20} />
- <span>{challenge._count.vote}</span>
+
+ <div className="text-muted-foreground">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-6 text-center">
+ <div className="flex items-center gap-2">
+ <MessageCircle size={18} />
+ {challenge._count.comment}
+ </div>
+ <div className="flex items-center gap-2">
+ <ThumbsUp size={18} />
+ <span>{challenge._count.vote}</span>
+ </div>
+ </div>
+ <div className="flex items-center gap-2 text-sm">
+ <Calendar size={18} /> {getRelativeTime(challenge.updatedAt)}
</div>
- {getRelativeTime(challenge.updatedAt)}
</div>
</div>
</CardContent>
diff --git a/src/components/explore/index.tsx b/src/components/explore/index.tsx
index 44f09072..277fcea7 100644
--- a/src/components/explore/index.tsx
+++ b/src/components/explore/index.tsx
@@ -3,34 +3,75 @@ import { prisma } from '~/server/db';
import { ExploreSection } from './section';
import { ExploreSectionSkeleton } from './section-skeleton';
-export async function Explore() {
- const data = await getExploreChallengeData();
+// CI fails without this
+export const dynamic = 'force-dynamic';
+export async function Explore() {
return (
<div className="container flex h-full flex-col">
- <section className="mb-8 flex max-w-[69ch] flex-col items-start gap-2">
- <h1 className="my-4 bg-gradient-to-r from-[#3178C6] from-30% to-black bg-clip-text text-4xl font-bold tracking-tight text-transparent dark:to-white md:text-6xl lg:my-6">
- <span className="mb-2 block text-2xl md:text-4xl">Welcome to</span> Type Hero Explore
- </h1>
- </section>
+ <p className="max-w-[66ch] bg-transparent pt-5 text-justify text-lg leading-10 text-neutral-600 dark:text-neutral-400">
+ <span className="text-xl font-bold text-[#3178c6]">Explore</span> the challenges. Embrace
+ the opportunity to grow, learn, and showcase your programming abilities. We hope you find
+ the <span className="font-semibold text-neutral-200">perfect</span> challenge!
+ </p>
+
+ <Suspense fallback={<ExploreSectionSkeleton />}>
+ <ExploreSection title="Great for Beginners" fetcher={getEasyChallenges} />
+ </Suspense>
+
+ <Suspense fallback={<ExploreSectionSkeleton />}>
+ <ExploreSection title="Great for Enthusiasts" fetcher={getMediumChallenges} />
+ </Suspense>
<Suspense fallback={<ExploreSectionSkeleton />}>
- <ExploreSection data={data} />
+ <ExploreSection title="For the Experts" fetcher={getHardChallenges} />
</Suspense>
</div>
);
}
-export type ExploreChallengeData = Awaited<ReturnType<typeof getExploreChallengeData>>;
-async function getExploreChallengeData() {
+export type ExploreChallengeData = Awaited<ReturnType<typeof getEasyChallenges>>;
+async function getEasyChallenges() {
+ return prisma.challenge.findMany({
+ where: {
+ visibility: 'VISIBLE',
+ difficulty: { in: ['EASY'] },
+ },
+ include: {
+ _count: {
+ select: { vote: true, comment: true },
+ },
+ },
+ take: 6,
+ });
+}
+
+async function getMediumChallenges() {
+ return prisma.challenge.findMany({
+ where: {
+ visibility: 'VISIBLE',
+ difficulty: { in: ['MEDIUM'] },
+ },
+ include: {
+ _count: {
+ select: { vote: true, comment: true },
+ },
+ },
+ take: 6,
+ });
+}
+
+async function getHardChallenges() {
return prisma.challenge.findMany({
where: {
visibility: 'VISIBLE',
+ difficulty: { in: ['HARD'] },
},
include: {
_count: {
- select: { vote: true, comment: true, submission: true },
+ select: { vote: true, comment: true },
},
},
+ take: 6,
});
}
diff --git a/src/components/explore/section-skeleton.tsx b/src/components/explore/section-skeleton.tsx
index 676bdf85..a4b36992 100644
--- a/src/components/explore/section-skeleton.tsx
+++ b/src/components/explore/section-skeleton.tsx
@@ -1,9 +1,13 @@
+import { Skeleton } from '../ui/skeleton';
import { ExploreCardSkeleton } from './explore-card-skeleton';
export function ExploreSectionSkeleton() {
return (
- <div className="animate-pulse">
- <div className="grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
+ <div className="p-5">
+ <div className="flex items-center ">
+ <Skeleton className="my-4 h-10 w-1/3 rounded-lg bg-zinc-300 dark:bg-zinc-700" />
+ </div>
+ <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
<ExploreCardSkeleton />
<ExploreCardSkeleton />
<ExploreCardSkeleton />
diff --git a/src/components/explore/section.tsx b/src/components/explore/section.tsx
index 7a6d14e1..da713612 100644
--- a/src/components/explore/section.tsx
+++ b/src/components/explore/section.tsx
@@ -1,11 +1,14 @@
-import type { ExploreChallengeData } from '.';
-import type { Difficulty } from '@prisma/client';
import Link from 'next/link';
+
import Card from './explore-card';
-// import Card2 from '~/components/card';
+
+import type { ExploreChallengeData } from '.';
+import type { Difficulty } from '@prisma/client';
+import { Button } from '../ui/button';
interface Props {
- data: ExploreChallengeData;
+ title: string;
+ fetcher: () => Promise<ExploreChallengeData>;
}
const difficultyToNumber: Record<Difficulty, number> = {
@@ -16,32 +19,35 @@ const difficultyToNumber: Record<Difficulty, number> = {
EXTREME: 4,
};
-export function ExploreSection({ data }: Props) {
- const challenges = data;
+export async function ExploreSection({ title, fetcher }: Props) {
+ const challenges = await fetcher();
return (
- <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
- {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 focus:outline-none"
- href={`/challenge/${challenge.id}`}
- key={challenge.id}
- >
- <Card key={`challenge-${challenge.id}`} challenge={challenge} />
- </Link>
- ))}
- {/* <Card2
- key={`challenge-${challenge.id}`}
- title={challenge.name}
- variant={challenge.difficulty}
- content="what"
- challenge={challenge}
- /> */}
- </div>
+ <section className="py-5">
+ <div className="flex items-center justify-between">
+ <h2 className="my-4 text-3xl font-semibold tracking-tight text-black text-transparent dark:text-white md:text-4xl lg:my-6">
+ {title}
+ </h2>
+ <Button variant="ghost" className="rounded-md p-2">
+ view more
+ </Button>
+ </div>
+ <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
+ {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 focus:outline-none"
+ href={`/challenge/${challenge.id}`}
+ key={challenge.id}
+ >
+ <Card key={`challenge-${challenge.id}`} challenge={challenge} />
+ </Link>
+ ))}
+ </div>
+ </section>
);
}
diff --git a/src/components/home/index.tsx b/src/components/home/index.tsx
deleted file mode 100644
index ca275694..00000000
--- a/src/components/home/index.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-interface Props {}
-
-export default function Home(_props: Props) {
- return <div>Home</div>;
-}