after art class
This commit is contained in:
parent
ab620bdc91
commit
1a1fedfa08
4 changed files with 127 additions and 27 deletions
36
src/app/jams/(manip)/new/content/[jamid]/components/form.tsx
Normal file
36
src/app/jams/(manip)/new/content/[jamid]/components/form.tsx
Normal 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>
|
||||
);
|
||||
}
|
|
@ -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 (
|
||||
<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 (
|
||||
<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>
|
||||
)
|
||||
}
|
|
@ -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
|
||||
});
|
||||
}
|
|
@ -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
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue