Skip to content

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

feat: fit-and-finish profile page for early access (#882)

Eric Leeb4381952cf1e
diff --git a/apps/web/src/app/[locale]/[username]/_components/dashboard/bookmarks-tab.tsx b/apps/web/src/app/[locale]/[username]/_components/dashboard/bookmarks-tab.tsx
new file mode 100644
index 00000000..244bde3e
--- /dev/null
+++ b/apps/web/src/app/[locale]/[username]/_components/dashboard/bookmarks-tab.tsx
@@ -0,0 +1,68 @@
+import Link from 'next/link';
+
+import { prisma } from '@repo/db';
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from '@repo/ui/components/table';
+
+import { getRelativeTime } from '~/utils/relativeTime';
+import { withUnstableCache } from '~/utils/withUnstableCache';
+
+export async function BookmarksTab({ userId }: { userId: string }) {
+ const bookmarks = await withUnstableCache({
+ fn: getBookmarkedChallenges,
+ args: [userId],
+ keys: ['bookmarked-challenges'],
+ tags: ['challenges'],
+ });
+
+ return (
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Challenge</TableHead>
+ <TableHead>Bookmarked</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {bookmarks.map((bookmark) => (
+ <TableRow key={bookmark.id}>
+ <TableCell className="font-medium underline">
+ {Boolean(bookmark.challenge) && (
+ <Link href={`/challenge/${bookmark.challenge?.slug}`}>
+ {bookmark.challenge?.name}
+ </Link>
+ )}
+ </TableCell>
+ <TableCell>
+ {Boolean(bookmark.createdAt) && getRelativeTime(bookmark.createdAt!)}
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ );
+}
+
+async function getBookmarkedChallenges(userId: string) {
+ return await prisma.bookmark.findMany({
+ where: { userId },
+ include: {
+ challenge: {
+ select: {
+ id: true,
+ slug: true,
+ name: true,
+ },
+ },
+ },
+ orderBy: {
+ createdAt: 'desc',
+ },
+ });
+}
diff --git a/apps/web/src/app/[locale]/[username]/_components/dashboard/in-progress-tab.tsx b/apps/web/src/app/[locale]/[username]/_components/dashboard/in-progress-tab.tsx
index c27c687a..2a61a25f 100644
--- a/apps/web/src/app/[locale]/[username]/_components/dashboard/in-progress-tab.tsx
+++ b/apps/web/src/app/[locale]/[username]/_components/dashboard/in-progress-tab.tsx
@@ -31,7 +31,7 @@ export async function InProgressTab({ userId }: { userId: string }) {
{challenges.map((challenge) => (
<TableRow key={challenge.id}>
<TableCell className="font-medium underline">
- <Link href={`/challenge/${challenge.id}`}>{challenge.name}</Link>
+ <Link href={`/challenge/${challenge.slug}`}>{challenge.name}</Link>
</TableCell>
<TableCell>{getRelativeTime(challenge.submission[0]!.createdAt)}</TableCell>
</TableRow>
@@ -59,6 +59,7 @@ async function getInProgressChallenges(userId: string) {
},
select: {
id: true,
+ slug: true,
name: true,
submission: {
orderBy: {
diff --git a/apps/web/src/app/[locale]/[username]/_components/dashboard/index.tsx b/apps/web/src/app/[locale]/[username]/_components/dashboard/index.tsx
index 803d8342..b436c8c5 100644
--- a/apps/web/src/app/[locale]/[username]/_components/dashboard/index.tsx
+++ b/apps/web/src/app/[locale]/[username]/_components/dashboard/index.tsx
@@ -1,3 +1,5 @@
+import Link from 'next/link';
+
import { getServerAuthSession } from '@repo/auth/server';
import type { User } from '@repo/db/types';
import {
@@ -14,14 +16,15 @@ import {
VerticalTabsList,
VerticalTabsTrigger,
} from '@repo/ui/components/tabs';
-import { Bookmark, ChevronRightSquare, MessagesSquare, Play, Settings } from '@repo/ui/icons';
-import Link from 'next/link';
-import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
+import { Bookmark, ChevronRightSquare, Play, Settings, Text } from '@repo/ui/icons';
+
import { getRelativeTime } from '~/utils/relativeTime';
import { stripProtocolAndWWW } from '~/utils/stringUtils';
+
+import { BookmarksTab } from './bookmarks-tab';
import { InProgressTab } from './in-progress-tab';
-import { Overview } from './overview';
-import { SubmissionsTab } from './submissions-tab';
+import { OverviewTab } from './overview-tab';
+import { SharedSolutionsTab } from './shared-solutions-tab';
import UserHeader from './user-header';
interface Props {
@@ -34,124 +37,138 @@ interface Props {
export async function Dashboard({ user }: Props) {
const session = await getServerAuthSession();
+ const isOwnProfile = session?.user.id === user.id;
+
+ const filteredProfileLinks =
+ user.userLinks.length > 0 ? user.userLinks.filter((item) => item.url !== '') : [];
+
return (
<div className="container">
{/* // TODO: GFI: make each page a subroute, put settings into this same layout */}
- <Tabs className="flex flex-col gap-8 py-8 md:flex-row" defaultValue="in-progress">
+ <Tabs className="flex flex-col gap-8 py-8 md:flex-row" defaultValue="overview">
<VerticalTabsList>
- <div className="mb-2 flex flex-col items-center md:items-start">
+ <div className="flex flex-col items-center gap-10 md:items-start">
<div
- className="mb-10 h-32 w-32 rounded-3xl bg-cover bg-center bg-no-repeat md:h-64 md:w-64"
+ className="h-32 w-32 rounded-3xl bg-cover bg-center bg-no-repeat md:h-64 md:w-64"
style={{ backgroundImage: `url(${user.image ?? '/avatar.jpeg'})` }}
/>
- <UserHeader user={user} isOwnProfile={session?.user.id === user.id} />
- <p
- className="text-sm italic tracking-tight text-neutral-500"
- title={`Joined ${user.createdAt.toString()}`}
- >
- Joined {getRelativeTime(user.createdAt)}
- </p>
- <div className="mb-4 mt-2 w-full text-center text-sm md:w-64 md:text-start">
- <ReactMarkdown>{user.bio}</ReactMarkdown>
+ <div className="flex flex-col items-center gap-2 md:w-full md:items-start">
+ <UserHeader user={user} isOwnProfile={isOwnProfile} />
+ <span
+ className="text-muted-foreground text-sm italic tracking-tight"
+ title={`Joined ${user.createdAt.toString()}`}
+ >
+ Joined {getRelativeTime(user.createdAt)}
+ </span>
</div>
-
- {user.userLinks.length > 0 && (
- <div className="flex flex-col gap-2">
- {user.userLinks
- .filter((item) => item.url !== '')
- .map((link) => (
- <div className="flex items-center gap-2" key={link.id}>
- <MagicIcon url={link.url} />
- <a
- className="text-xs text-neutral-400 hover:text-neutral-600 dark:text-neutral-600 dark:hover:text-neutral-400"
- href={link.url}
- rel="noopener noreferrer"
- target="_blank"
- >
- {stripProtocolAndWWW(link.url)}
- </a>
- </div>
- ))}
+ {Boolean(filteredProfileLinks.length > 0) && (
+ <div className="flex w-full flex-col items-center gap-2 md:items-start">
+ {filteredProfileLinks.map((link) => (
+ <div className="flex items-center gap-2" key={link.id}>
+ <MagicIcon url={link.url} />
+ <a
+ className="text-xs text-neutral-400 hover:text-neutral-600 dark:text-neutral-600 dark:hover:text-neutral-400"
+ href={link.url}
+ rel="noopener noreferrer"
+ target="_blank"
+ >
+ {stripProtocolAndWWW(link.url)}
+ </a>
+ </div>
+ ))}
</div>
)}
- </div>
- <div className="flex gap-4 pr-6 md:flex-col">
- <VerticalTabsTrigger
- className="flex items-center justify-center gap-3 px-2 md:justify-normal md:px-3"
- value="in-progress"
- >
- <Play className="h-4 w-4" />
- <span className="hidden md:block">In-Progress</span>
- </VerticalTabsTrigger>
- <VerticalTabsTrigger
- className="flex items-center justify-center gap-3 px-2 md:justify-normal md:px-3"
- value="submissions"
- >
- <ChevronRightSquare className="h-4 w-4" />
- <span className="hidden md:block">Submissions</span>
- </VerticalTabsTrigger>
- <VerticalTabsTrigger
- className="flex items-center justify-center gap-3 px-2 md:justify-normal md:px-3"
- disabled
- value="bookmarks"
- >
- <Bookmark className="h-4 w-4" />
- <span className="hidden md:block">Bookmarks</span>
- </VerticalTabsTrigger>
- <VerticalTabsTrigger
- className="flex items-center justify-center gap-3 px-2 md:justify-normal md:px-3"
- disabled
- value="comments"
- >
- <MessagesSquare className="h-4 w-4" />
- <span className="hidden md:block">Comments</span>
- </VerticalTabsTrigger>
- <div>
- {session?.user.id === user.id && (
- <Link
- href="/settings"
- className="border-border dark:border-ring data-[state=active]:bg-border ring-offset-background focus-visible:ring-ring data-[state=active]:text-foreground flex items-center justify-center gap-3 whitespace-nowrap rounded-xl border px-1.5 py-1.5 text-sm font-medium transition-all duration-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm md:justify-normal md:px-3"
+ <div className="flex gap-4 md:w-full md:flex-col">
+ <VerticalTabsTrigger
+ className="flex items-center justify-center gap-3 px-2 md:justify-normal md:px-3"
+ value="overview"
+ >
+ <Text className="h-4 w-4" />
+ <span className="hidden md:block">Overview</span>
+ </VerticalTabsTrigger>
+ {Boolean(isOwnProfile) && (
+ <VerticalTabsTrigger
+ className="flex items-center justify-center gap-3 px-2 md:justify-normal md:px-3"
+ value="in-progress"
>
- <Settings width={18} height={18} />
- <span className="hidden md:block">Settings</span>
- </Link>
+ <Play className="h-4 w-4" />
+ <span className="hidden md:block">In-Progress</span>
+ </VerticalTabsTrigger>
+ )}
+ <VerticalTabsTrigger
+ className="flex items-center justify-center gap-3 px-2 md:justify-normal md:px-3"
+ value="shared-solutions"
+ >
+ <ChevronRightSquare className="h-4 w-4" />
+ <span className="hidden md:block">Shared Solutions</span>
+ </VerticalTabsTrigger>
+ {Boolean(isOwnProfile) && (
+ <>
+ <VerticalTabsTrigger
+ className="flex items-center justify-center gap-3 px-2 md:justify-normal md:px-3"
+ value="bookmarks"
+ >
+ <Bookmark className="h-4 w-4" />
+ <span className="hidden md:block">Bookmarks</span>
+ </VerticalTabsTrigger>
+ <Link
+ href="/settings"
+ className="border-border dark:border-ring data-[state=active]:bg-border ring-offset-background focus-visible:ring-ring data-[state=active]:text-foreground flex items-center justify-center gap-3 whitespace-nowrap rounded-xl border px-1.5 py-1.5 text-sm font-medium transition-all duration-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm md:justify-normal md:px-3"
+ >
+ <Settings className="h-4 w-4" />
+ <span className="hidden md:block">Settings</span>
+ </Link>
+ </>
)}
</div>
</div>
</VerticalTabsList>
<VerticalTabsContent className="shrink grow space-y-4" value="overview">
- <Card className="col-span-4 min-h-[calc(100vh_-_56px_-_6rem)]">
+ <Card className="col-span-4 md:min-h-[calc(100vh_-_56px_-_6rem)]">
<CardHeader>
<CardTitle>Overview</CardTitle>
</CardHeader>
- <CardContent className="pl-2">
- <Overview />
+ <CardContent>
+ <OverviewTab user={user} />
</CardContent>
</Card>
</VerticalTabsContent>
<VerticalTabsContent className="shrink grow space-y-4" value="in-progress">
- <Card className="col-span-4 min-h-[calc(100vh_-_56px_-_6rem)]">
+ <Card className="col-span-4 md:min-h-[calc(100vh_-_56px_-_6rem)]">
<CardHeader>
<CardTitle>In-Progress</CardTitle>
<CardDescription className="text-muted-foreground mb-4 text-sm">
- These are all your in-progress challenges.
+ Your in-progress challenges.
</CardDescription>
</CardHeader>
- <CardContent className="pl-2">
+ <CardContent>
<InProgressTab userId={user.id} />
</CardContent>
</Card>
</VerticalTabsContent>
- <VerticalTabsContent className="shrink grow space-y-4" value="submissions">
- <Card className="col-span-4 min-h-[calc(100vh_-_56px_-_6rem)]">
+ <VerticalTabsContent className="shrink grow space-y-4" value="shared-solutions">
+ <Card className="col-span-4 md:min-h-[calc(100vh_-_56px_-_6rem)]">
+ <CardHeader>
+ <CardTitle>Shared Solutions</CardTitle>
+ <CardDescription className="text-muted-foreground mb-4 text-sm">
+ {isOwnProfile ? 'Your' : `${user.name}'s`} shared challenge solutions.
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ <SharedSolutionsTab userId={user.id} />
+ </CardContent>
+ </Card>
+ </VerticalTabsContent>
+ <VerticalTabsContent className="shrink grow space-y-4" value="bookmarks">
+ <Card className="col-span-4 md:min-h-[calc(100vh_-_56px_-_6rem)]">
<CardHeader>
- <CardTitle>Submissions</CardTitle>
+ <CardTitle>Bookmarks</CardTitle>
<CardDescription className="text-muted-foreground mb-4 text-sm">
- This is your entire submission history.
+ Your bookmarked challenges.
</CardDescription>
</CardHeader>
- <CardContent className="pl-2">
- <SubmissionsTab userId={user.id} />
+ <CardContent>
+ <BookmarksTab userId={user.id} />
</CardContent>
</Card>
</VerticalTabsContent>
diff --git a/apps/web/src/app/[locale]/[username]/_components/dashboard/overview-tab.tsx b/apps/web/src/app/[locale]/[username]/_components/dashboard/overview-tab.tsx
new file mode 100644
index 00000000..f98f8013
--- /dev/null
+++ b/apps/web/src/app/[locale]/[username]/_components/dashboard/overview-tab.tsx
@@ -0,0 +1,23 @@
+import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
+
+import type { User } from '@repo/db/types';
+
+interface Props {
+ // TODO: how do do this union type with just letting prisma halp
+ user: Pick<User, 'bio' | 'createdAt' | 'id' | 'image' | 'name'> & {
+ userLinks: { id: string | null; url: string }[];
+ };
+}
+
+export async function OverviewTab({ user }: Props) {
+ const hasBio = Boolean(user.bio) && user.bio.trim().length > 0;
+
+ return (
+ <div className="w-full text-sm md:w-64 md:text-start">
+ {Boolean(hasBio) && <ReactMarkdown>{user.bio}</ReactMarkdown>}
+ {Boolean(!hasBio) && (
+ <p className="text-muted-foreground">{user.name} does not have a bio.</p>
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/[username]/_components/dashboard/overview.tsx b/apps/web/src/app/[locale]/[username]/_components/dashboard/overview.tsx
deleted file mode 100644
index 270d47ca..00000000
--- a/apps/web/src/app/[locale]/[username]/_components/dashboard/overview.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import {
- Table,
- TableBody,
- TableCaption,
- TableCell,
- TableHead,
- TableHeader,
- TableRow,
-} from '@repo/ui/components/table';
-
-const challengesList = [
- {
- challengeTitle: 'Extreme Challenge 1',
- challengeStatus: 'In-Progress',
- },
- {
- challengeTitle: 'Easy Challenge 1',
- challengeStatus: 'Submitted',
- },
- {
- challengeTitle: 'Easy Challenge 2',
- challengeStatus: 'Submitted',
- },
- {
- challengeTitle: 'Easy Challenge 3',
- challengeStatus: 'Submitted',
- },
- {
- challengeTitle: 'Extreme Challenge 4',
- challengeStatus: 'In-Progress',
- },
-];
-
-export function Overview() {
- return (
- <Table>
- <TableCaption>A list of your recent challenges.</TableCaption>
- <TableHeader>
- <TableRow>
- <TableHead>Challenge</TableHead>
- <TableHead>Status</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {challengesList.map((challengeTitle) => (
- <TableRow key={challengeTitle.challengeTitle}>
- <TableCell className="font-medium">{challengeTitle.challengeTitle}</TableCell>
- <TableCell>{challengeTitle.challengeStatus}</TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- );
-}
diff --git a/apps/web/src/app/[locale]/[username]/_components/dashboard/shared-solutions-tab.tsx b/apps/web/src/app/[locale]/[username]/_components/dashboard/shared-solutions-tab.tsx
new file mode 100644
index 00000000..020bbaa3
--- /dev/null
+++ b/apps/web/src/app/[locale]/[username]/_components/dashboard/shared-solutions-tab.tsx
@@ -0,0 +1,76 @@
+import Link from 'next/link';
+
+import { prisma } from '@repo/db';
+import { Badge } from '@repo/ui/components/badge';
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from '@repo/ui/components/table';
+
+import { getRelativeTime } from '~/utils/relativeTime';
+import { withUnstableCache } from '~/utils/withUnstableCache';
+
+export async function SharedSolutionsTab({ userId }: { userId: string }) {
+ const solutions = await withUnstableCache({
+ fn: getSharedSolutions,
+ args: [userId],
+ keys: ['shared-solutions'],
+ tags: ['submissions'],
+ });
+
+ return (
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Shared Solution</TableHead>
+ <TableHead>Votes</TableHead>
+ <TableHead>Date</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {solutions.map((solution) => (
+ <TableRow key={solution.id}>
+ <TableCell className="font-medium underline">
+ <Link href={`/challenge/${solution.challenge?.slug}`}>
+ {solution.challenge?.name}
+ </Link>
+ </TableCell>
+ <TableCell>{solution._count.vote}</TableCell>
+ <TableCell className="font-medium underline">
+ {Boolean(solution.createdAt) && getRelativeTime(solution.createdAt)}
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ );
+}
+
+async function getSharedSolutions(userId: string) {
+ return await prisma.sharedSolution.findMany({
+ where: {
+ userId,
+ },
+ orderBy: {
+ createdAt: 'desc',
+ },
+ include: {
+ _count: {
+ select: {
+ vote: true,
+ },
+ },
+ challenge: {
+ select: {
+ id: true,
+ slug: true,
+ name: true,
+ },
+ },
+ },
+ });
+}
diff --git a/apps/web/src/app/[locale]/[username]/_components/dashboard/submissions-tab.tsx b/apps/web/src/app/[locale]/[username]/_components/dashboard/submissions-tab.tsx
deleted file mode 100644
index 89e3bd0c..00000000
--- a/apps/web/src/app/[locale]/[username]/_components/dashboard/submissions-tab.tsx
+++ /dev/null
@@ -1,72 +0,0 @@
-import { prisma } from '@repo/db';
-import { Badge } from '@repo/ui/components/badge';
-import {
- Table,
- TableBody,
- TableCell,
- TableHead,
- TableHeader,
- TableRow,
-} from '@repo/ui/components/table';
-import Link from 'next/link';
-import { withUnstableCache } from '~/utils/withUnstableCache';
-
-export async function SubmissionsTab({ userId }: { userId: string }) {
- const submissions = await withUnstableCache({
- fn: getRecentSubmissions,
- args: [userId],
- keys: ['all-submissions'],
- tags: ['submissions'],
- });
-
- return (
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead>Challenge</TableHead>
- <TableHead>Status</TableHead>
- </TableRow>
- </TableHeader>
-
- <TableBody>
- {submissions.map((submission) => (
- <TableRow key={submission.id}>
- <TableCell className="font-medium underline">
- <Link href={`/challenge/${submission.challenge.id}`}>
- {submission.challenge.name}
- </Link>
- </TableCell>
- <TableCell>
- {submission.isSuccessful ? (
- <Badge className="dark:bg-difficulty-easy-dark bg-difficulty-easy text-white duration-300 dark:text-black">
- Accepted
- </Badge>
- ) : (
- <Badge className="dark:bg-difficulty-hard-dark bg-difficulty-hard text-white duration-300 dark:text-black">
- Rejected
- </Badge>
- )}
- </TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- );
-}
-
-async function getRecentSubmissions(id: string) {
- return await prisma.submission.findMany({
- where: {
- userId: id,
- },
- orderBy: [
- {
- createdAt: 'desc',
- },
- ],
- take: 25,
- include: {
- challenge: true,
- },
- });
-}
diff --git a/apps/web/src/app/[locale]/[username]/_components/profile.tsx b/apps/web/src/app/[locale]/[username]/_components/profile.tsx
index 96dcbda3..d5759d26 100644
--- a/apps/web/src/app/[locale]/[username]/_components/profile.tsx
+++ b/apps/web/src/app/[locale]/[username]/_components/profile.tsx
@@ -34,5 +34,6 @@ export async function Profile({ username: usernameFromQuery }: Props) {
});
if (!user) return notFound();
+
return <Dashboard user={user} />;
}
diff --git a/packages/db/schema.prisma b/packages/db/schema.prisma
index acdeff9d..5993e85a 100644
--- a/packages/db/schema.prisma
+++ b/packages/db/schema.prisma
@@ -105,7 +105,7 @@ model User {
roles Role[]
/// this is the bio that shows up on the profile page
- bio String @default("") @db.VarChar(256)
+ bio String @default("") @db.VarChar(1000)
/// this is the twitter URL that shows up on the profile page
userLinks UserLink[]
@@ -253,6 +253,8 @@ model Bookmark {
challenge Challenge? @relation(fields: [challengeId], references: [id])
challengeId Int?
+ createdAt DateTime? @default(now())
+
@@index([userId])
@@index([challengeId])
}