From 1a1fedfa0881ef6ad56b1bf7d9bcdebcdf9eb453 Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Wed, 24 Apr 2024 09:40:04 -0500 Subject: [PATCH] after art class --- .../new/content/[jamid]/components/form.tsx | 36 +++++++++ .../jams/(manip)/new/content/[jamid]/page.tsx | 74 +++++++++++++++++-- .../api/content/[content]/judgements/route.ts | 20 ++--- src/app/jams/api/jams/[jam]/content/route.ts | 24 +++--- 4 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 src/app/jams/(manip)/new/content/[jamid]/components/form.tsx diff --git a/src/app/jams/(manip)/new/content/[jamid]/components/form.tsx b/src/app/jams/(manip)/new/content/[jamid]/components/form.tsx new file mode 100644 index 0000000..0750f30 --- /dev/null +++ b/src/app/jams/(manip)/new/content/[jamid]/components/form.tsx @@ -0,0 +1,36 @@ +'use client'; +import React from "react"; +import { useFormik } from "formik"; + +export function Form() { + const formik = useFormik({ + initialValues: { + email: '', + }, + onSubmit: values => { + alert(JSON.stringify(values, null, 2)); + }, + }); + + return ( +
+ + + + + +
+ ); +} \ No newline at end of file diff --git a/src/app/jams/(manip)/new/content/[jamid]/page.tsx b/src/app/jams/(manip)/new/content/[jamid]/page.tsx index 193afd5..02ea9f7 100644 --- a/src/app/jams/(manip)/new/content/[jamid]/page.tsx +++ b/src/app/jams/(manip)/new/content/[jamid]/page.tsx @@ -1,19 +1,79 @@ + +import { Conditional, ConditionalNull } from "@/components/utility/Conditional"; import { MainLayout } from "@/layout/MainLayout/MainLayout"; +import { db } from "@/lib/mastoauth/kysely"; +import { JSONJamTable } from "@/lib/mastoauth/realtypes"; +import { cookies } from "next/headers"; +import { notFound, redirect } from "next/navigation"; +import { Form } from "./components/form"; export default async function Home({ - params, - searchParams + params }: { params: { - content: string - }, - searchParams: { - until: string + jamid: string } }) { + const cookieStore = cookies(); + const token = cookieStore.get('token')?.value; + let existingUser; + if (token != null) { + let existingToken = await db + .selectFrom('tokens') + .where('tokens.id', '=', token) + .select('owner') + .executeTakeFirst(); + + if (existingToken != null) { + existingUser = await db + .selectFrom('users') + .where('users.id', '=', existingToken.owner) + .selectAll() + .executeTakeFirst(); + } + } + + const jamid = params.jamid; + + if (jamid == null) return notFound(); + + // It's a JSONJamTable. I don't know why TS hates `number` => `string` conversion. + let parentJam = await db + .selectFrom('jams') + .where('jams.id', '=', jamid) + .selectAll() + .executeTakeFirst() as unknown as JSONJamTable; + + // const started = Date.now() >= parseInt(parentJam.date_start); + // const ended = Date.now() >= parseInt(parentJam.date_end); + const started = true; + const ended = false; + + if (!started || ended) return ( + +

Can't submit to this jam

+ +

The jam starts at {new Date(parseInt(parentJam.date_start)).toLocaleString('en-us', { + timeZoneName: "long" + })}

+
+ +

The jam ended at {new Date(parseInt(parentJam.date_start)).toLocaleString('en-us', { + timeZoneName: "long" + })}

+
+
+ ); + + if (existingUser == null) return redirect("/jams/"); return ( - + +

Submit something to {parentJam.name}

+ +

Logged in as {existingUser?.username}@{existingUser?.instance}

+
+
) } \ No newline at end of file diff --git a/src/app/jams/api/content/[content]/judgements/route.ts b/src/app/jams/api/content/[content]/judgements/route.ts index 5c08547..0bab06b 100644 --- a/src/app/jams/api/content/[content]/judgements/route.ts +++ b/src/app/jams/api/content/[content]/judgements/route.ts @@ -100,17 +100,19 @@ export async function POST(request: NextRequest, {params}: {params: {content: st let newBody:JudgementTable = body; + let curBody = { + id: nanoid(21), + author_id: existingUser.id, + content_id: content.id, + content: newBody.content, + published: Date.now() + }; + let res; try { res = await db .insertInto('judgements') - .values({ - id: nanoid(21), - author_id: existingUser.id, - content_id: content.id, - content: newBody.content, - published: Date.now() - }) + .values(curBody) .executeTakeFirstOrThrow(); } catch (err) { return new Response('', { @@ -118,7 +120,7 @@ export async function POST(request: NextRequest, {params}: {params: {content: st }); } - return new Response(null, { - status: 204 + return new Response(curBody.id, { + status: 200 }); } \ No newline at end of file diff --git a/src/app/jams/api/jams/[jam]/content/route.ts b/src/app/jams/api/jams/[jam]/content/route.ts index ed562e5..00fcd4f 100644 --- a/src/app/jams/api/jams/[jam]/content/route.ts +++ b/src/app/jams/api/jams/[jam]/content/route.ts @@ -107,19 +107,21 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string let newBody:ContentTable = body; + let curBody = { + id: nanoid(21), + author_id: existingUser.id, + jam_id: id, + name: newBody.name, + description: newBody.description, + url: newBody.url, + submitted: Date.now() + }; + let res; try { res = await db .insertInto('content') - .values({ - id: nanoid(21), - author_id: existingUser.id, - jam_id: id, - name: newBody.name, - description: newBody.description, - url: newBody.url, - submitted: Date.now() - }) + .values(curBody) .executeTakeFirstOrThrow(); } catch (err) { return new Response('', { @@ -127,7 +129,7 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string }); } - return new Response(null, { - status: 204 + return new Response(curBody.id, { + status: 200 }) } \ No newline at end of file