Skip to content

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

Challenges route (#147)

bautistaaa38a0f31a7bd2
diff --git a/package.json b/package.json
index 6a34f2b4..5027f1f9 100644
--- a/package.json
+++ b/package.json
@@ -52,7 +52,7 @@
"lodash": "^4.17.21",
"lucide-react": "^0.224.0",
"monaco-vim": "^0.4.0",
- "next": "^13.4.8",
+ "next": "^13.4.9",
"next-auth": "^4.22.1",
"next-themes": "^0.2.1",
"react": "18.2.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b9676fa2..1987cec0 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -15,7 +15,7 @@ patchedDependencies:
dependencies:
'@clerk/nextjs':
specifier: ^4.19.0
'@hookform/resolvers':
specifier: ^3.1.1
version: 3.1.1([email protected])
@@ -81,7 +81,7 @@ dependencies:
version: 10.26.0(@trpc/[email protected])
'@trpc/next':
specifier: ^10.26.0
'@trpc/react-query':
specifier: ^10.26.0
@@ -119,14 +119,14 @@ dependencies:
specifier: ^0.4.0
version: 0.4.0([email protected])
next:
- specifier: ^13.4.8
+ specifier: ^13.4.9
next-auth:
specifier: ^4.22.1
- version: 4.22.1(patch_hash=mr6pbhgbmy4dt4xo4hxm5k4ym4)([email protected])([email protected])([email protected])
+ version: 4.22.1(patch_hash=mr6pbhgbmy4dt4xo4hxm5k4ym4)([email protected])([email protected])([email protected])
next-themes:
specifier: ^0.2.1
react:
specifier: 18.2.0
version: 18.2.0
@@ -294,7 +294,7 @@ packages:
tslib: 2.4.1
dev: false
resolution: {integrity: sha512-k7BUhu2hV924UOf3bzS/3KnNJWONzUQtWxaeJMHnd8AgS2X2j7iP32Sp5aPL5Jg2+n9h2lyI5A5obgbQhLeo5g==}
engines: {node: '>=14'}
peerDependencies:
@@ -306,7 +306,7 @@ packages:
'@clerk/clerk-react': 4.19.0([email protected])
'@clerk/clerk-sdk-node': 4.10.4
'@clerk/types': 3.41.1
path-to-regexp: 6.2.1
react: 18.2.0
react-dom: 18.2.0([email protected])
@@ -694,11 +694,11 @@ packages:
next-auth: ^4
dependencies:
'@prisma/client': 4.14.0([email protected])
- next-auth: 4.22.1(patch_hash=mr6pbhgbmy4dt4xo4hxm5k4ym4)([email protected])([email protected])([email protected])
+ next-auth: 4.22.1(patch_hash=mr6pbhgbmy4dt4xo4hxm5k4ym4)([email protected])([email protected])([email protected])
dev: false
- resolution: {integrity: sha512-twuSf1klb3k9wXI7IZhbZGtFCWvGD4wXTY2rmvzIgVhXhs7ISThrbNyutBx3jWIL8Y/Hk9+woytFz5QsgtcRKQ==}
+ resolution: {integrity: sha512-vuDRK05BOKfmoBYLNi2cujG2jrYbEod/ubSSyqgmEx9n/W3eZaJQdRNhTfumO+qmq/QTzLurW487n/PM/fHOkw==}
dev: false
@@ -707,8 +707,8 @@ packages:
glob: 7.1.7
dev: true
- resolution: {integrity: sha512-MSFplVM4dTWOuKAUv0XR9gY7AWtMSBu9os9f+kp+s5rWhM1I2CdR3obFttd6366nS/W/VZxbPM5oEIdlIa46zA==}
+ resolution: {integrity: sha512-TVzGHpZoVBk3iDsTOQA/R6MGmFp0+17SWXMEWd6zG30AfuELmSSMe2SdPqxwXU0gbpWkJL1KgfLzy5ReN0crqQ==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [darwin]
@@ -716,8 +716,8 @@ packages:
dev: false
optional: true
- resolution: {integrity: sha512-Reox+UXgonon9P0WNDE6w85DGtyBqGitl/ryznOvn6TvfxEaZIpTgeu3ZrJLU9dHSMhiK7YAM793mE/Zii2/Qw==}
+ resolution: {integrity: sha512-aSfF1fhv28N2e7vrDZ6zOQ+IIthocfaxuMWGReB5GDriF0caTqtHttAvzOMgJgXQtQx6XhyaJMozLTSEXeNN+A==}
engines: {node: '>= 10'}
cpu: [x64]
os: [darwin]
@@ -725,8 +725,8 @@ packages:
dev: false
optional: true
- resolution: {integrity: sha512-kdyzYvAYtqQVgzIKNN7e1rLU8aZv86FDSRqPlOkKZlvqudvTO0iohuTPmnEEDlECeBM6qRPShNffotDcU/R2KA==}
+ resolution: {integrity: sha512-JhKoX5ECzYoTVyIy/7KykeO4Z2lVKq7HGQqvAH+Ip9UFn1MOJkOnkPRB7v4nmzqAoY+Je05Aj5wNABR1N18DMg==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
@@ -734,8 +734,8 @@ packages:
dev: false
optional: true
- resolution: {integrity: sha512-oWxx4yRkUGcR81XwbI+T0zhZ3bDF6V1aVLpG+C7hSG50ULpV8gC39UxVO22/bv93ZlcfMY4zl8xkz9Klct6dpQ==}
+ resolution: {integrity: sha512-OOn6zZBIVkm/4j5gkPdGn4yqQt+gmXaLaSjRSO434WplV8vo2YaBNbSHaTM9wJpZTHVDYyjzuIYVEzy9/5RVZw==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
@@ -743,8 +743,8 @@ packages:
dev: false
optional: true
- resolution: {integrity: sha512-anhtvuO6eE9YRhYnaEGTfbpH3L5gT/9qPFcNoi6xS432r/4DAtpJY8kNktqkTVevVIC/pVumqO8tV59PR3zbNg==}
+ resolution: {integrity: sha512-iA+fJXFPpW0SwGmx/pivVU+2t4zQHNOOAr5T378PfxPHY6JtjV6/0s1vlAJUdIHeVpX98CLp9k5VuKgxiRHUpg==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
@@ -752,8 +752,8 @@ packages:
dev: false
optional: true
- resolution: {integrity: sha512-aR+J4wWfNgH1DwCCBNjan7Iumx0lLtn+2/rEYuhIrYLY4vnxqSVGz9u3fXcgUwo6Q9LT8NFkaqK1vPprdq+BXg==}
+ resolution: {integrity: sha512-rlNf2WUtMM+GAQrZ9gMNdSapkVi3koSW3a+dmBVp42lfugWVvnyzca/xJlN48/7AGx8qu62WyO0ya1ikgOxh6A==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
@@ -761,8 +761,8 @@ packages:
dev: false
optional: true
- resolution: {integrity: sha512-OWBKIrJwQBTqrat0xhxEB/jcsjJR3+diD9nc/Y8F1mRdQzsn4bPsomgJyuqPVZs6Lz3K18qdIkvywmfSq75SsQ==}
+ resolution: {integrity: sha512-5T9ybSugXP77nw03vlgKZxD99AFTHaX8eT1ayKYYnGO9nmYhJjRPxcjU5FyYI+TdkQgEpIcH7p/guPLPR0EbKA==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [win32]
@@ -770,8 +770,8 @@ packages:
dev: false
optional: true
- resolution: {integrity: sha512-agiPWGjUndXGTOn4ChbKipQXRA6/UPkywAWIkx7BhgGv48TiJfHTK6MGfBoL9tS6B4mtW39++uy0wFPnfD0JWg==}
+ resolution: {integrity: sha512-ojZTCt1lP2ucgpoiFgrFj07uq4CZsq4crVXpLGgQfoFq00jPKRPgesuGPaz8lg1yLfvafkU3Jd1i8snKwYR3LA==}
engines: {node: '>= 10'}
cpu: [ia32]
os: [win32]
@@ -779,8 +779,8 @@ packages:
dev: false
optional: true
- resolution: {integrity: sha512-UIRKoByVKbuR6SnFG4JM8EMFlJrfEGuUQ1ihxzEleWcNwRMMiVaCj1KyqfTOW8VTQhJ0u8P1Ngg6q1RwnIBTtw==}
+ resolution: {integrity: sha512-QbT03FXRNdpuL+e9pLnu+XajZdm/TtIXVYY4lA9t+9l0fLZbHXDYEKitAqxrOj37o3Vx5ufxiRAniaIebYDCgw==}
engines: {node: '>= 10'}
cpu: [x64]
os: [win32]
@@ -1966,7 +1966,7 @@ packages:
'@trpc/server': 10.26.0
dev: false
resolution: {integrity: sha512-p328crXBH6C228LKxjqbpDEXdLmy4+LdgsZuYK3oFMqaJEmCT22b+zcQ9IvQrcPfDxhKOpJym0QpuDNaWpG2qg==}
peerDependencies:
'@tanstack/react-query': ^4.18.0
@@ -1981,7 +1981,7 @@ packages:
'@trpc/client': 10.26.0(@trpc/[email protected])
'@trpc/react-query': 10.26.0(@tanstack/[email protected])(@trpc/[email protected])(@trpc/[email protected])([email protected])([email protected])
'@trpc/server': 10.26.0
react: 18.2.0
react-dom: 18.2.0([email protected])
react-ssr-prepass: 1.5.0([email protected])
@@ -4933,7 +4933,7 @@ packages:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
dev: true
- /[email protected](patch_hash=mr6pbhgbmy4dt4xo4hxm5k4ym4)([email protected])([email protected])([email protected]):
+ /[email protected](patch_hash=mr6pbhgbmy4dt4xo4hxm5k4ym4)([email protected])([email protected])([email protected]):
resolution: {integrity: sha512-NTR3f6W7/AWXKw8GSsgSyQcDW6jkslZLH8AiZa5PQ09w1kR8uHtR9rez/E9gAq/o17+p0JYHE8QjF3RoniiObA==}
peerDependencies:
next: ^12.2.5 || ^13
@@ -4948,7 +4948,7 @@ packages:
'@panva/hkdf': 1.1.1
cookie: 0.5.0
jose: 4.14.4
oauth: 0.9.15
openid-client: 5.4.2
preact: 10.15.1
@@ -4959,20 +4959,20 @@ packages:
dev: false
patched: true
resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==}
peerDependencies:
next: '*'
react: '*'
react-dom: '*'
dependencies:
react: 18.2.0
react-dom: 18.2.0([email protected])
dev: false
- resolution: {integrity: sha512-lxUjndYKjZHGK3CWeN2RI+/6ni6EUvjiqGWXAYPxUfGIdFGQ5XoisrqAJ/dF74aP27buAfs8MKIbIMMdxjqSBg==}
+ resolution: {integrity: sha512-vtefFm/BWIi/eWOqf1GsmKG3cjKw1k3LjuefKRcL3iiLl3zWzFdPG3as6xtxrGO6gwTzzaO1ktL4oiHt/uvTjA==}
engines: {node: '>=16.8.0'}
hasBin: true
peerDependencies:
@@ -4989,7 +4989,7 @@ packages:
sass:
optional: true
dependencies:
- '@next/env': 13.4.8
+ '@next/env': 13.4.9
'@swc/helpers': 0.5.1
busboy: 1.6.0
caniuse-lite: 1.0.30001497
@@ -5000,15 +5000,15 @@ packages:
watchpack: 2.4.0
zod: 3.21.4
optionalDependencies:
- '@next/swc-darwin-arm64': 13.4.8
- '@next/swc-darwin-x64': 13.4.8
- '@next/swc-linux-arm64-gnu': 13.4.8
- '@next/swc-linux-arm64-musl': 13.4.8
- '@next/swc-linux-x64-gnu': 13.4.8
- '@next/swc-linux-x64-musl': 13.4.8
- '@next/swc-win32-arm64-msvc': 13.4.8
- '@next/swc-win32-ia32-msvc': 13.4.8
- '@next/swc-win32-x64-msvc': 13.4.8
+ '@next/swc-darwin-arm64': 13.4.9
+ '@next/swc-darwin-x64': 13.4.9
+ '@next/swc-linux-arm64-gnu': 13.4.9
+ '@next/swc-linux-arm64-musl': 13.4.9
+ '@next/swc-linux-x64-gnu': 13.4.9
+ '@next/swc-linux-x64-musl': 13.4.9
+ '@next/swc-win32-arm64-msvc': 13.4.9
+ '@next/swc-win32-ia32-msvc': 13.4.9
+ '@next/swc-win32-x64-msvc': 13.4.9
transitivePeerDependencies:
- '@babel/core'
- babel-plugin-macros
diff --git a/src/app/challenge/[id]/comments/loading.tsx b/src/app/challenge/[id]/comments/loading.tsx
new file mode 100644
index 00000000..90c4524f
--- /dev/null
+++ b/src/app/challenge/[id]/comments/loading.tsx
@@ -0,0 +1,3 @@
+export default function Loading() {
+ return 'loading';
+}
diff --git a/src/components/challenge/index.tsx b/src/app/challenge/[id]/comments/page.tsx
similarity index 80%
rename from src/components/challenge/index.tsx
rename to src/app/challenge/[id]/comments/page.tsx
index 702c4b5f..b2e8c000 100644
--- a/src/components/challenge/index.tsx
+++ b/src/app/challenge/[id]/comments/page.tsx
@@ -1,18 +1,17 @@
import { getServerSession, type Session } from 'next-auth';
import { notFound } from 'next/navigation';
+import { LeftPanel } from '~/components/challenge/left-panel';
import { prisma } from '~/server/db';
-import { ChallengeLayout } from './challenge-layout';
-import { DescriptionPanel } from './description-panel';
-import { CodePanel } from './editor';
-
interface Props {
- id: string;
+ params: {
+ id: string;
+ };
}
export type Challenge = Awaited<ReturnType<typeof getChallenge>>;
-export async function Challenge({ id }: Props) {
+export default async function CommentsPage({ params: { id } }: Props) {
const session = await getServerSession();
const challenge = await getChallenge(id, session);
@@ -20,12 +19,7 @@ export async function Challenge({ id }: Props) {
return notFound();
}
- return (
- <ChallengeLayout
- left={<DescriptionPanel challenge={challenge} />}
- right={<CodePanel mode="solve" challenge={challenge} />}
- />
- );
+ return <LeftPanel challenge={challenge} selectedTab={'comments'} />;
}
async function getChallenge(id: string, session: Session | null) {
diff --git a/src/app/challenge/[id]/layout.data.tsx b/src/app/challenge/[id]/layout.data.tsx
new file mode 100644
index 00000000..f5651e61
--- /dev/null
+++ b/src/app/challenge/[id]/layout.data.tsx
@@ -0,0 +1,81 @@
+'use server'
+import { type Session, getServerSession } from 'next-auth';
+import { ChallengeLayout } from '~/components/challenge/challenge-layout';
+import { CodePanel } from '~/components/challenge/editor';
+import { prisma } from '~/server/db';
+
+export async function LayoutData({
+ children,
+ challengeId,
+}: {
+ children: React.ReactNode;
+ challengeId: string;
+}) {
+ const session = await getServerSession();
+ const challenge = await getChallenge(challengeId, session);
+ if (!challenge) return <div>loading</div>;
+ // if on submissions/{id} feed the overlay as right panel
+ // else use editor
+ return (
+ <ChallengeLayout left={children} right={<CodePanel mode="solve" challenge={challenge} />} />
+ );
+}
+
+async function getChallenge(id: string, session: Session | null) {
+ const challenge = await prisma.challenge.findFirst({
+ where: { id: +id },
+ include: {
+ _count: {
+ select: { vote: true },
+ },
+ vote: {
+ where: {
+ userId: session?.user.id,
+ },
+ },
+ bookmark: {
+ where: {
+ 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: {
+ take: 10,
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ include: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ return challenge;
+}
diff --git a/src/app/challenge/[id]/layout.tsx b/src/app/challenge/[id]/layout.tsx
new file mode 100644
index 00000000..f90351af
--- /dev/null
+++ b/src/app/challenge/[id]/layout.tsx
@@ -0,0 +1,77 @@
+import { getServerSession, type Session } from 'next-auth';
+import { ChallengeLayout } from '~/components/challenge/challenge-layout';
+import { prisma } from '~/server/db';
+import { Wrapper } from './wrapper';
+
+export type Challenge = Awaited<ReturnType<typeof getChallenge>>;
+export default async function LayoutData({
+ children,
+ params: { id },
+}: {
+ children: React.ReactNode;
+ params: { id: string };
+}) {
+ const session = await getServerSession();
+ const challenge = await getChallenge(id, session);
+ if (!challenge) return <div>loading</div>;
+ return <ChallengeLayout left={children} right={<Wrapper challenge={challenge} />} />;
+}
+
+async function getChallenge(id: string, session: Session | null) {
+ const challenge = await prisma.challenge.findFirst({
+ where: { id: +id },
+ include: {
+ _count: {
+ select: { vote: true },
+ },
+ vote: {
+ where: {
+ userId: session?.user.id,
+ },
+ },
+ bookmark: {
+ where: {
+ 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: {
+ take: 10,
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ include: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ return challenge;
+}
diff --git a/src/app/challenge/[id]/loading.tsx b/src/app/challenge/[id]/loading.tsx
deleted file mode 100644
index 3144826c..00000000
--- a/src/app/challenge/[id]/loading.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { ChallengeSkeleton } from '~/components/challenge/skeleton';
-
-export default function Loading() {
- return <ChallengeSkeleton />;
-}
diff --git a/src/app/challenge/[id]/page.tsx b/src/app/challenge/[id]/page.tsx
index 1848787c..21bccb94 100644
--- a/src/app/challenge/[id]/page.tsx
+++ b/src/app/challenge/[id]/page.tsx
@@ -1,4 +1,7 @@
-import { Challenge } from '~/components/challenge';
+import { getServerSession, type Session } from 'next-auth';
+import { notFound } from 'next/navigation';
+import { LeftPanel } from '~/components/challenge/left-panel';
+import { prisma } from '~/server/db';
interface Props {
params: {
@@ -6,6 +9,76 @@ interface Props {
};
}
-export default function Page({ params }: Props) {
- return <Challenge id={params.id} />;
+export type Challenge = Awaited<ReturnType<typeof getChallenge>>;
+
+export default async function Challenges({ params: { id } }: Props) {
+ const session = await getServerSession();
+ const challenge = await getChallenge(id, session);
+
+ if (!challenge || typeof challenge.prompt !== 'string') {
+ return notFound();
+ }
+
+ console.log('challenge root');
+
+ return <LeftPanel challenge={challenge} selectedTab={'description'} />;
+}
+
+async function getChallenge(id: string, session: Session | null) {
+ const challenge = await prisma.challenge.findFirst({
+ where: { id: +id },
+ include: {
+ _count: {
+ select: { vote: true },
+ },
+ vote: {
+ where: {
+ userId: session?.user.id,
+ },
+ },
+ bookmark: {
+ where: {
+ 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: {
+ take: 10,
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ include: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ return challenge;
}
diff --git a/src/app/challenge/[id]/solutions/[solutionId]/page.tsx b/src/app/challenge/[id]/solutions/[solutionId]/page.tsx
new file mode 100644
index 00000000..eeba3d58
--- /dev/null
+++ b/src/app/challenge/[id]/solutions/[solutionId]/page.tsx
@@ -0,0 +1,8 @@
+interface Props {
+ params: {
+ solutionId: string;
+ };
+}
+export default function SolutionPage({ params: { solutionId } }: Props) {
+ return <div>Solution Details for Solution {solutionId}</div>;
+}
diff --git a/src/app/challenge/[id]/solutions/loading.tsx b/src/app/challenge/[id]/solutions/loading.tsx
new file mode 100644
index 00000000..90c4524f
--- /dev/null
+++ b/src/app/challenge/[id]/solutions/loading.tsx
@@ -0,0 +1,3 @@
+export default function Loading() {
+ return 'loading';
+}
diff --git a/src/app/challenge/[id]/solutions/page.tsx b/src/app/challenge/[id]/solutions/page.tsx
new file mode 100644
index 00000000..d7cb68a0
--- /dev/null
+++ b/src/app/challenge/[id]/solutions/page.tsx
@@ -0,0 +1,82 @@
+import { getServerSession, type Session } from 'next-auth';
+import { notFound } from 'next/navigation';
+import { LeftPanel } from '~/components/challenge/left-panel';
+import { prisma } from '~/server/db';
+
+interface Props {
+ params: {
+ id: string;
+ };
+}
+
+export type Challenge = Awaited<ReturnType<typeof getChallenge>>;
+
+export default async function SolutionPage({ params: { id } }: Props) {
+ const session = await getServerSession();
+ const challenge = await getChallenge(id, session);
+
+ if (!challenge || typeof challenge.prompt !== 'string') {
+ return notFound();
+ }
+
+ return <LeftPanel challenge={challenge} selectedTab={'solutions'} />;
+}
+
+async function getChallenge(id: string, session: Session | null) {
+ const challenge = await prisma.challenge.findFirst({
+ where: { id: +id },
+ include: {
+ _count: {
+ select: { vote: true },
+ },
+ vote: {
+ where: {
+ userId: session?.user.id,
+ },
+ },
+ bookmark: {
+ where: {
+ 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: {
+ take: 10,
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ include: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ return challenge;
+}
diff --git a/src/app/challenge/[id]/submissions/[submissionId]/page.tsx b/src/app/challenge/[id]/submissions/[submissionId]/page.tsx
new file mode 100644
index 00000000..6665add0
--- /dev/null
+++ b/src/app/challenge/[id]/submissions/[submissionId]/page.tsx
@@ -0,0 +1,82 @@
+import { getServerSession, type Session } from 'next-auth';
+import { notFound } from 'next/navigation';
+import { LeftPanel } from '~/components/challenge/left-panel';
+import { prisma } from '~/server/db';
+
+interface Props {
+ params: {
+ id: string;
+ };
+}
+
+export type Challenge = Awaited<ReturnType<typeof getChallenge>>;
+
+export default async function SubmissionPage({ params: { id } }: Props) {
+ const session = await getServerSession();
+ const challenge = await getChallenge(id, session);
+
+ if (!challenge || typeof challenge.prompt !== 'string') {
+ return notFound();
+ }
+
+ return <LeftPanel challenge={challenge} selectedTab={'submissions'} />;
+}
+
+async function getChallenge(id: string, session: Session | null) {
+ const challenge = await prisma.challenge.findFirst({
+ where: { id: +id },
+ include: {
+ _count: {
+ select: { vote: true },
+ },
+ vote: {
+ where: {
+ userId: session?.user.id,
+ },
+ },
+ bookmark: {
+ where: {
+ 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: {
+ take: 10,
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ include: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ return challenge;
+}
diff --git a/src/app/challenge/[id]/submissions/loading.tsx b/src/app/challenge/[id]/submissions/loading.tsx
new file mode 100644
index 00000000..90c4524f
--- /dev/null
+++ b/src/app/challenge/[id]/submissions/loading.tsx
@@ -0,0 +1,3 @@
+export default function Loading() {
+ return 'loading';
+}
diff --git a/src/app/challenge/[id]/submissions/page.tsx b/src/app/challenge/[id]/submissions/page.tsx
new file mode 100644
index 00000000..6665add0
--- /dev/null
+++ b/src/app/challenge/[id]/submissions/page.tsx
@@ -0,0 +1,82 @@
+import { getServerSession, type Session } from 'next-auth';
+import { notFound } from 'next/navigation';
+import { LeftPanel } from '~/components/challenge/left-panel';
+import { prisma } from '~/server/db';
+
+interface Props {
+ params: {
+ id: string;
+ };
+}
+
+export type Challenge = Awaited<ReturnType<typeof getChallenge>>;
+
+export default async function SubmissionPage({ params: { id } }: Props) {
+ const session = await getServerSession();
+ const challenge = await getChallenge(id, session);
+
+ if (!challenge || typeof challenge.prompt !== 'string') {
+ return notFound();
+ }
+
+ return <LeftPanel challenge={challenge} selectedTab={'submissions'} />;
+}
+
+async function getChallenge(id: string, session: Session | null) {
+ const challenge = await prisma.challenge.findFirst({
+ where: { id: +id },
+ include: {
+ _count: {
+ select: { vote: true },
+ },
+ vote: {
+ where: {
+ userId: session?.user.id,
+ },
+ },
+ bookmark: {
+ where: {
+ 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: {
+ take: 10,
+ orderBy: [
+ {
+ createdAt: 'desc',
+ },
+ ],
+ include: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ return challenge;
+}
diff --git a/src/app/challenge/[id]/wrapper.tsx b/src/app/challenge/[id]/wrapper.tsx
new file mode 100644
index 00000000..5f2e9e39
--- /dev/null
+++ b/src/app/challenge/[id]/wrapper.tsx
@@ -0,0 +1,16 @@
+'use client';
+import { useSelectedLayoutSegments } from 'next/navigation';
+import { CodePanel } from '~/components/challenge/editor';
+import type { Challenge } from './layout';
+
+export function Wrapper({ challenge }: { challenge: Challenge }) {
+ const segments = useSelectedLayoutSegments();
+ if (!challenge) return <div>loading</div>;
+ console.log({ segments });
+ // if on submissions/{id} feed the overlay as right panel
+ // else use editor
+ if (segments[0] === 'submissions' && typeof segments[1] === 'string') {
+ return <div>FUCK YES BABY</div>;
+ }
+ return <CodePanel mode="solve" challenge={challenge} />;
+}
diff --git a/src/app/create/loading.tsx b/src/app/create/loading.tsx
deleted file mode 100644
index f694aa37..00000000
--- a/src/app/create/loading.tsx
+++ /dev/null
@@ -1,2 +0,0 @@
-// TODO actually make a skeleton
-export { default as default } from '../challenge/[id]/loading';
diff --git a/src/components/challenge/comments.tsx b/src/components/challenge/comments.tsx
index f3b47482..717206b4 100644
--- a/src/components/challenge/comments.tsx
+++ b/src/components/challenge/comments.tsx
@@ -1,6 +1,6 @@
import { Button } from '~/components/ui/button';
import Comment from '~/components/ui/comment';
-import type { Challenge } from '.';
+import { type Challenge } from '~/app/challenge/[id]/page';
interface Props {
challenge: NonNullable<Challenge>;
diff --git a/src/components/challenge/description/index.tsx b/src/components/challenge/description/index.tsx
new file mode 100644
index 00000000..e69de29b
diff --git a/src/components/challenge/editor/index.tsx b/src/components/challenge/editor/index.tsx
index 7f5b8530..43fc7a9e 100644
--- a/src/components/challenge/editor/index.tsx
+++ b/src/components/challenge/editor/index.tsx
@@ -19,7 +19,6 @@ import {
import { ToastAction } from '~/components/ui/toast';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '~/components/ui/tooltip';
import { useToast } from '~/components/ui/use-toast';
-import type { Challenge } from '..';
import { saveSubmission } from '../save-submission.action';
import { SettingsForm } from '../settings-form';
import { useEditorSettingsStore } from '../settings-store';
@@ -27,6 +26,7 @@ import { USER_CODE_START, USER_CODE_START_REGEX } from './constants';
import { libSource } from './editor-types';
import { createTwoslashInlayProvider } from './twoslash';
import { VimStatusBar } from './vimMode';
+import { type Challenge } from '~/app/challenge/[id]/page';
loader.config({
paths: {
diff --git a/src/components/challenge/description-panel-skeleton.tsx b/src/components/challenge/left-panel-skeleton.tsx
similarity index 100%
rename from src/components/challenge/description-panel-skeleton.tsx
rename to src/components/challenge/left-panel-skeleton.tsx
diff --git a/src/components/challenge/description-panel.tsx b/src/components/challenge/left-panel.tsx
similarity index 96%
rename from src/components/challenge/description-panel.tsx
rename to src/components/challenge/left-panel.tsx
index cedfd766..ed28337f 100644
--- a/src/components/challenge/description-panel.tsx
+++ b/src/components/challenge/left-panel.tsx
@@ -20,7 +20,6 @@ import {
import { Tabs, TabsContent, TabsList, TabsTrigger } from '~/components/ui/tabs';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '~/components/ui/tooltip';
import { TypographyH3 } from '~/components/ui/typography/h3';
-import type { Challenge } from '.';
import { DifficultyBadge } from '../explore/difficulty-badge';
import { ActionMenu } from '../ui/action-menu';
import { Checkbox } from '../ui/checkbox';
@@ -36,9 +35,12 @@ import { addReport } from './report.action';
import { ShareForm } from './share-form';
import { Solutions } from './solutions';
import { Submissions } from './submissions';
+import Link from 'next/link';
+import { type Challenge } from '~/app/challenge/[id]/layout';
interface Props {
challenge: NonNullable<Challenge>;
+ selectedTab: 'description' | 'submissions' | 'solutions' | 'comments';
}
export type FormValues = {
@@ -48,7 +50,7 @@ export type FormValues = {
other: boolean;
};
-export function DescriptionPanel({ challenge }: Props) {
+export function LeftPanel({ challenge, selectedTab }: Props) {
const router = useRouter();
const [votes, setVotes] = useState(challenge._count.vote);
const [hasVoted, setHasVoted] = useState(challenge.vote.length > 0);
@@ -125,31 +127,31 @@ export function DescriptionPanel({ challenge }: Props) {
return (
<>
- <Tabs defaultValue="description" className="flex h-full w-full flex-col">
+ <Tabs defaultValue={selectedTab} className="flex h-full w-full flex-col">
<TabsList className="sticky top-0 z-10 grid h-auto w-full grid-cols-4 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
+ <Link href={`/challenge/${challenge.id}`}>Description</Link>
</TabsTrigger>
<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
+ <Link href={`/challenge/${challenge.id}/solutions`}>Solutions</Link>
</TabsTrigger>
<TabsTrigger
value="submissions"
className="rounded-md rounded-tr-lg duration-300 data-[state=active]:bg-neutral-200 dark:data-[state=active]:bg-neutral-700"
>
- Submissions
+ <Link href={`/challenge/${challenge.id}/submissions`}>Submissions</Link>
</TabsTrigger>
<TabsTrigger
value="comments"
className="rounded-md rounded-tr-lg duration-300 data-[state=active]:bg-neutral-200 dark:data-[state=active]:bg-neutral-700"
>
- Comments
+ <Link href={`/challenge/${challenge.id}/comments`}>Comments</Link>
</TabsTrigger>
</TabsList>
<TabsContent value="description" className="mt-0 flex-1 dark:bg-muted">
diff --git a/src/components/challenge/report.action.ts b/src/components/challenge/report.action.ts
index 8f4fc0c4..28211a62 100644
--- a/src/components/challenge/report.action.ts
+++ b/src/components/challenge/report.action.ts
@@ -1,7 +1,7 @@
'use server';
import { prisma } from '~/server/db';
-import type { FormValues } from './description-panel';
+import type { FormValues } from './left-panel';
export async function doTheThing() {
await Promise.resolve(0);
diff --git a/src/components/challenge/skeleton.tsx b/src/components/challenge/skeleton.tsx
index 0966c2df..7fe4786a 100644
--- a/src/components/challenge/skeleton.tsx
+++ b/src/components/challenge/skeleton.tsx
@@ -1,7 +1,7 @@
'use client';
import { ChallengeLayout } from './challenge-layout';
-import { DescriptionPanelSkeleton } from './description-panel-skeleton';
+import { DescriptionPanelSkeleton } from './left-panel-skeleton';
export function ChallengeSkeleton() {
return <ChallengeLayout skeleton left={<DescriptionPanelSkeleton />} right={'Loading...'} />;
diff --git a/src/components/challenge/solutions/index.tsx b/src/components/challenge/solutions/index.tsx
index d5961999..f91de8df 100644
--- a/src/components/challenge/solutions/index.tsx
+++ b/src/components/challenge/solutions/index.tsx
@@ -3,11 +3,10 @@ import { ArrowUp, MessageCircle, Plus } from 'lucide-react';
import { Button } from '~/components/ui/button';
-import type { Challenge } from '..';
import { SolutionEditor } from './solution-editor';
import { useState } from 'react';
-import { SharedSolution } from '@prisma/client';
import { getRelativeTime } from '~/utils/relativeTime';
+import { type Challenge } from '~/app/challenge/[id]/page';
interface Props {
challenge: NonNullable<Challenge>;
@@ -60,7 +59,6 @@ function SolutionRow({
}: {
solution: NonNullable<NonNullable<Challenge>['sharedSolution'][0]>;
}) {
- const date = new Date();
return (
<div className="group 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">{solution.title}</h3>
diff --git a/src/components/challenge/solutions/solution-editor.tsx b/src/components/challenge/solutions/solution-editor.tsx
index c1fa2254..93cf9ca6 100644
--- a/src/components/challenge/solutions/solution-editor.tsx
+++ b/src/components/challenge/solutions/solution-editor.tsx
@@ -7,7 +7,7 @@ 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 { Challenge } from '..';
+import { type Challenge } from '~/app/challenge/[id]/layout';
import { useSession } from 'next-auth/react';
import { useTheme } from 'next-themes';
import { useRouter } from 'next/navigation';
diff --git a/src/components/challenge/submissions.tsx b/src/components/challenge/submissions.tsx
index affcea45..9db4a927 100644
--- a/src/components/challenge/submissions.tsx
+++ b/src/components/challenge/submissions.tsx
@@ -1,7 +1,7 @@
'use client';
import type { Solution } from '@prisma/client';
-import type { Challenge } from '.';
+import { type Challenge } from '~/app/challenge/[id]/layout';
import { getRelativeTime } from '~/utils/relativeTime';
import clsx from 'clsx';
import {
diff --git a/src/components/user/dashboard/index.tsx b/src/components/user/dashboard/index.tsx
index 788fc616..acffff44 100644
--- a/src/components/user/dashboard/index.tsx
+++ b/src/components/user/dashboard/index.tsx
@@ -4,7 +4,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '~/components/ui/tabs';
import { Overview } from '../dashboard/overview';
import { InProgressTab } from '../dashboard/in-progress-tab';
import { SolutionsTab } from '../dashboard/solutions-tab';
-import { User } from '@prisma/client';
+import type { User } from '@prisma/client';
import { getRelativeTime } from '~/utils/relativeTime';
import { prisma } from '~/server/db';
diff --git a/src/components/user/dashboard/solutions-tab.tsx b/src/components/user/dashboard/solutions-tab.tsx
index 7701f909..bc1de0df 100644
--- a/src/components/user/dashboard/solutions-tab.tsx
+++ b/src/components/user/dashboard/solutions-tab.tsx
@@ -7,7 +7,7 @@ import {
TableHeader,
TableRow,
} from '~/components/ui/table';
-import { UserData } from '.';
+import type { UserData } from '.';
import Link from 'next/link';
export function SolutionsTab({ solutions = [] }: { solutions: UserData['solution'] }) {
diff --git a/src/components/user/profile.tsx b/src/components/user/profile.tsx
index 2fdd376d..53010023 100644
--- a/src/components/user/profile.tsx
+++ b/src/components/user/profile.tsx
@@ -1,7 +1,7 @@
import { notFound } from 'next/navigation';
import { prisma } from '~/server/db';
import Dashboard from './dashboard';
-import { Metadata } from 'next';
+import type { Metadata } from 'next';
interface Props {
username: string;
diff --git a/src/server/auth.ts b/src/server/auth.ts
index 62f81475..6f699e2e 100644
--- a/src/server/auth.ts
+++ b/src/server/auth.ts
@@ -2,7 +2,7 @@ import { PrismaAdapter } from '@next-auth/prisma-adapter';
import type { Role, RoleTypes } from '@prisma/client';
import { type GetServerSidePropsContext } from 'next';
import { getServerSession, type DefaultSession, type NextAuthOptions } from 'next-auth';
-import GitHubProvider, { GithubProfile } from 'next-auth/providers/github';
+import GitHubProvider from 'next-auth/providers/github';
import { env } from '~/env.mjs';
import { prisma } from '~/server/db';
diff --git a/src/utils/featureFlags.ts b/src/utils/featureFlags.ts
index c9955472..753a8c37 100644
--- a/src/utils/featureFlags.ts
+++ b/src/utils/featureFlags.ts
@@ -1,20 +1,3 @@
-import { createClient } from '@vercel/edge-config';
-import { env } from '../env.mjs';
-
-interface FeatureFlags {
- // The mode the site is running in
- mode: 'marketing' | 'production';
-}
-
-// We use prefixes to avoid mixing up the flags with other Edge Config values
-const prefixKey = (key: string) => `ff_${key}`;
-// export async function get(key: keyof FeatureFlags) {
-// const prefixedKey = prefixKey(key);
-// const edgeConfig = createClient(env.EDGE_CONFIG);
-// const featureFlag = await edgeConfig.get<FeatureFlags>(prefixedKey);
-// return featureFlag;
-// }
-
// For now we use this since it is a simp build time thingy
export function isProd() {
return process.env.NODE_ENV === 'production';