after art class

This commit is contained in:
MeowcaTheoRange 2024-04-24 09:40:04 -05:00
parent ab620bdc91
commit 1a1fedfa08
4 changed files with 127 additions and 27 deletions

View file

@ -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 (
<form onSubmit={formik.handleSubmit}>
<label htmlFor="email">Email Address</label>
<input
id="name"
name="name"
type="text"
onChange={formik.handleChange}
value={formik.values.email}
/>
<input
id="name"
name="name"
type="text"
onChange={formik.handleChange}
value={formik.values.email}
/>
<button type="submit">Submit</button>
</form>
);
}

View file

@ -1,19 +1,79 @@
import { Conditional, ConditionalNull } from "@/components/utility/Conditional";
import { MainLayout } from "@/layout/MainLayout/MainLayout"; 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({ export default async function Home({
params, params
searchParams
}: { }: {
params: { params: {
content: string jamid: string
},
searchParams: {
until: 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 (
<MainLayout currentPage="/jams/" title="New Submission" subtitle="Jams" backButton>
<h1>Can't submit to this jam</h1>
<ConditionalNull condition={!started}>
<p>The jam starts at {new Date(parseInt(parentJam.date_start)).toLocaleString('en-us', {
timeZoneName: "long"
})}</p>
</ConditionalNull>
<ConditionalNull condition={ended}>
<p>The jam ended at {new Date(parseInt(parentJam.date_start)).toLocaleString('en-us', {
timeZoneName: "long"
})}</p>
</ConditionalNull>
</MainLayout>
);
if (existingUser == null) return redirect("/jams/");
return ( return (
<MainLayout currentPage="/jams/" title="New Jams" subtitle="Jams" backButton> <MainLayout currentPage="/jams/" title="New Submission" subtitle="Jams" backButton>
<p>Submit something to <b>{parentJam.name}</b></p>
<ConditionalNull condition={existingUser != null}>
<p><small>Logged in as <b>{existingUser?.username}@{existingUser?.instance}</b></small></p>
</ConditionalNull>
<Form />
</MainLayout> </MainLayout>
) )
} }

View file

@ -100,17 +100,19 @@ export async function POST(request: NextRequest, {params}: {params: {content: st
let newBody:JudgementTable = body; let newBody:JudgementTable = body;
let res; let curBody = {
try {
res = await db
.insertInto('judgements')
.values({
id: nanoid(21), id: nanoid(21),
author_id: existingUser.id, author_id: existingUser.id,
content_id: content.id, content_id: content.id,
content: newBody.content, content: newBody.content,
published: Date.now() published: Date.now()
}) };
let res;
try {
res = await db
.insertInto('judgements')
.values(curBody)
.executeTakeFirstOrThrow(); .executeTakeFirstOrThrow();
} catch (err) { } catch (err) {
return new Response('', { return new Response('', {
@ -118,7 +120,7 @@ export async function POST(request: NextRequest, {params}: {params: {content: st
}); });
} }
return new Response(null, { return new Response(curBody.id, {
status: 204 status: 200
}); });
} }

View file

@ -107,11 +107,7 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string
let newBody:ContentTable = body; let newBody:ContentTable = body;
let res; let curBody = {
try {
res = await db
.insertInto('content')
.values({
id: nanoid(21), id: nanoid(21),
author_id: existingUser.id, author_id: existingUser.id,
jam_id: id, jam_id: id,
@ -119,7 +115,13 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string
description: newBody.description, description: newBody.description,
url: newBody.url, url: newBody.url,
submitted: Date.now() submitted: Date.now()
}) };
let res;
try {
res = await db
.insertInto('content')
.values(curBody)
.executeTakeFirstOrThrow(); .executeTakeFirstOrThrow();
} catch (err) { } catch (err) {
return new Response('', { return new Response('', {
@ -127,7 +129,7 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string
}); });
} }
return new Response(null, { return new Response(curBody.id, {
status: 204 status: 200
}) })
} }