Skip to content

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

alot of stuff (#222)

bautistaaa4473971724ff
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index e47388c1..98f61d14 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -90,11 +90,11 @@ model User {
status UserStatus @default(PENDING)
banReason String? @db.MediumText
- accounts Account[]
- sessions Session[]
- challenge Challenge[]
- vote Vote[]
- solution Solution[]
+ accounts Account[]
+ sessions Session[]
+ challenge Challenge[]
+ vote Vote[]
+ submission Submission[]
challengeReports ChallengeReport[] @relation(name: "authored_challenge_reports")
moderatedChallengeReports ChallengeReport[] @relation(name: "moderated_challenge_reports")
@@ -138,7 +138,7 @@ model Challenge {
userId String
vote Vote[]
- solution Solution[]
+ submission Submission[]
comment ChallengeComment[]
report ChallengeReport[]
bookmark Bookmark[]
@@ -153,14 +153,15 @@ model Vote {
userId String
challenge Challenge? @relation(fields: [challengeId], references: [id])
challengeId Int?
- solution Solution? @relation(fields: [solutionId], references: [id])
- solutionId Int?
+ submission Submission? @relation(fields: [submissionId], references: [id])
+ submissionId Int?
sharedSolution SharedSolution? @relation(fields: [sharedSolutionId], references: [id])
sharedSolutionId Int?
@@index([userId])
@@index([challengeId])
- @@index([solutionId])
+ @@index([submissionId])
+ @@index([sharedSolutionId])
}
/// This is a public solution created by a user for a challenge
@@ -180,8 +181,8 @@ model SharedSolution {
@@index([challengeId])
}
-/// This is a submission of a challenge
-model Solution {
+/// Every attempt a user makes to a challenge is stored here
+model Submission {
id Int @id @default(autoincrement())
code String @db.MediumText
createdAt DateTime @default(now())
diff --git a/prisma/seed.ts b/prisma/seed.ts
index 26f57484..38fd7ccb 100644
--- a/prisma/seed.ts
+++ b/prisma/seed.ts
@@ -40,7 +40,7 @@ try {
name: 'g',
challenge: challenges(),
- solution: {
+ submission: {
create: {
code: 'const a: string = "hello world"',
isSuccessful: true,
diff --git a/src/app/api/submissions/[id]/route.ts b/src/app/api/submissions/[id]/route.ts
new file mode 100644
index 00000000..7ce11cc4
--- /dev/null
+++ b/src/app/api/submissions/[id]/route.ts
@@ -0,0 +1,12 @@
+import { NextResponse } from 'next/server';
+import { prisma } from '~/server/db';
+
+export async function GET(request: Request, { params }: { params: { id: string } }) {
+ const submission = await prisma.submission.findFirst({
+ where: {
+ id: Number(params.id),
+ },
+ });
+
+ return NextResponse.json(submission);
+}
diff --git a/src/app/challenge/[id]/getChallengeRouteData.ts b/src/app/challenge/[id]/getChallengeRouteData.ts
index 25c49765..01ad01dc 100644
--- a/src/app/challenge/[id]/getChallengeRouteData.ts
+++ b/src/app/challenge/[id]/getChallengeRouteData.ts
@@ -4,7 +4,7 @@ import { prisma } from '~/server/db';
export type ChallengeRouteData = NonNullable<Awaited<ReturnType<typeof getChallengeRouteData>>>;
-// TODO: Make this only get called once on the routes that need it
+// this is to data to populate the description tab (default tab on challenge page)
export async function getChallengeRouteData(id: string, session: Session | null) {
const challenge = await prisma.challenge.findFirst({
where: { id: +id },
@@ -23,31 +23,6 @@ export async function getChallengeRouteData(id: string, session: Session | null)
userId: session?.user.id || '',
},
},
- solution: {
- where: {
- userId: session?.user.id || '',
- },
- orderBy: [
- {
- createdAt: 'desc',
- },
- ],
- take: 10,
- },
- sharedSolution: {
- orderBy: [
- {
- createdAt: 'desc',
- },
- ],
- take: 5,
- include: {
- user: true,
- _count: {
- select: { vote: true, solutionComment: true },
- },
- },
- },
comment: {
orderBy: [
{
diff --git a/src/app/challenge/[id]/solutions/[solutionId]/page.tsx b/src/app/challenge/[id]/solutions/[solutionId]/page.tsx
index a996fae2..a35b60b2 100644
--- a/src/app/challenge/[id]/solutions/[solutionId]/page.tsx
+++ b/src/app/challenge/[id]/solutions/[solutionId]/page.tsx
@@ -7,7 +7,7 @@ interface Props {
};
}
-export type SolutionData = NonNullable<Awaited<ReturnType<typeof getSolution>>>;
+export type ChallengeSolution = NonNullable<Awaited<ReturnType<typeof getSolution>>>;
export default async function SolutionPage({ params: { solutionId } }: Props) {
const solution = await getSolution(solutionId);
if (!solution) return null;
diff --git a/src/app/challenge/[id]/solutions/page.tsx b/src/app/challenge/[id]/solutions/page.tsx
index 29d62d2a..41054180 100644
--- a/src/app/challenge/[id]/solutions/page.tsx
+++ b/src/app/challenge/[id]/solutions/page.tsx
@@ -1,7 +1,8 @@
+import type { Session } from 'next-auth';
import { notFound } from 'next/navigation';
-import { getChallengeRouteData } from '../getChallengeRouteData';
-import { getServerAuthSession } from '~/server/auth';
import { Solutions } from '~/components/challenge/solutions';
+import { getServerAuthSession } from '~/server/auth';
+import { prisma } from '~/server/db';
interface Props {
params: {
@@ -11,11 +12,48 @@ interface Props {
export default async function SolutionPage({ params: { id } }: Props) {
const session = await getServerAuthSession();
- const challenge = await getChallengeRouteData(id, session);
+ const solutions = await getSolutionsData(id, session);
- if (!challenge) {
+ if (!solutions) {
return notFound();
}
- return <Solutions challenge={challenge} />;
+ return <Solutions challenge={solutions} />;
+}
+
+export type ChallengeSolutionsRouteData = NonNullable<Awaited<ReturnType<typeof getSolutionsData>>>;
+export async function getSolutionsData(challengeId: string, session: Session | null) {
+ const data = await prisma.challenge.findFirst({
+ where: { id: +challengeId },
+ select: {
+ id: true,
+ // we just want their most recent solution
+ submission: {
+ where: {
+ userId: session?.user.id || '',
+ },
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ take: 1,
+ },
+ sharedSolution: {
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ include: {
+ user: true,
+ _count: {
+ select: { vote: true, solutionComment: true },
+ },
+ },
+ },
+ },
+ });
+
+ return data;
}
diff --git a/src/app/challenge/[id]/submissions/[submissionId]/page.tsx b/src/app/challenge/[id]/submissions/[submissionId]/page.tsx
index a959cc2b..28125189 100644
--- a/src/app/challenge/[id]/submissions/[submissionId]/page.tsx
+++ b/src/app/challenge/[id]/submissions/[submissionId]/page.tsx
@@ -1,8 +1,8 @@
import { notFound } from 'next/navigation';
import { getServerAuthSession } from '~/server/auth';
-import { getChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';
import { Submissions } from '~/components/challenge/submissions';
+import { getChallengeSubmissions } from '../page';
interface Props {
params: {
id: string;
@@ -11,11 +11,11 @@ interface Props {
export default async function SubmissionPage({ params: { id } }: Props) {
const session = await getServerAuthSession();
- const challenge = await getChallengeRouteData(id, session);
+ const submissions = await getChallengeSubmissions(session?.user.id ?? '', id);
- if (!challenge) {
+ if (!submissions) {
return notFound();
}
- return <Submissions challenge={challenge} />;
+ return <Submissions submissions={submissions} />;
}
diff --git a/src/app/challenge/[id]/submissions/page.tsx b/src/app/challenge/[id]/submissions/page.tsx
index ab745e6c..3c5f9a0e 100644
--- a/src/app/challenge/[id]/submissions/page.tsx
+++ b/src/app/challenge/[id]/submissions/page.tsx
@@ -1,7 +1,7 @@
import { notFound } from 'next/navigation';
import { Submissions } from '~/components/challenge/submissions';
import { getServerAuthSession } from '~/server/auth';
-import { getChallengeRouteData } from '../getChallengeRouteData';
+import { prisma } from '~/server/db';
interface Props {
params: {
@@ -11,10 +11,25 @@ interface Props {
export default async function SubmissionPage({ params: { id } }: Props) {
const session = await getServerAuthSession();
- const challenge = await getChallengeRouteData(id, session);
+ const submissions = await getChallengeSubmissions(session?.user.id ?? '', id);
- if (!challenge) {
+ if (!submissions) {
return notFound();
}
- return <Submissions challenge={challenge} />;
+
+ return <Submissions submissions={submissions} />;
+}
+
+export type ChallengeSubmissions = NonNullable<Awaited<ReturnType<typeof getChallengeSubmissions>>>;
+export async function getChallengeSubmissions(userId: string, challengeId: string) {
+ const solutions = await prisma.submission.findMany({
+ where: { challengeId: +challengeId, userId },
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ });
+
+ return solutions;
}
diff --git a/src/app/challenge/[id]/wrapper.tsx b/src/app/challenge/[id]/wrapper.tsx
index 35e14530..d205dee0 100644
--- a/src/app/challenge/[id]/wrapper.tsx
+++ b/src/app/challenge/[id]/wrapper.tsx
@@ -6,9 +6,11 @@ import { SubmissionOverview } from '~/components/challenge/submissions/overview'
export function Wrapper({ challenge }: { challenge: ChallengeRouteData }) {
const segments = useSelectedLayoutSegments();
+
if (!challenge) return null;
+
if (segments[0] === 'submissions' && typeof segments[1] === 'string') {
- return <SubmissionOverview challenge={challenge} submissionId={segments[1]} />;
+ return <SubmissionOverview submissionId={segments[1]} />;
}
return <CodePanel mode="solve" challenge={challenge} />;
diff --git a/src/app/create/preview/page.tsx b/src/app/create/preview/page.tsx
index edf4bcc6..58cab9ff 100644
--- a/src/app/create/preview/page.tsx
+++ b/src/app/create/preview/page.tsx
@@ -77,7 +77,7 @@ export default function PreviewCreatedChallenge() {
...createChallengeStore.data,
_count: {
vote: 420,
- solution: 0,
+ submission: 0,
comment: 0,
},
updatedAt: new Date(),
diff --git a/src/components/challenge/editor/index.tsx b/src/components/challenge/editor/index.tsx
index 9cc29383..2c06dcec 100644
--- a/src/components/challenge/editor/index.tsx
+++ b/src/components/challenge/editor/index.tsx
@@ -55,7 +55,7 @@ const LIB_URI = 'ts:filename/checking.d.ts';
type Props = (
| {
mode: 'solve';
- challenge: Pick<ChallengeRouteData, 'solution' | 'prompt' | 'id'>;
+ challenge: ChallengeRouteData;
prompt?: never;
}
| {
diff --git a/src/components/challenge/save-submission.action.ts b/src/components/challenge/save-submission.action.ts
index 74a6e4aa..0ecf72f4 100644
--- a/src/components/challenge/save-submission.action.ts
+++ b/src/components/challenge/save-submission.action.ts
@@ -7,7 +7,7 @@ export async function saveSubmission(
code: string,
isSuccessful: boolean,
) {
- await prisma.solution.create({
+ await prisma.submission.create({
data: {
challengeId,
userId,
diff --git a/src/components/challenge/solutions/index.tsx b/src/components/challenge/solutions/index.tsx
index bd8e37f0..8169b1c6 100644
--- a/src/components/challenge/solutions/index.tsx
+++ b/src/components/challenge/solutions/index.tsx
@@ -4,23 +4,21 @@ import { ArrowUp, MessageCircle, Plus } from 'lucide-react';
import { Button } from '~/components/ui/button';
import { useSession } from 'next-auth/react';
+import Link from 'next/link';
import { useState } from 'react';
-import { type ChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';
+import type { ChallengeSolutionsRouteData } from '~/app/challenge/[id]/solutions/page';
import { getRelativeTime } from '~/utils/relativeTime';
import { SolutionEditor } from './solution-editor';
-import Link from 'next/link';
interface Props {
- challenge: ChallengeRouteData;
+ challenge: ChallengeSolutionsRouteData;
}
type View = 'editor' | 'list' | 'details';
export function Solutions({ challenge }: Props) {
const [view, setView] = useState<View>('list');
- const hasSolution = challenge.solution?.length > 0;
+ const loggedInUserHasSolution = challenge?.submission?.length;
const session = useSession();
- const sharedSolution = challenge.sharedSolution;
-
return (
<div className="relative h-full">
{view === 'editor' && (
@@ -33,12 +31,12 @@ export function Solutions({ challenge }: Props) {
<Button
className="h-8 rounded-lg bg-emerald-600 px-3 py-2 hover:bg-emerald-500 dark:bg-emerald-400 dark:hover:bg-emerald-300"
onClick={() => setView('editor')}
- disabled={!hasSolution || !session?.data?.user}
+ disabled={!loggedInUserHasSolution || !session?.data?.user}
>
<Plus className="mr-2 h-4 w-4" /> Solution
</Button>
</div>
- {sharedSolution.map((solution) => (
+ {challenge?.sharedSolution.map((solution) => (
<SolutionRow
key={solution.id}
solution={solution}
@@ -59,7 +57,7 @@ function SolutionRow({
solution,
}: {
handleClick: (id: string) => void;
- solution: ChallengeRouteData['sharedSolution'][number];
+ solution: ChallengeSolutionsRouteData['sharedSolution'][0];
}) {
return (
<Link href={`/challenge/${solution.challengeId}/solutions/${solution.id}`}>
diff --git a/src/components/challenge/solutions/solution-detail.tsx b/src/components/challenge/solutions/solution-detail.tsx
index 4c284818..821e185a 100644
--- a/src/components/challenge/solutions/solution-detail.tsx
+++ b/src/components/challenge/solutions/solution-detail.tsx
@@ -1,7 +1,8 @@
'use client';
+
import { Calendar, MessageCircle, Share, X } from 'lucide-react';
import Link from 'next/link';
-import type { SolutionData } from '~/app/challenge/[id]/solutions/[solutionId]/page';
+import type { ChallengeSolution } from '~/app/challenge/[id]/solutions/[solutionId]/page';
import { Avatar, AvatarFallback, AvatarImage } from '~/components/ui/avatar';
import { Button } from '~/components/ui/button';
import { Markdown } from '~/components/ui/markdown';
@@ -10,12 +11,12 @@ import { toast } from '~/components/ui/use-toast';
import { UserBadge } from '~/components/ui/user-badge';
interface Props {
- solution: SolutionData;
+ solution: ChallengeSolution;
}
export function SolutionDetails({ solution }: Props) {
- const url = window.location.href;
const handleShareClick = async () => {
if (navigator.clipboard) {
+ const url = window.location.href;
await navigator.clipboard.writeText(url);
toast({
variant: 'success',
diff --git a/src/components/challenge/solutions/solution-editor.tsx b/src/components/challenge/solutions/solution-editor.tsx
index f3b57dce..151ac0a9 100644
--- a/src/components/challenge/solutions/solution-editor.tsx
+++ b/src/components/challenge/solutions/solution-editor.tsx
@@ -1,4 +1,7 @@
import { zodResolver } from '@hookform/resolvers/zod';
+import { useSession } from 'next-auth/react';
+import { useTheme } from 'next-themes';
+import { useRouter } from 'next/navigation';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { Button } from '~/components/ui/button';
@@ -6,11 +9,8 @@ import { Form, FormControl, FormField, FormItem, FormMessage } from '~/component
import { Input } from '~/components/ui/input';
import { useToast } from '~/components/ui/use-toast';
import { postSolution } from './post-solution.action';
-import { type ChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';
-import { useSession } from 'next-auth/react';
-import { useTheme } from 'next-themes';
-import { useRouter } from 'next/navigation';
+import type { ChallengeSolutionsRouteData } from '~/app/challenge/[id]/solutions/page';
import { RichMarkdownEditor } from '~/components/ui/rich-markdown-editor';
const getDefaultMarkdown = (solution: string) => `
@@ -35,7 +35,7 @@ const formSchema = z.object({
export type FormSchema = z.infer<typeof formSchema>;
interface Props {
- challenge: ChallengeRouteData;
+ challenge: ChallengeSolutionsRouteData;
dismiss: () => void;
}
@@ -45,7 +45,7 @@ export function SolutionEditor({ dismiss, challenge }: Props) {
const form = useForm<FormSchema>({
resolver: zodResolver(formSchema),
defaultValues: {
- content: getDefaultMarkdown(challenge.solution[0]?.code ?? ''),
+ content: getDefaultMarkdown(challenge.submission[0]?.code ?? ''),
},
});
const { toast } = useToast();
diff --git a/src/components/challenge/submissions/index.tsx b/src/components/challenge/submissions/index.tsx
index dbddc0a2..e2606c54 100644
--- a/src/components/challenge/submissions/index.tsx
+++ b/src/components/challenge/submissions/index.tsx
@@ -1,24 +1,23 @@
'use client';
-import type { Solution } from '@prisma/client';
-import { type ChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';
-import { getRelativeTime } from '~/utils/relativeTime';
+import type { Submission } from '@prisma/client';
import clsx from 'clsx';
+import { getRelativeTime } from '~/utils/relativeTime';
-import { useMemo, useState } from 'react';
import Link from 'next/link';
+import { useMemo, useState } from 'react';
+import type { ChallengeSubmissions } from '~/app/challenge/[id]/submissions/page';
interface Props {
- challenge: ChallengeRouteData;
+ submissions: ChallengeSubmissions;
}
type Status = 'all' | 'accepted' | 'rejected';
-export function Submissions({ challenge }: Props) {
+export function Submissions({ submissions }: Props) {
const [selectedStatus, setSelectStatus] = useState<Status>('all');
- const submissions = challenge.solution;
const filteredSubmissions = useMemo(() => {
- const predicate = (submission: Solution) => {
+ const predicate = (submission: Submission) => {
if (selectedStatus === 'all') return true;
if (selectedStatus === 'accepted') return submission.isSuccessful;
return !submission.isSuccessful;
@@ -64,7 +63,11 @@ export function Submissions({ challenge }: Props) {
<ul className="relative flex flex-col">
{filteredSubmissions.map((submission) => {
return (
- <SubmissionRow challengeId={challenge.id} submission={submission} key={submission.id} />
+ <SubmissionRow
+ challengeId={submission.challengeId}
+ submission={submission}
+ key={submission.id}
+ />
);
})}
</ul>
@@ -73,7 +76,7 @@ export function Submissions({ challenge }: Props) {
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
-function SubmissionRow({ challengeId, submission }: { challengeId: number; submission: Solution }) {
+function SubmissionRow({ challengeId, submission }: { challengeId: number; submission: Submission }) {
return (
<li className="flex cursor-pointer items-center justify-between px-4 py-2 duration-300 hover:bg-neutral-100 dark:rounded-none dark:hover:bg-zinc-700/50">
<Link className="w-full" href={`/challenge/${challengeId}/submissions/${submission.id}`}>
diff --git a/src/components/challenge/submissions/overview.tsx b/src/components/challenge/submissions/overview.tsx
index a3ff8b91..1f800287 100644
--- a/src/components/challenge/submissions/overview.tsx
+++ b/src/components/challenge/submissions/overview.tsx
@@ -1,23 +1,27 @@
+import { useQuery } from '@tanstack/react-query';
import { Copy, X } from 'lucide-react';
import Link from 'next/link';
-
-import type { ChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';
import { Button } from '~/components/ui/button';
import { Markdown } from '~/components/ui/markdown';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '~/components/ui/tooltip';
import { toast } from '~/components/ui/use-toast';
+import { getBaseUrl } from '~/utils/getBaseUrl';
import { getRelativeTime } from '~/utils/relativeTime';
interface Props {
- challenge: ChallengeRouteData;
submissionId: string;
}
const codifyForMarkdown = (code: string) => {
return `\`\`\`ts
${code} \`\`\``;
};
-export function SubmissionOverview({ challenge, submissionId }: Props) {
- const submission = challenge.solution?.find((submission) => submission.id === +submissionId);
+
+export function SubmissionOverview({ submissionId }: Props) {
+ const { data: submission } = useQuery({
+ queryKey: ['submission', submissionId],
+ queryFn: () => getSubmission(submissionId),
+ });
+
const code = codifyForMarkdown(submission?.code.trimStart() ?? '');
const copyToClipboard = async () => {
@@ -35,7 +39,7 @@ export function SubmissionOverview({ challenge, submissionId }: Props) {
return (
<>
<div className="sticky top-0 flex h-[40px] items-center justify-between border-b border-zinc-300 px-3 py-2 dark:border-zinc-700 dark:bg-[#1e1e1e]">
- <Link href={`/challenge/${challenge.id}/submissions`}>
+ <Link href={`/challenge/${submission.challengeId}/submissions`}>
<X size={20} className="stroke-gray-500 hover:stroke-gray-400" />
</Link>
<TooltipProvider>
@@ -60,7 +64,7 @@ export function SubmissionOverview({ challenge, submissionId }: Props) {
: 'bg-rose-600/10 text-rose-600 dark:bg-rose-400/10 dark:text-rose-400 '
}`}
>
- {submission?.isSuccessful ? 'Accepted' : 'Rejected'}
+ {submission.isSuccessful ? 'Accepted' : 'Rejected'}
</div>
<div className="text-sm text-neutral-500">{getRelativeTime(submission.createdAt)}</div>
</div>
@@ -69,3 +73,7 @@ export function SubmissionOverview({ challenge, submissionId }: Props) {
</>
);
}
+
+function getSubmission(id: string) {
+ return fetch(`${getBaseUrl()}/api/submissions/${id}`).then((res) => res.json());
+}
diff --git a/src/components/explore/explore-card.tsx b/src/components/explore/explore-card.tsx
index ce15da2f..3eb6fe69 100644
--- a/src/components/explore/explore-card.tsx
+++ b/src/components/explore/explore-card.tsx
@@ -135,7 +135,7 @@ const ExploreCard = ({ challenge }: ExploreCardProps) => {
</div>
<div className="mr-auto flex flex-col items-center">
<h1 className="text-4xl font-bold text-black dark:text-white">
- {challenge._count.solution}
+ {challenge._count.submission}
</h1>
<span>Solutions</span>
</div>
diff --git a/src/components/explore/index.tsx b/src/components/explore/index.tsx
index d311c8ca..44f09072 100644
--- a/src/components/explore/index.tsx
+++ b/src/components/explore/index.tsx
@@ -29,7 +29,7 @@ async function getExploreChallengeData() {
},
include: {
_count: {
- select: { vote: true, comment: true, solution: true },
+ select: { vote: true, comment: true, submission: true },
},
},
});
diff --git a/src/components/user/dashboard/index.tsx b/src/components/user/dashboard/index.tsx
index acffff44..e750c8d4 100644
--- a/src/components/user/dashboard/index.tsx
+++ b/src/components/user/dashboard/index.tsx
@@ -19,7 +19,7 @@ async function getUserdata(id: string) {
id,
},
include: {
- solution: {
+ submission: {
where: {
userId: id,
},
@@ -130,7 +130,7 @@ export default async function Dashboard({ user }: Props) {
<CardTitle>Solutions</CardTitle>
</CardHeader>
<CardContent className="pl-2">
- <SolutionsTab solutions={userData.solution} />
+ <SolutionsTab submissions={userData.submission} />
</CardContent>
</Card>
</div>
diff --git a/src/components/user/dashboard/solutions-tab.tsx b/src/components/user/dashboard/solutions-tab.tsx
index bc1de0df..3c1cbbe3 100644
--- a/src/components/user/dashboard/solutions-tab.tsx
+++ b/src/components/user/dashboard/solutions-tab.tsx
@@ -10,7 +10,7 @@ import {
import type { UserData } from '.';
import Link from 'next/link';
-export function SolutionsTab({ solutions = [] }: { solutions: UserData['solution'] }) {
+export function SolutionsTab({ submissions = [] }: { submissions: UserData['submission'] }) {
return (
<Table>
<TableCaption>A list of your recent challenges.</TableCaption>
@@ -21,12 +21,12 @@ export function SolutionsTab({ solutions = [] }: { solutions: UserData['solution
</TableRow>
</TableHeader>
<TableBody>
- {solutions.map((solution) => (
- <TableRow key={solution.id}>
+ {submissions.map((submission) => (
+ <TableRow key={submission.id}>
<TableCell className="font-medium underline">
- <Link href={`/challenge/${solution.challenge.id}`}>{solution.challenge.name}</Link>
+ <Link href={`/challenge/${submission.challenge.id}`}>{submission.challenge.name}</Link>
</TableCell>
- <TableCell>{solution.isSuccessful ? 'Accepted' : 'Rejected'}</TableCell>
+ <TableCell>{submission.isSuccessful ? 'Accepted' : 'Rejected'}</TableCell>
</TableRow>
))}
</TableBody>
diff --git a/src/utils/getBaseUrl.ts b/src/utils/getBaseUrl.ts
new file mode 100644
index 00000000..55561872
--- /dev/null
+++ b/src/utils/getBaseUrl.ts
@@ -0,0 +1,15 @@
+export function getBaseUrl() {
+ if (typeof window !== 'undefined') {
+ // In the browser, we return a relative URL
+ return '';
+ }
+ // When rendering on the server, we return an absolute URL
+
+ // reference for vercel.com
+ if (process.env.VERCEL_URL) {
+ return `https://${process.env.VERCEL_URL}`;
+ }
+
+ // assume localhost
+ return `http://localhost:${process.env.PORT ?? 3000}`;
+}
diff --git a/src/utils/relativeTime.ts b/src/utils/relativeTime.ts
index f62c0a90..109ebda3 100644
--- a/src/utils/relativeTime.ts
+++ b/src/utils/relativeTime.ts
@@ -1,6 +1,7 @@
import { formatDistanceToNow } from 'date-fns';
-export const getRelativeTime = (date: Date) => {
+export const getRelativeTime = (date: Date | string) => {
+ if (typeof date === 'string') date = new Date(date);
return formatDistanceToNow(date, {
addSuffix: true,
});
diff --git a/tsconfig.json b/tsconfig.json
index 3f1aea75..3b1ec233 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -42,5 +42,5 @@
"scripts/dl-monaco.mjs",
"./prisma/*.ts"
],
- "exclude": ["node_modules"]
+ "exclude": ["node_modules", ".next"]
}