Connect, collaborate, and grow with a community of TypeScript developers
Submission overview (#184)
bautistaaa993567eff6f9
diff --git a/src/app/challenge/[id]/wrapper.tsx b/src/app/challenge/[id]/wrapper.tsxindex ff5c46d6..f294ca4d 100644--- a/src/app/challenge/[id]/wrapper.tsx+++ b/src/app/challenge/[id]/wrapper.tsx@@ -2,15 +2,13 @@import { useSelectedLayoutSegments } from 'next/navigation';import { CodePanel } from '~/components/challenge/editor';import { type ChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';+import { SubmissionOverview } from '~/components/challenge/submissions/overview';export function Wrapper({ challenge }: { challenge: ChallengeRouteData }) {const segments = useSelectedLayoutSegments();if (!challenge) return <div>loading</div>;- console.log({ segments });- // if on submissions/{id} feed the overlay as right panel- // else use editorif (segments[0] === 'submissions' && typeof segments[1] === 'string') {- return <div>FUCK YES BABY</div>;+ return <SubmissionOverview challenge={challenge} submissionId={segments[1]} />;}return <CodePanel mode="solve" challenge={challenge} />;}diff --git a/src/app/page.tsx b/src/app/page.tsxindex bf7d88c7..2ea073a5 100644--- a/src/app/page.tsx+++ b/src/app/page.tsx@@ -22,9 +22,11 @@ export default function Index() {</h1><p className="font-bold">πͺ Challenge π§ Learn π Excel</p>- <p className="max-w-[40ch] text-center text-neutral-400 dark:text-neutral-600">- Unlock the power of strong typing and seamless JavaScript integration on our immersive- learning platform designed for developers of all levels+ <p className="max-w-[80ch] bg-transparent text-center text-neutral-600 dark:text-neutral-400">+ Connect and collaborate with a community of TypeScript developers on Type Hero. Engage in+ discussions, create challenges, and share insights with fellow typescript enthusiasts.+ Type Hero has collaborative coding challenges that foster a supportive and inspiring+ environment, where you can learn from others and showcase your expertise.</p></div><Footsies />diff --git a/src/components/challenge/comments/index.tsx b/src/components/challenge/comments/index.tsxindex a6486b96..4d4f21da 100644--- a/src/components/challenge/comments/index.tsx+++ b/src/components/challenge/comments/index.tsx@@ -34,7 +34,6 @@ const Comments = ({ challenge }: Props) => {async function createChallengeComment() {try {const res = await addChallengeComment(challenge.id, text);- console.log(challenge.id, text);if (res === 'text_is_empty') {toast({title: 'Empty Comment',diff --git a/src/components/challenge/editor/index.tsx b/src/components/challenge/editor/index.tsxindex 2b92a8ca..7c102991 100644--- a/src/components/challenge/editor/index.tsx+++ b/src/components/challenge/editor/index.tsx@@ -82,8 +82,6 @@ type TsErrors = [CompilerOptionsDiagnostics: monaco.languages.typescript.Diagnostic[],];-const libCache = new Set<string>();-export const CodePanel = (props: Props) => {const router = useRouter();const { toast } = useToast();@@ -93,7 +91,6 @@ export const CodePanel = (props: Props) => {const [tsErrors, setTsErrors] = useState<TsErrors>([[], [], [], []]);const [initialTypecheckDone, setInitialTypecheckDone] = useState(false);- // Prisma.JsonValueconst defaultCode = useMemo(() => {if (props.mode !== 'solve') return props.prompt ?? '';@@ -132,7 +129,6 @@ export const CodePanel = (props: Props) => {props.mode === 'solve'? async () => {const [, solution] = code.split(USER_CODE_START);-const hasErrors = tsErrors.some((e) => e.length);await saveSubmission(@@ -213,12 +209,9 @@ export const CodePanel = (props: Props) => {.split('\n').findIndex((line) => line.includes(USER_CODE_START));- // once you register a lib you cant unregister it (idk how to unregister it)- // so when editor mounts again it tries to add the lib again and throws an error- if (!libCache.has(libSource)) {+ if (!monaco.editor.getModel(monaco.Uri.parse(LIB_URI))) {monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, LIB_URI);monaco.editor.createModel(libSource, 'typescript', monaco.Uri.parse(LIB_URI));- libCache.add(libSource);}const model = editor.getModel();diff --git a/src/components/challenge/submissions.tsx b/src/components/challenge/submissions/index.tsxsimilarity index 74%rename from src/components/challenge/submissions.tsxrename to src/components/challenge/submissions/index.tsxindex 874d0c69..dbddc0a2 100644--- a/src/components/challenge/submissions.tsx+++ b/src/components/challenge/submissions/index.tsx@@ -6,6 +6,7 @@ import { getRelativeTime } from '~/utils/relativeTime';import clsx from 'clsx';import { useMemo, useState } from 'react';+import Link from 'next/link';interface Props {challenge: ChallengeRouteData;@@ -62,7 +63,9 @@ export function Submissions({ challenge }: Props) {<ul className="relative flex flex-col">{filteredSubmissions.map((submission) => {- return <SubmissionRow submission={submission} key={submission.id} />;+ return (+ <SubmissionRow challengeId={challenge.id} submission={submission} key={submission.id} />+ );})}</ul></>@@ -70,24 +73,20 @@ export function Submissions({ challenge }: Props) {}// eslint-disable-next-line @typescript-eslint/no-unused-vars-function SubmissionRow({ submission }: { submission: Solution }) {- const handleClick = () => {- console.log('navigate to some route and overlay submission on top of editor');- };+function SubmissionRow({ challengeId, submission }: { challengeId: number; submission: Solution }) {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"- onClick={handleClick}- >- <div- className={clsx({- 'text-emerald-600 dark:text-emerald-400': submission.isSuccessful,- 'text-rose-600 dark:text-rose-400': !submission.isSuccessful,- })}- >- {submission.isSuccessful ? 'Accepted' : 'Rejected'}- </div>- <div className="text-sm text-neutral-500">{getRelativeTime(submission.createdAt)}</div>+ <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}`}>+ <div+ className={clsx({+ 'text-emerald-600 dark:text-emerald-400': submission.isSuccessful,+ 'text-rose-600 dark:text-rose-400': !submission.isSuccessful,+ })}+ >+ {submission.isSuccessful ? 'Accepted' : 'Rejected'}+ </div>+ <div className="text-sm text-neutral-500">{getRelativeTime(submission.createdAt)}</div>+ </Link></li>);}diff --git a/src/components/challenge/submissions/overview.tsx b/src/components/challenge/submissions/overview.tsxnew file mode 100644index 00000000..a3ff8b91--- /dev/null+++ b/src/components/challenge/submissions/overview.tsx@@ -0,0 +1,71 @@+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 { 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);+ const code = codifyForMarkdown(submission?.code.trimStart() ?? '');++ const copyToClipboard = async () => {+ if (navigator.clipboard) {+ await navigator.clipboard.writeText(submission?.code ?? '').catch(console.error);+ toast({+ variant: 'success',+ description: 'Copied!',+ });+ }+ };++ if (!submission) return null;++ 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`}>+ <X size={20} className="stroke-gray-500 hover:stroke-gray-400" />+ </Link>+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button variant="ghost" onClick={copyToClipboard}>+ <Copy size={20} className="stroke-gray-500 hover:stroke-gray-400" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>+ <p>Copy</p>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </div>+ <div className="p-2">+ <div className="mb-5">+ <div+ className={`inline-block rounded-xl px-4 py-1 ${+ submission.isSuccessful+ ? 'bg-emerald-600/10 text-emerald-600 dark:bg-emerald-400/10 dark:text-emerald-400 '+ : 'bg-rose-600/10 text-rose-600 dark:bg-rose-400/10 dark:text-rose-400 '+ }`}+ >+ {submission?.isSuccessful ? 'Accepted' : 'Rejected'}+ </div>+ <div className="text-sm text-neutral-500">{getRelativeTime(submission.createdAt)}</div>+ </div>+ <Markdown>{code}</Markdown>+ </div>+ </>+ );+}diff --git a/src/server/auth.ts b/src/server/auth.tsindex 7a0fa822..077db316 100644--- a/src/server/auth.ts+++ b/src/server/auth.ts@@ -79,7 +79,6 @@ export const authOptions: NextAuthOptions = {};},},- secret: env.NEXTAUTH_SECRET,adapter: PrismaAdapter(prisma),providers: [GitHubProvider({