Fix stuff

This commit is contained in:
MeowcaTheoRange 2024-04-25 16:49:27 -05:00
parent 7d2e224ecb
commit 4d11ac2382
11 changed files with 89 additions and 20 deletions

View file

@ -5,7 +5,7 @@ import { useRouter } from "next/navigation";
import { ConditionalNull } from "@/components/utility/Conditional";
import { JSONContentTable } from "@/lib/mastoauth/realtypes";
export function Form({contentID, preset}:{contentID:string, preset:Partial<JSONContentTable>}) {
export function Form({contentID, preset}:{contentID:string, preset:JSONContentTable}) {
const router = useRouter();
const formik = useFormik({
initialValues: preset,
@ -77,6 +77,19 @@ export function Form({contentID, preset}:{contentID:string, preset:Partial<JSONC
<p><small>Error: {formik.errors.url}</small></p>
</ConditionalNull>
</div>
<div>
<p><label htmlFor="winner">Winner (Admin property only!)</label></p>
<input
id="winner"
name="winner"
type="checkbox"
onChange={formik.handleChange}
checked={formik.values.winner}
/>
<ConditionalNull condition={formik.touched.winner != null && formik.errors.winner != null}>
<p><small>Error: {formik.errors.winner}</small></p>
</ConditionalNull>
</div>
<br />
<div>
<p><label htmlFor="submit">Done?</label></p>

View file

@ -43,7 +43,7 @@ export default async function Home({
let editingContent = await db
.selectFrom('content')
.where('content.id', '=', contentid)
.select(['id','name','description','url'])
.selectAll()
.executeTakeFirst() as unknown as JSONContentTable;
if (editingContent == null) return notFound();

View file

@ -43,7 +43,7 @@ export default async function Home({
let editingJudgement = await db
.selectFrom('judgements')
.where('judgements.id', '=', judgementid)
.select(['content_id', 'content', 'published'])
.select(['author_id', 'content_id', 'content', 'published'])
.executeTakeFirst() as unknown as JSONJudgementTable;
if (editingJudgement == null) return notFound();

View file

@ -95,7 +95,7 @@ export async function POST(request: NextRequest, {params}: {params: {content: st
if (body.id != null) te.push("id");
if (body.author_id != null) te.push("author_id");
if (body.content_id != null) te.push("content_id");
if (typeof body.content !== 'string' || body.description.length < 10 || body.description.length > 10000) te.push("content");
if (typeof body.content !== 'string' || body.content.length < 10 || body.content.length > 10000) te.push("content");
if (body.published != null) te.push("published");

View file

@ -89,6 +89,9 @@ export async function PATCH(request: NextRequest, {params}: {params: {content:st
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.url != null && typeof body.url === 'string' && body.url.length >= 3 && body.url.length <= 2048) newBody.url = body.url;
if (body.winner != null && typeof body.winner === 'boolean' && existingUser?.admin) newBody.winner = body.winner;
console.log(body, newBody);
let res;
try {

View file

@ -104,6 +104,7 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string
if (typeof body.description !== 'string' || body.description.length < 10 || body.description.length > 10000) te.push("description");
if (typeof body.url !== 'string' || body.url.length < 3 || body.url.length > 2048) te.push("url");
if (body.submitted != null) te.push("submitted");
if (body.winner != null) te.push("winner");
if (te.length > 0) return new Response(JSON.stringify(te, null, 2), {
@ -119,7 +120,8 @@ export async function POST(request: NextRequest, {params}: {params: {jam: string
name: newBody.name,
description: newBody.description,
url: newBody.url,
submitted: Date.now()
submitted: Date.now(),
winner: false
};
let res;

View file

@ -93,6 +93,9 @@ export default async function Home({
<ConditionalNull condition={submittedJam == null}>
<p><small>Submitted by <a href={`/jams/user/${contentOwner.id}`}>{`${contentOwner.username}@${contentOwner.instance}`}</a> {new Date(parseInt(content.submitted)).toDateString()}</small></p>
</ConditionalNull>
<ConditionalNull condition={content.winner}>
<p><small><b>WINNER!</b></small></p>
</ConditionalNull>
<p>{content.description}</p>
<ConditionalNull condition={existingUser != null}>
<div>

View file

@ -69,6 +69,14 @@ export default async function Home({
jam.theme_description = "";
}
let contentWinners = await db
.selectFrom('content')
.where('content.jam_id', '=', jam.id)
.where('content.winner', '=', true)
.orderBy('content.submitted', 'desc')
.selectAll()
.execute() as unknown[] as JSONContentTable[];
let content = await db
.selectFrom('content')
.where('content.jam_id', '=', jam.id)
@ -110,6 +118,44 @@ export default async function Home({
<p>{jam.theme_description || "Something exciting, maybe?"}</p>
<ConditionalNull condition={existingUser != null && started && !ended}><p><a href={`/jams/new/content/${jam.id}`}>Submit something</a></p></ConditionalNull>
</div>
<ConditionalNull condition={contentWinners.length > 0}>
<h1>Winners</h1>
{contentWinners.map(async (content:JSONContentTable) => {
let contentOwner = await db
.selectFrom('users')
.where('users.id', '=', content.author_id)
.selectAll()
.executeTakeFirst();
if (contentOwner == null) return <p>An error occured.</p>;
let allAdmins = await db
.selectFrom('users')
.where('users.admin', '=', true)
.selectAll()
.execute();
let judgementWinner = await db
.selectFrom('judgements')
.where('judgements.author_id', 'in', allAdmins.map(x=>x.id))
.where('judgements.content_id', '=', content.id)
.selectAll()
.executeTakeFirst();
let adminWhoSaid = allAdmins.find(x=> judgementWinner?.author_id == x.id);
return (<div style={{
margin: "16px 0"
}}>
<h2><Link href={`/jams/content/${content.id}`}>{content.name}</Link></h2>
<p><small>by <a href={`/jams/user/${contentOwner.id}`}>{`${contentOwner.username}@${contentOwner.instance}`}</a></small></p>
<ConditionalNull condition={judgementWinner != null && adminWhoSaid != null}>
<p><b>ADMIN</b> <a href={`/jams/user/${adminWhoSaid?.id}`}>{adminWhoSaid?.username}@{adminWhoSaid?.instance}</a> - <i>"{judgementWinner?.content}"</i></p>
</ConditionalNull>
<p></p>
</div>);
})}
</ConditionalNull>
<h1>Submissions</h1>
{content.map(async (content:JSONContentTable) => {
let contentOwner = await db

View file

@ -55,6 +55,7 @@ export interface ContentTable {
description: string;
url: string;
submitted: number;
winner: boolean;
}
export interface JudgementTable {

View file

@ -37,6 +37,7 @@ export interface JSONContentTable {
description: string;
url: string;
submitted: string;
winner: boolean;
}
export interface JSONJudgementTable {

View file

@ -1,14 +1,14 @@
:root {
--accent-color: hsl(24, 40%, 75%);
--bg-0: hsl(24, 20%, 0%);
--bg-1: hsl(24, 20%, 6.25%);
--bg-2: hsl(24, 20%, 12.5%);
--bg-3: hsl(24, 20%, 25%);
--accent-color: hsl(120, 40%, 75%);
--bg-0: hsl(120, 20%, 0%);
--bg-1: hsl(120, 20%, 6.25%);
--bg-2: hsl(120, 20%, 12.5%);
--bg-3: hsl(120, 20%, 25%);
--neutral: #80808080;
--fg-0: hsl(24, 20%, 50%);
--fg-1: hsl(24, 20%, 62.5%);
--fg-2: hsl(24, 20%, 75%);
--fg-3: hsl(24, 20%, 87.5%);
--fg-0: hsl(120, 20%, 50%);
--fg-1: hsl(120, 20%, 62.5%);
--fg-2: hsl(120, 20%, 75%);
--fg-3: hsl(120, 20%, 87.5%);
height: 100%;
}