Skip to content

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

feat: Adds in new card design for explore page (#151)

Jim Burbridge02e41ed07dd8
diff --git a/package.json b/package.json
index 2046dc49..3be682ea 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"postinstall": "prisma generate && pnpm dl-monaco",
"lint": "next lint",
"reset": "prisma db push --force-reset",
- "format": "prettier -w 'src/**/*.{ts,tsx,css,cjs,mjs,json}'",
+ "format": "prettier -w src/**/*.{ts,tsx,css,cjs,mjs,json}",
"start": "next start",
"refresh": "pnpm reset && pnpm prisma db seed",
"typecheck": "tsc --noEmit",
@@ -73,6 +73,7 @@
"zustand": "^4.3.8"
},
"devDependencies": {
+ "@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/typography": "^0.5.9",
"@types/eslint": "^8.37.0",
"@types/node": "^18.16.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 727f5516..6a51cadd 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1,9 +1,5 @@
lockfileVersion: '6.0'
-settings:
- autoInstallPeers: true
- excludeLinksFromLockfile: false
-
patchedDependencies:
'@monaco-editor/[email protected]':
hash: xep4qb27qzc6gvlhv2fxe3r2ka
@@ -177,6 +173,9 @@ dependencies:
version: 4.3.8([email protected])
devDependencies:
+ '@tailwindcss/container-queries':
+ specifier: ^0.1.1
+ version: 0.1.1([email protected])
'@tailwindcss/typography':
specifier: ^0.5.9
version: 0.5.9([email protected])
@@ -1956,6 +1955,14 @@ packages:
zod: 3.21.4
dev: false
+ resolution: {integrity: sha512-p18dswChx6WnTSaJCSGx6lTmrGzNNvm2FtXmiO6AuA1V4U5REyoqwmT6kgAsIMdjo07QdAfYXHJ4hnMtfHzWgA==}
+ peerDependencies:
+ tailwindcss: '>=3.2.0'
+ dependencies:
+ tailwindcss: 3.3.0([email protected])
+ dev: true
+
resolution: {integrity: sha512-t8Sg3DyynFysV9f4JDOVISGsjazNb48AeIYQwcL+Bsq5uf4RYL75C1giZ43KISjeDGBaTN3Kxh7Xj/vRSMJUUg==}
peerDependencies:
@@ -6760,3 +6767,7 @@ packages:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
dev: false
+
+settings:
+ autoInstallPeers: true
+ excludeLinksFromLockfile: false
diff --git a/src/app/create/page.tsx b/src/app/create/page.tsx
index ab21c5d3..a674dbb8 100644
--- a/src/app/create/page.tsx
+++ b/src/app/create/page.tsx
@@ -225,6 +225,7 @@ export default function CreateChallenge() {
// removes resize handle on bottom right
visibleDragbar={false}
// @ts-ignore
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
onChange={(ev) => setDescription(ev)}
// TODO: customize toolbar GH #131
// components={{
diff --git a/src/app/create/preview/page.tsx b/src/app/create/preview/page.tsx
index b7aaa8e0..47a487ff 100644
--- a/src/app/create/preview/page.tsx
+++ b/src/app/create/preview/page.tsx
@@ -63,7 +63,11 @@ export default function PreviewCreatedChallenge() {
<ExploreCard
challenge={{
...createChallengeStore.data,
- _count: { vote: 420 },
+ _count: {
+ vote: 420,
+ solution: 0,
+ comment: 0,
+ },
updatedAt: new Date(),
difficulty: 'BEGINNER',
}}
diff --git a/src/components/card/index.tsx b/src/components/card/index.tsx
new file mode 100644
index 00000000..2ae2448f
--- /dev/null
+++ b/src/components/card/index.tsx
@@ -0,0 +1,113 @@
+'use client';
+import { cva, type VariantProps } from 'class-variance-authority';
+import { MessageCircle, Play } from 'lucide-react';
+import * as React from 'react';
+import { cn } from '~/utils/cn';
+import { TypographyP } from '../ui/paragraph';
+import { TypographyH3 } from '../ui/typography/h3';
+import type { Challenge } from '@prisma/client';
+import { useRouter } from 'next/navigation';
+import { getRelativeTime } from '~/utils/relativeTime';
+
+const cardVariants = cva('card border-2 rounded-xl @container/card dark:bg-gray-900', {
+ variants: {
+ variant: {
+ BEGINNER: 'border-pink-300 hover:shadow-lg dark:hover:shadow-pink-400/30',
+ EASY: 'border-green-500 hover:shadow-lg dark:hover:shadow-green-500/40',
+ MEDIUM: 'border-yellow-400 hover:shadow-lg dark:hover:shadow-yellow-300/50',
+ HARD: 'border-red-600 hover:shadow-lg dark:hover:shadow-red-500/40',
+ EXTREME: 'border-orange-400 hover:shadow-lg dark:hover:shadow-orange-300/50',
+ },
+ },
+ defaultVariants: {
+ variant: 'BEGINNER',
+ },
+});
+
+const headerVariants = cva('relative rounded-t-xl bg-gradient-to-b p-6 pb-12', {
+ variants: {
+ variant: {
+ BEGINNER: 'dark:bg-pink-400 dark:text-gray-800 dark:from-pink-700/40 dark:to-pink-300/50',
+ EASY: 'dark:bg-green-500 dark:from-green-800/60 dark:to-green-600',
+ MEDIUM: 'dark:bg-yellow-400 dark:text-gray-800 dark:from-yellow-700/60 dark:to-yellow-400',
+ EXTREME: 'dark:bg-orange-400 dark:from-orange-700/60 dark:to-orange-400',
+ HARD: 'dark:bg-red-600 dark:from-red-800/50 dark:to-red-500',
+ },
+ },
+ defaultVariants: {
+ variant: 'BEGINNER',
+ },
+});
+
+const actionButton = cva('rounded-full p-4 hover:shadow hover:outline', {
+ variants: {
+ variant: {
+ BEGINNER: 'dark:bg-pink-400 dark:shadow-pink-300',
+ EASY: 'dark:bg-green-600 dark:shadow-green-400 dark:hover:outline-green-800',
+ MEDIUM: 'dark:bg-yellow-400',
+ HARD: 'dark:bg-red-500 dark:shadow-red-300 dark:hover:outline-red-800',
+ EXTREME:
+ 'dark:bg-orange-400 dark:hover:outline-orange-700/70 dark:hover:shadow-orange-800/70',
+ },
+ },
+ defaultVariants: {
+ variant: 'BEGINNER',
+ },
+});
+
+export interface CardProps extends VariantProps<typeof cardVariants> {
+ title: string;
+ content: React.ReactNode;
+ // children: React.ReactNode | React.ReactNode[] | undefined;
+ challenge: Challenge & {
+ _count: {
+ vote: number;
+ comment: number;
+ solution: number;
+ };
+ };
+}
+
+export default function Card({ challenge, variant }: CardProps) {
+ const router = useRouter();
+
+ return (
+ <div className={cn(cardVariants({ variant: variant }), '')}>
+ <header className={headerVariants({ variant: variant })}>
+ <TypographyH3>{challenge.name}</TypographyH3>
+ <p className="capitalize">{challenge.difficulty.toLowerCase()}</p>
+ <p>{getRelativeTime(challenge.updatedAt)}</p>
+ <section className="absolute bottom-0 right-6 translate-y-1/2 ">
+ <button
+ className={actionButton({ variant: variant })}
+ type="button"
+ onClick={(e) => {
+ e.preventDefault();
+ router.push(`/challenge/${challenge.id}`);
+ }}
+ >
+ <Play size={36} />
+ </button>
+ </section>
+ </header>
+ <section className="flex flex-col gap-6 px-6 pb-6 pt-8 shadow-inner">
+ <div className="flex justify-start gap-6">
+ <div className="flex flex-col items-center">
+ <TypographyH3>{challenge._count.solution}</TypographyH3>
+ <TypographyP>Solutions</TypographyP>
+ </div>
+ <div className="flex flex-col items-center">
+ <TypographyH3>
+ <div className="flex items-center gap-4">
+ <MessageCircle size={28} />
+ <TypographyH3>{challenge._count.comment}</TypographyH3>
+ </div>
+ </TypographyH3>
+ <TypographyP>Comments</TypographyP>
+ </div>
+ </div>
+ <p>{challenge.shortDescription}</p>
+ </section>
+ </div>
+ );
+}
diff --git a/src/components/explore/index.tsx b/src/components/explore/index.tsx
index ceb7d411..b4ad774c 100644
--- a/src/components/explore/index.tsx
+++ b/src/components/explore/index.tsx
@@ -10,7 +10,7 @@ export async function Explore() {
<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">
- Explode
+ Explore
</h1>
<p className="leading-loose text-neutral-700 dark:text-neutral-300">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
@@ -37,7 +37,7 @@ async function getExploreChallengeData() {
},
include: {
_count: {
- select: { vote: true },
+ select: { vote: true, comment: true, solution: true },
},
},
});
diff --git a/src/components/explore/section.tsx b/src/components/explore/section.tsx
index 260c595a..ae96d199 100644
--- a/src/components/explore/section.tsx
+++ b/src/components/explore/section.tsx
@@ -1,25 +1,38 @@
-import Link from 'next/link';
import type { ExploreChallengeData } from '.';
-import { ExploreCard } from './explore-card';
+import Card from '~/components/card';
+import type { Difficulty } from '@prisma/client';
interface Props {
data: ExploreChallengeData;
}
+const difficultyToNumber: Record<Difficulty, number> = {
+ BEGINNER: 0,
+ EASY: 1,
+ MEDIUM: 2,
+ HARD: 3,
+ EXTREME: 4,
+};
+
export function ExploreSection({ data }: Props) {
+ const challenges = data;
return (
- <div>
- <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
- {data.map((challenge) => (
- <Link
- className="group focus:outline-none"
- href={`/challenge/${challenge.id}`}
- key={challenge.id}
- >
- <ExploreCard key={challenge.id} challenge={challenge} />
- </Link>
+ <div className="grid gap-4 @container/explore-section 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) => (
+ <Card
+ key={`challenge-${challenge.id}`}
+ title={challenge.name}
+ variant={challenge.difficulty}
+ content="what"
+ challenge={challenge}
+ />
))}
- </div>
</div>
);
}
diff --git a/tailwind.config.ts b/tailwind.config.ts
index 1831a78f..c183f94f 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -78,5 +78,5 @@ module.exports = {
},
},
},
- plugins: [require('tailwindcss-animate'), require('@tailwindcss/typography')],
+ plugins: [require('tailwindcss-animate'), require('@tailwindcss/typography'), require('@tailwindcss/container-queries')],
};