Skip to content

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

[WIP] tabs (#93)

PickleNikef6dbb6ea3c9
diff --git a/src/components/challenge/description-panel-skeleton.tsx b/src/components/challenge/description-panel-skeleton.tsx
index 4725547e..ae06364b 100644
--- a/src/components/challenge/description-panel-skeleton.tsx
+++ b/src/components/challenge/description-panel-skeleton.tsx
@@ -4,15 +4,21 @@ export function DescriptionPanelSkeleton() {
return (
<>
<Tabs defaultValue="description" className="w-full">
- <TabsList className="grid w-full grid-cols-2">
- <TabsTrigger value="description" className="hover:bg-zinc-200 dark:hover:bg-zinc-700">
+ <TabsList className="sticky top-0 grid h-auto w-full grid-cols-2 rounded-none border-b border-zinc-300 bg-background dark:border-zinc-700 dark:bg-muted">
+ <TabsTrigger
+ value="description"
+ className="rounded-md rounded-tl-lg duration-300 data-[state=active]:bg-neutral-200 dark:data-[state=active]:bg-neutral-700"
+ >
Description
</TabsTrigger>
- <TabsTrigger value="solutions" className="hover:bg-zinc-200 dark:hover:bg-zinc-700">
+ <TabsTrigger
+ value="solutions"
+ className="rounded-md rounded-tr-lg duration-300 data-[state=active]:bg-neutral-200 dark:data-[state=active]:bg-neutral-700"
+ >
Solutions
</TabsTrigger>
</TabsList>
- <TabsContent value="description" className="mt-0">
+ <TabsContent value="description" className="mt-0 dark:bg-muted">
<div className="h-full p-5">
<div className="mb-2 h-8 w-1/2 rounded-lg bg-zinc-300 dark:bg-zinc-700"> </div>
<div className="mb-6 flex items-center gap-6 py-4">
diff --git a/src/components/challenge/description-panel.tsx b/src/components/challenge/description-panel.tsx
index 64ffed45..60a01e30 100644
--- a/src/components/challenge/description-panel.tsx
+++ b/src/components/challenge/description-panel.tsx
@@ -6,6 +6,7 @@ import { Bookmark as BookmarkIcon, Share, ThumbsUp } from 'lucide-react';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { useRef, useState } from 'react';
+
import { Button } from '~/components/ui/button';
import {
Dialog,
@@ -123,16 +124,22 @@ export function DescriptionPanel({ challenge }: Props) {
return (
<>
<Tabs defaultValue="description" className="w-full">
- <TabsList className="sticky top-0 grid w-full grid-cols-2 rounded-xl bg-neutral-200 bg-opacity-70 backdrop-blur-md dark:bg-muted">
- <TabsTrigger className="rounded-lg" value="description">
+ <TabsList className="sticky top-0 z-10 grid h-auto w-full grid-cols-2 rounded-none border-b border-zinc-300 bg-background/90 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">
+ <TabsTrigger
+ value="description"
+ className="rounded-md rounded-tl-lg duration-300 data-[state=active]:bg-neutral-200 dark:data-[state=active]:bg-neutral-700"
+ >
Description
</TabsTrigger>
- <TabsTrigger className="rounded-lg" value="solutions">
+ <TabsTrigger
+ value="solutions"
+ className="rounded-md rounded-tr-lg duration-300 data-[state=active]:bg-neutral-200 dark:data-[state=active]:bg-neutral-700"
+ >
Solutions
</TabsTrigger>
</TabsList>
- <TabsContent value="description" className="mt-0">
- <div className="h-full px-1 pb-0 pt-3 dark:px-4 dark:pb-2">
+ <TabsContent value="description" className="mt-0 dark:bg-muted">
+ <div className="h-full px-4 py-3">
<div className="flex items-baseline justify-between">
<TypographyH3 className="mb-2 font-medium">{challenge.name}</TypographyH3>
<div>
@@ -361,7 +368,7 @@ export function DescriptionPanel({ challenge }: Props) {
</div>
</div>
</TabsContent>
- <TabsContent className="mt-0" value="solutions">
+ <TabsContent value="solutions" className="mt-0 dark:bg-muted">
<Solutions challenge={challenge} />
</TabsContent>
</Tabs>
diff --git a/src/components/challenge/innerIndex.tsx b/src/components/challenge/innerIndex.tsx
index 68b13ab4..75b6fd8a 100644
--- a/src/components/challenge/innerIndex.tsx
+++ b/src/components/challenge/innerIndex.tsx
@@ -116,7 +116,7 @@ export function InnerIndex({ challenge }: Props) {
>
<div
ref={leftSide}
- className="min-h-[42px] w-full overflow-y-auto rounded-xl bg-white dark:bg-zinc-800 lg:min-w-[500px]"
+ className="min-h-[42px] w-full overflow-y-auto rounded-xl border border-zinc-300 bg-white dark:border-zinc-700 dark:bg-zinc-800 lg:min-w-[500px]"
>
<DescriptionPanel challenge={challenge} />
</div>
diff --git a/src/components/challenge/skeleton.tsx b/src/components/challenge/skeleton.tsx
index e01efed3..54d31420 100644
--- a/src/components/challenge/skeleton.tsx
+++ b/src/components/challenge/skeleton.tsx
@@ -25,7 +25,7 @@ export function ChallengeSkeleton() {
>
<div
ref={leftSide}
- className="w-full min-w-full animate-pulse overflow-y-auto rounded-xl bg-white dark:bg-zinc-800 lg:min-w-[500px]"
+ className="w-full min-w-full animate-pulse overflow-y-auto rounded-xl border border-zinc-300 bg-white dark:border-zinc-700 dark:bg-zinc-800 lg:min-w-[500px]"
>
<DescriptionPanelSkeleton />
</div>
diff --git a/src/components/challenge/solutions.tsx b/src/components/challenge/solutions.tsx
index 87f91757..79599d13 100644
--- a/src/components/challenge/solutions.tsx
+++ b/src/components/challenge/solutions.tsx
@@ -2,7 +2,6 @@
import { ArrowUp, MessageCircle, Plus } from 'lucide-react';
import { Button } from '~/components/ui/button';
-import { TypographyH3 } from '../ui/typography/h3';
import type { Challenge } from '.';
interface Props {
@@ -16,27 +15,35 @@ export function Solutions({ challenge }: Props) {
};
return (
- <div className="relative flex flex-col gap-4">
- <div className="sticky right-0 top-0 flex h-full items-center justify-between px-2 py-1">
+ <>
+ <div className="sticky right-0 top-[41px] z-10 flex h-full items-center justify-between border-b border-zinc-300 bg-background/90 bg-opacity-20 p-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">
<div className="flex gap-2">
- <div className="flex gap-2 rounded-full bg-blue-600/10 px-4 py-1 text-blue-600 dark:bg-blue-400/10 dark:text-blue-400">
+ <div className="flex gap-2 rounded-xl bg-blue-600/10 px-4 py-1 text-blue-600 dark:bg-blue-400/10 dark:text-blue-400">
All
</div>
- <div className="flex gap-2 rounded-full bg-black/5 px-4 py-1 text-neutral-500 dark:bg-white/5 dark:text-neutral-400">
+ <div className="flex gap-2 rounded-xl bg-black/5 px-4 py-1 text-neutral-500 dark:bg-white/5 dark:text-neutral-400">
Tag 2
</div>
</div>
<Button
- className="bg-emerald-600 hover:bg-emerald-500 dark:bg-emerald-400 dark:hover:bg-emerald-300"
+ className="h-8 rounded-xl bg-emerald-600 hover:bg-emerald-500 dark:bg-emerald-400 dark:hover:bg-emerald-300"
onClick={() => handleClick()}
disabled={!hasSolution}
>
<Plus className="mr-2 h-4 w-4" /> Solution
</Button>
</div>
- <SolutionRow />
- <SolutionRow2 />
- </div>
+ <div className="relative flex flex-col">
+ <SolutionRow />
+ <SolutionRow />
+ <SolutionRow />
+ <SolutionRow />
+ <SolutionRow />
+ <SolutionRow />
+ <SolutionRow />
+ <SolutionRow />
+ </div>
+ </>
);
}
@@ -44,16 +51,16 @@ export function Solutions({ challenge }: Props) {
function SolutionRow() {
const date = new Date();
return (
- <div className="flex cursor-pointer flex-col gap-2 rounded-3xl p-4 duration-300 hover:bg-neutral-200 dark:rounded-none dark:hover:bg-neutral-700">
- <TypographyH3>🔥🔥Some | LeetCodeLooking✅ | Title🔥🔥</TypographyH3>
- <div className="flex gap-2 text-neutral-600 dark:text-neutral-400">
- <div>
- <b>username</b> goes here
+ <div className="flex cursor-pointer flex-col gap-2 p-4 duration-300 hover:bg-neutral-100 dark:rounded-none dark:hover:bg-neutral-700">
+ <h3 className="font-bold">🔥🔥Some | LeetCodeLooking✅ | Title🔥🔥</h3>
+ <div className="mb-2 flex items-center gap-2 text-neutral-600 dark:text-neutral-400">
+ <div className="rounded-lg bg-neutral-200 pl-1 pr-2 font-bold dark:bg-neutral-700 dark:text-neutral-300">
+ @&nbsp;username goes here
</div>
<div>{date.toLocaleString()}</div>
</div>
<div className="flex gap-5 text-neutral-600 duration-300 dark:text-neutral-400">
- <button className="flex items-center gap-2 rounded-full bg-emerald-600/10 p-2 pr-3 text-emerald-600 duration-300 hover:bg-emerald-400/20 dark:bg-emerald-400/5 dark:text-emerald-400">
+ <button className="flex items-center gap-2 rounded-full bg-emerald-600/10 p-2 pr-3 text-emerald-600 duration-300 hover:bg-emerald-400/20 dark:bg-emerald-400/20 dark:text-emerald-400">
<ArrowUp className="stroke-1" /> 70
</button>
<button className="flex items-center gap-2 rounded-full bg-white/5 p-2 pr-3 duration-300 hover:bg-black/20 only:dark:hover:bg-white/20">
@@ -63,27 +70,3 @@ function SolutionRow() {
</div>
);
}
-
-// TODO: nuke this
-function SolutionRow2() {
- const date = new Date();
- return (
- <div className="flex cursor-pointer flex-col gap-2 rounded-3xl p-4 duration-300 hover:bg-neutral-200 dark:rounded-none dark:hover:bg-neutral-700">
- <TypographyH3>C++ VS Rust</TypographyH3>
- <div className="flex gap-2 text-neutral-600 dark:text-neutral-400">
- <div>
- <b>username</b> goes here
- </div>
- <div>{date.toLocaleString()}</div>
- </div>
- <div className="flex gap-5 text-neutral-600 duration-300 dark:text-neutral-400">
- <button className="flex items-center gap-2 rounded-full bg-white/5 p-2 pr-3 duration-300 hover:bg-black/20 only:dark:hover:bg-white/20">
- <ArrowUp className="stroke-1" /> 69
- </button>
- <button className="flex items-center gap-2 rounded-full bg-white/5 p-2 pr-3 duration-300 hover:bg-black/20 only:dark:hover:bg-white/20">
- <MessageCircle className="stroke-1" /> 69
- </button>
- </div>
- </div>
- );
-}
diff --git a/src/components/dashboard/DashboardPage.tsx b/src/components/dashboard/DashboardPage.tsx
index 774c8668..191ad03a 100644
--- a/src/components/dashboard/DashboardPage.tsx
+++ b/src/components/dashboard/DashboardPage.tsx
@@ -17,7 +17,13 @@ export default function DashboardPage() {
<div className="flex-1 space-y-4 pt-6">
<div className="flex items-center gap-4">
<div className="flex items-center space-x-2">
- <Image alt="user avatar" width="100" height="100" src="/avatar.jpeg" />
+ <Image
+ className="rounded-3xl"
+ alt="user avatar"
+ width="100"
+ height="100"
+ src="/avatar.jpeg"
+ />
</div>
<div>
<p className="text-3xl font-bold tracking-tight">Username</p>
@@ -26,14 +32,37 @@ export default function DashboardPage() {
</div>
</div>
<Tabs defaultValue="overview" className="space-y-4">
- <TabsList>
- <TabsTrigger value="overview">Overview</TabsTrigger>
- <TabsTrigger value="in-progress">In-Progress</TabsTrigger>
- <TabsTrigger value="solutions">Solutions</TabsTrigger>
- <TabsTrigger value="bookmarks" disabled>
+ <TabsList className="rounded-full border border-border bg-background">
+ <TabsTrigger
+ className="rounded-l-2xl rounded-r-lg duration-300 data-[state=active]:bg-border"
+ value="overview"
+ >
+ Overview
+ </TabsTrigger>
+ <TabsTrigger
+ className="rounded-lg duration-300 data-[state=active]:bg-border"
+ value="in-progress"
+ >
+ In-Progress
+ </TabsTrigger>
+ <TabsTrigger
+ className="rounded-lg duration-300 data-[state=active]:bg-border"
+ value="solutions"
+ >
+ Solutions
+ </TabsTrigger>
+ <TabsTrigger
+ className="rounded-lg duration-300 data-[state=active]:bg-border"
+ value="bookmarks"
+ disabled
+ >
Bookmarks
</TabsTrigger>
- <TabsTrigger value="comments" disabled>
+ <TabsTrigger
+ className="rounded-l-lg rounded-r-full duration-300 data-[state=active]:bg-border"
+ value="comments"
+ disabled
+ >
Comments
</TabsTrigger>
</TabsList>
diff --git a/src/components/explore/explore-card.tsx b/src/components/explore/explore-card.tsx
index 62e3270a..d2be9000 100644
--- a/src/components/explore/explore-card.tsx
+++ b/src/components/explore/explore-card.tsx
@@ -1,15 +1,12 @@
'use client';
-import { ArrowBigUp, ThumbsUp } from 'lucide-react';
+import { ThumbsUp } from 'lucide-react';
import { type Challenge } from '.';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card';
import { DifficultyBadge } from './difficulty-badge';
-import ReactMarkdown from 'react-markdown';
-import SyntaxHighlighter from 'react-syntax-highlighter';
-import remarkGfm from 'remark-gfm';
-import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
-import clsx from 'clsx';
+import { Markdown } from '../ui/markdown';
+import getRelativeTime from '~/utils/relativeTime';
interface Props {
challenge: Awaited<Challenge>[0];
@@ -37,32 +34,6 @@ const SHADOWS_BY_DIFFICULTY = {
'hover:shadow-[0_0_1rem_-0.5rem_#fdba74,inset_0_0_1rem_-0.5rem_#fdba74] group-focus:shadow-[0_0_1rem_-0.5rem_#fdba74,inset_0_0_1rem_-0.5rem_#fdba74]',
};
-// in miliseconds
-const units = {
- year: 24 * 60 * 60 * 1000 * 365,
- month: (24 * 60 * 60 * 1000 * 365) / 12,
- day: 24 * 60 * 60 * 1000,
- hour: 60 * 60 * 1000,
- minute: 60 * 1000,
- second: 1000,
-};
-
-const rtf = new Intl.RelativeTimeFormat('en', {
- numeric: 'auto',
- // TODO: style: 'short' on 640px - 720px
-});
-
-// get relevant time from a date object
-const getRelativeTime = (date: Date) => {
- const elapsed = date.getTime() - Date.now();
-
- for (const [unit, ms] of Object.entries(units)) {
- if (Math.abs(elapsed) > ms || unit === 'second') {
- return rtf.format(Math.round(elapsed / ms), unit as Intl.RelativeTimeFormatUnit);
- }
- }
-};
-
export function ExploreCard({ challenge }: Props) {
return (
<Card
@@ -75,34 +46,7 @@ export function ExploreCard({ challenge }: Props) {
<CardTitle className="pb-4">{challenge.name}</CardTitle>
<CardDescription className="relative h-48 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))]" />
- {/* // TODO: we use this in two places and we should just make this shared */}
- <ReactMarkdown
- remarkPlugins={[remarkGfm]}
- components={{
- p: ({ ...props }) => <p className="mb-4" {...props} />,
- code({ inline, className, children, ...props }) {
- const match = /language-(\w+)/.exec(className || '');
- return !inline && match ? (
- <SyntaxHighlighter
- // @ts-ignore
- style={vscDarkPlus} // theme
- className="rounded-xl dark:rounded-md"
- language={match[1]}
- PreTag="section" // parent tag
- {...props}
- >
- {String(children).replace(/\n$/, '')}
- </SyntaxHighlighter>
- ) : (
- <code className="rounded-md bg-neutral-200 p-1 font-mono dark:bg-black">
- {children}
- </code>
- );
- },
- }}
- >
- {challenge?.shortDescription}
- </ReactMarkdown>
+ <Markdown>{challenge?.shortDescription}</Markdown>
</CardDescription>
</div>
</CardHeader>
@@ -117,7 +61,7 @@ export function ExploreCard({ challenge }: Props) {
<span>{challenge._count.Vote}</span>
</div>
</div>
- <div>Updated {getRelativeTime(challenge.updatedAt)}</div>
+ <div>{getRelativeTime(challenge.updatedAt)}</div>
</div>
</CardContent>
</Card>
diff --git a/src/components/ui/markdown.tsx b/src/components/ui/markdown.tsx
new file mode 100644
index 00000000..b16f5706
--- /dev/null
+++ b/src/components/ui/markdown.tsx
@@ -0,0 +1,38 @@
+'use client';
+
+import ReactMarkdown from 'react-markdown';
+import SyntaxHighlighter from 'react-syntax-highlighter';
+import remarkGfm from 'remark-gfm';
+import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
+
+export function Markdown({ children }: { children: string }) {
+ return (
+ <ReactMarkdown
+ remarkPlugins={[remarkGfm]}
+ components={{
+ p: ({ ...props }) => <p className="mb-4" {...props} />,
+ code({ inline, className, children, ...props }) {
+ const match = /language-(\w+)/.exec(className || '');
+ return !inline && match ? (
+ <SyntaxHighlighter
+ // @ts-ignore
+ style={vscDarkPlus} // theme
+ className="rounded-xl dark:rounded-md"
+ language={match[1]}
+ PreTag="section" // parent tag
+ {...props}
+ >
+ {String(children).replace(/\n$/, '')}
+ </SyntaxHighlighter>
+ ) : (
+ <code className="rounded-md bg-neutral-200 p-1 font-mono dark:bg-black">
+ {children}
+ </code>
+ );
+ },
+ }}
+ >
+ {children}
+ </ReactMarkdown>
+ );
+}
diff --git a/src/components/ui/navigation.tsx b/src/components/ui/navigation.tsx
index 776fe074..1b538afd 100644
--- a/src/components/ui/navigation.tsx
+++ b/src/components/ui/navigation.tsx
@@ -59,7 +59,7 @@ export function Navigation() {
<header className="w-full">
<nav
className={`flex h-14 items-center ${
- pathname.includes('/challenge') ? 'px-8' : 'container'
+ pathname.includes('/challenge') ? 'px-4' : 'container'
}`}
>
<div className="flex w-full items-center justify-between">
diff --git a/src/utils/relativeTime.ts b/src/utils/relativeTime.ts
new file mode 100644
index 00000000..1606fd22
--- /dev/null
+++ b/src/utils/relativeTime.ts
@@ -0,0 +1,26 @@
+// in miliseconds
+const units = {
+ year: 24 * 60 * 60 * 1000 * 365,
+ month: (24 * 60 * 60 * 1000 * 365) / 12,
+ day: 24 * 60 * 60 * 1000,
+ hour: 60 * 60 * 1000,
+ minute: 60 * 1000,
+ second: 1000,
+};
+
+const rtf = new Intl.RelativeTimeFormat('en', {
+ numeric: 'auto',
+ style: 'short',
+});
+
+const getRelativeTime = (date: Date) => {
+ const elapsed = date.getTime() - Date.now();
+
+ for (const [unit, ms] of Object.entries(units)) {
+ if (Math.abs(elapsed) > ms || unit === 'second') {
+ return rtf.format(Math.round(elapsed / ms), unit as Intl.RelativeTimeFormatUnit);
+ }
+ }
+};
+
+export default getRelativeTime;