Jam themes
This commit is contained in:
parent
63a90cb3a4
commit
191a7b6b67
9 changed files with 102 additions and 8 deletions
|
@ -8,6 +8,7 @@ import { JSONContentTable, JSONJamTable } from "@/lib/mastoauth/realtypes";
|
|||
export function Form({jamID, preset}:{jamID:string, preset:{
|
||||
name: string,
|
||||
description: string,
|
||||
theme: string,
|
||||
date_start: string,
|
||||
date_end: string
|
||||
}}) {
|
||||
|
@ -79,6 +80,19 @@ export function Form({jamID, preset}:{jamID:string, preset:{
|
|||
<p><small>Error: {formik.errors.description}</small></p>
|
||||
</ConditionalNull>
|
||||
</div>
|
||||
<div>
|
||||
<p><label htmlFor="theme">Theme</label></p>
|
||||
<input
|
||||
id="theme"
|
||||
name="theme"
|
||||
type="theme"
|
||||
onChange={formik.handleChange}
|
||||
value={formik.values.theme}
|
||||
/>
|
||||
<ConditionalNull condition={formik.touched.theme != null && formik.errors.theme != null}>
|
||||
<p><small>Error: {formik.errors.theme}</small></p>
|
||||
</ConditionalNull>
|
||||
</div>
|
||||
<div>
|
||||
<p><label htmlFor="date_start">Date Start</label></p>
|
||||
<input
|
||||
|
|
|
@ -43,7 +43,7 @@ export default async function Home({
|
|||
let editingJam = await db
|
||||
.selectFrom('jams')
|
||||
.where('jams.id', '=', jamid)
|
||||
.select(['id','name','description','date_start','date_end'])
|
||||
.selectAll()
|
||||
.executeTakeFirst() as unknown as JSONJamTable;
|
||||
|
||||
if (editingJam == null) return notFound();
|
||||
|
|
|
@ -10,6 +10,7 @@ export function Form() {
|
|||
initialValues: {
|
||||
name: '',
|
||||
description: '',
|
||||
theme: '',
|
||||
date_start: '',
|
||||
date_end: '',
|
||||
},
|
||||
|
@ -77,6 +78,18 @@ export function Form() {
|
|||
<p><small>Error: {formik.errors.description}</small></p>
|
||||
</ConditionalNull>
|
||||
</div>
|
||||
<div>
|
||||
<p><label htmlFor="theme">Theme</label></p>
|
||||
<textarea
|
||||
id="theme"
|
||||
name="theme"
|
||||
onChange={formik.handleChange}
|
||||
value={formik.values.theme}
|
||||
/>
|
||||
<ConditionalNull condition={formik.touched.theme != null && formik.errors.theme != null}>
|
||||
<p><small>Error: {formik.errors.theme}</small></p>
|
||||
</ConditionalNull>
|
||||
</div>
|
||||
<div>
|
||||
<p><label htmlFor="date_start">Date Start</label></p>
|
||||
<input
|
||||
|
|
|
@ -1,8 +1,28 @@
|
|||
import { db, JamTable } from "@/lib/mastoauth/kysely";
|
||||
import { JSONJamTable } from "@/lib/mastoauth/realtypes";
|
||||
import { cookies } from "next/headers";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function GET(request: NextRequest, {params}: {params: {jam: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 id = params.jam;
|
||||
if (id == null) return new Response('', {
|
||||
status: 400
|
||||
|
@ -11,12 +31,16 @@ export async function GET(request: NextRequest, {params}: {params: {jam:string}}
|
|||
.selectFrom('jams')
|
||||
.where('jams.id', '=', id)
|
||||
.selectAll()
|
||||
.executeTakeFirst();
|
||||
.executeTakeFirst() as unknown as JSONJamTable;
|
||||
|
||||
if (jam == null) return new Response('', {
|
||||
status: 404
|
||||
});
|
||||
|
||||
const started = Date.now() >= parseInt(jam.date_start);
|
||||
|
||||
if (!started && !existingUser?.admin && jam.author_id != existingUser?.id) jam.theme = "";
|
||||
|
||||
return Response.json(jam);
|
||||
}
|
||||
|
||||
|
@ -88,6 +112,7 @@ export async function PATCH(request: NextRequest, {params}: {params: {jam:string
|
|||
|
||||
if (body.name != null && typeof body.name === 'string' && body.name.length >= 10 && body.name.length <= 2048) newBody.name = body.name;
|
||||
if (body.description != null && typeof body.description === 'string' && body.description.length >= 10 && body.description.length <= 10000) newBody.description = body.description;
|
||||
if (body.theme != null && typeof body.theme === 'string' && body.theme.length >= 2 && body.theme.length <= 255) newBody.theme = body.theme;
|
||||
if (body.date_start != null && typeof body.date_start === 'number') newBody.date_start = body.date_start;
|
||||
if (body.date_end != null && typeof body.date_end === 'number') newBody.date_end = body.date_end;
|
||||
|
||||
|
|
|
@ -1,9 +1,29 @@
|
|||
import { db, JamTable } from "@/lib/mastoauth/kysely";
|
||||
import { JSONJamTable, JSONUserTable } from "@/lib/mastoauth/realtypes";
|
||||
import { nanoid } from "nanoid";
|
||||
import { cookies } from "next/headers";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const cookieStore = cookies();
|
||||
const token = cookieStore.get('token')?.value;
|
||||
let existingUser:JSONUserTable | undefined;
|
||||
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() as unknown as JSONUserTable;
|
||||
}
|
||||
}
|
||||
|
||||
const until = parseInt(request.nextUrl.searchParams.get("until") || Date.now().toString());
|
||||
let jams = await db
|
||||
.selectFrom('jams')
|
||||
|
@ -11,12 +31,17 @@ export async function GET(request: NextRequest) {
|
|||
.limit(20)
|
||||
.orderBy('jams.created', 'desc')
|
||||
.selectAll()
|
||||
.execute();
|
||||
.execute() as unknown[] as JSONJamTable[];
|
||||
|
||||
if (jams == null) return new Response('', {
|
||||
status: 500
|
||||
});
|
||||
|
||||
jams.forEach((jam) => {
|
||||
const started = Date.now() >= parseInt(jam.date_start);
|
||||
if (!started && !existingUser?.admin && jam.author_id != existingUser?.id) jam.theme = "";
|
||||
})
|
||||
|
||||
return Response.json(jams);
|
||||
}
|
||||
|
||||
|
@ -71,6 +96,7 @@ export async function POST(request: NextRequest) {
|
|||
if (body.author_id != null) te.push("author_id");
|
||||
if (typeof body.name !== 'string' || body.name.length < 10 || body.name.length > 2048) te.push("name");
|
||||
if (typeof body.description !== 'string' || body.description.length < 10 || body.description.length > 10000) te.push("description");
|
||||
if (typeof body.theme !== 'string' || body.theme.length < 2 || body.theme.length > 10000) te.push("theme");
|
||||
if (typeof body.date_start !== 'number') te.push("date_start");
|
||||
if (typeof body.date_end !== 'number') te.push("date_end");
|
||||
if (body.created != null) te.push("created");
|
||||
|
@ -87,6 +113,7 @@ export async function POST(request: NextRequest) {
|
|||
author_id: existingUser.id,
|
||||
name: newBody.name,
|
||||
description: newBody.description,
|
||||
theme: newBody.theme,
|
||||
date_start: newBody.date_start,
|
||||
date_end: newBody.date_end,
|
||||
created: Date.now()
|
||||
|
|
|
@ -52,6 +52,8 @@ export default async function Home({
|
|||
.selectAll()
|
||||
.executeTakeFirst() as unknown as JSONJamTable;
|
||||
|
||||
if (jam == null) return notFound();
|
||||
|
||||
const started = Date.now() >= parseInt(jam.date_start);
|
||||
const ended = Date.now() >= parseInt(jam.date_end);
|
||||
|
||||
|
@ -62,7 +64,7 @@ export default async function Home({
|
|||
.selectAll()
|
||||
.executeTakeFirst() as unknown as JSONUserTable;
|
||||
|
||||
if (jam == null) return notFound();
|
||||
if (!started && !existingUser?.admin && jam.author_id != existingUser?.id) jam.theme = "";
|
||||
|
||||
let content = await db
|
||||
.selectFrom('content')
|
||||
|
@ -95,7 +97,13 @@ export default async function Home({
|
|||
<ConditionalNull condition={existingUser?.admin || jam.author_id == jam.id}><p><b>You have the ability to modify this Jam.</b></p></ConditionalNull>
|
||||
<ConditionalNull condition={existingUser?.admin || jam.author_id == jam.id}><p><a href={`/jams/edit/jam/${jam.id}`}>Edit jam</a></p></ConditionalNull>
|
||||
<ConditionalNull condition={existingUser?.admin || jam.author_id == jam.id}><p><a href={`/jams/delete/jam/${jam.id}`}>Delete jam</a></p></ConditionalNull>
|
||||
<ConditionalNull condition={started && !ended}><p><a href={`/jams/new/content/${jam.id}`}>Submit something</a></p></ConditionalNull>
|
||||
</div>
|
||||
</ConditionalNull>
|
||||
<ConditionalNull condition={jam.theme != ""}>
|
||||
<div style={{textAlign: 'center'}}>
|
||||
<p>The theme is:</p>
|
||||
<h1>{jam.theme}</h1>
|
||||
<ConditionalNull condition={existingUser != null && started && !ended}><p><a href={`/jams/new/content/${jam.id}`}>Submit something</a></p></ConditionalNull>
|
||||
</div>
|
||||
</ConditionalNull>
|
||||
<h1>Submissions</h1>
|
||||
|
|
|
@ -5,7 +5,7 @@ import { ConditionalNull } from "@/components/utility/Conditional";
|
|||
import Link from "next/link";
|
||||
import Markdown from "react-markdown";
|
||||
import rehypeRaw from "rehype-raw";
|
||||
import { JSONJamTable } from "@/lib/mastoauth/realtypes";
|
||||
import { JSONJamTable, JSONUserTable } from "@/lib/mastoauth/realtypes";
|
||||
|
||||
export default async function Home({
|
||||
searchParams
|
||||
|
@ -19,7 +19,7 @@ export default async function Home({
|
|||
|
||||
const cookieStore = cookies();
|
||||
const token = cookieStore.get('token')?.value;
|
||||
let existingUser;
|
||||
let existingUser: JSONUserTable | undefined;
|
||||
if (token != null) {
|
||||
let existingToken = await db
|
||||
.selectFrom('tokens')
|
||||
|
@ -32,7 +32,7 @@ export default async function Home({
|
|||
.selectFrom('users')
|
||||
.where('users.id', '=', existingToken.owner)
|
||||
.selectAll()
|
||||
.executeTakeFirst();
|
||||
.executeTakeFirst() as unknown as JSONUserTable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,11 @@ export default async function Home({
|
|||
.selectAll()
|
||||
.execute() as unknown[] as JSONJamTable[];
|
||||
|
||||
jams.forEach((jam) => {
|
||||
const started = Date.now() >= parseInt(jam.date_start);
|
||||
if (!started && !existingUser?.admin && jam.author_id != existingUser?.id) jam.theme = "";
|
||||
})
|
||||
|
||||
return (
|
||||
<MainLayout currentPage="/jams/" title="Jams" subtitle="">
|
||||
<img className="headerImage" src="/headers/jams.png" alt="JAMS"></img>
|
||||
|
|
|
@ -43,6 +43,7 @@ export interface JamTable {
|
|||
date_start: number;
|
||||
date_end: number;
|
||||
created: number;
|
||||
theme: string;
|
||||
}
|
||||
|
||||
export interface ContentTable {
|
||||
|
|
|
@ -25,6 +25,7 @@ export interface JSONJamTable {
|
|||
date_start: string;
|
||||
date_end: string;
|
||||
created: string;
|
||||
theme: string;
|
||||
}
|
||||
|
||||
export interface JSONContentTable {
|
||||
|
|
Loading…
Reference in a new issue