From 4d11ac2382f4e87e9ac4df7a64d25c4defbf74dc Mon Sep 17 00:00:00 2001
From: MeowcaTheoRange
Date: Thu, 25 Apr 2024 16:49:27 -0500
Subject: [PATCH] Fix stuff
---
.../content/[contentid]/components/form.tsx | 15 ++++-
.../(manip)/edit/content/[contentid]/page.tsx | 2 +-
.../edit/judgement/[judgementid]/page.tsx | 2 +-
.../api/content/[content]/judgements/route.ts | 2 +-
src/app/jams/api/content/[content]/route.ts | 3 +
src/app/jams/api/jams/[jam]/content/route.ts | 4 +-
src/app/jams/content/[content]/page.tsx | 3 +
src/app/jams/jam/[jam]/page.tsx | 58 +++++++++++++++++--
src/lib/mastoauth/kysely.ts | 1 +
src/lib/mastoauth/realtypes.ts | 1 +
src/styles/style.css | 18 +++---
11 files changed, 89 insertions(+), 20 deletions(-)
diff --git a/src/app/jams/(manip)/edit/content/[contentid]/components/form.tsx b/src/app/jams/(manip)/edit/content/[contentid]/components/form.tsx
index 6fb6f98..709a647 100644
--- a/src/app/jams/(manip)/edit/content/[contentid]/components/form.tsx
+++ b/src/app/jams/(manip)/edit/content/[contentid]/components/form.tsx
@@ -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}) {
+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:PartialError: {formik.errors.url}
+
diff --git a/src/app/jams/(manip)/edit/content/[contentid]/page.tsx b/src/app/jams/(manip)/edit/content/[contentid]/page.tsx
index 5a75795..8dbf62b 100644
--- a/src/app/jams/(manip)/edit/content/[contentid]/page.tsx
+++ b/src/app/jams/(manip)/edit/content/[contentid]/page.tsx
@@ -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();
diff --git a/src/app/jams/(manip)/edit/judgement/[judgementid]/page.tsx b/src/app/jams/(manip)/edit/judgement/[judgementid]/page.tsx
index d416cc9..bb38b97 100644
--- a/src/app/jams/(manip)/edit/judgement/[judgementid]/page.tsx
+++ b/src/app/jams/(manip)/edit/judgement/[judgementid]/page.tsx
@@ -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();
diff --git a/src/app/jams/api/content/[content]/judgements/route.ts b/src/app/jams/api/content/[content]/judgements/route.ts
index c1b9310..9e63da7 100644
--- a/src/app/jams/api/content/[content]/judgements/route.ts
+++ b/src/app/jams/api/content/[content]/judgements/route.ts
@@ -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");
diff --git a/src/app/jams/api/content/[content]/route.ts b/src/app/jams/api/content/[content]/route.ts
index 44d4067..de69912 100644
--- a/src/app/jams/api/content/[content]/route.ts
+++ b/src/app/jams/api/content/[content]/route.ts
@@ -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 {
diff --git a/src/app/jams/api/jams/[jam]/content/route.ts b/src/app/jams/api/jams/[jam]/content/route.ts
index fa07152..7e6f92e 100644
--- a/src/app/jams/api/jams/[jam]/content/route.ts
+++ b/src/app/jams/api/jams/[jam]/content/route.ts
@@ -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;
diff --git a/src/app/jams/content/[content]/page.tsx b/src/app/jams/content/[content]/page.tsx
index f8ddd61..822030c 100644
--- a/src/app/jams/content/[content]/page.tsx
+++ b/src/app/jams/content/[content]/page.tsx
@@ -93,6 +93,9 @@ export default async function Home({
Submitted by {`${contentOwner.username}@${contentOwner.instance}`} {new Date(parseInt(content.submitted)).toDateString()}
+
+ WINNER!
+
{content.description}
diff --git a/src/app/jams/jam/[jam]/page.tsx b/src/app/jams/jam/[jam]/page.tsx
index 5cb27c2..a8949f7 100644
--- a/src/app/jams/jam/[jam]/page.tsx
+++ b/src/app/jams/jam/[jam]/page.tsx
@@ -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)
@@ -104,12 +112,50 @@ export default async function Home({
Delete jam
-
-
The theme is:
-
{jam.theme || "To be announced"}
-
{jam.theme_description || "Something exciting, maybe?"}
-
Submit something
-
+
+
The theme is:
+
{jam.theme || "To be announced"}
+
{jam.theme_description || "Something exciting, maybe?"}
+
Submit something
+
+
0}>
+ Winners
+ {contentWinners.map(async (content:JSONContentTable) => {
+ let contentOwner = await db
+ .selectFrom('users')
+ .where('users.id', '=', content.author_id)
+ .selectAll()
+ .executeTakeFirst();
+
+ if (contentOwner == null) return An error occured.
;
+
+ 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 ();
+ })}
+
Submissions
{content.map(async (content:JSONContentTable) => {
let contentOwner = await db
diff --git a/src/lib/mastoauth/kysely.ts b/src/lib/mastoauth/kysely.ts
index 126f68a..ed7af2d 100644
--- a/src/lib/mastoauth/kysely.ts
+++ b/src/lib/mastoauth/kysely.ts
@@ -55,6 +55,7 @@ export interface ContentTable {
description: string;
url: string;
submitted: number;
+ winner: boolean;
}
export interface JudgementTable {
diff --git a/src/lib/mastoauth/realtypes.ts b/src/lib/mastoauth/realtypes.ts
index c888f72..73b1ac7 100644
--- a/src/lib/mastoauth/realtypes.ts
+++ b/src/lib/mastoauth/realtypes.ts
@@ -37,6 +37,7 @@ export interface JSONContentTable {
description: string;
url: string;
submitted: string;
+ winner: boolean;
}
export interface JSONJudgementTable {
diff --git a/src/styles/style.css b/src/styles/style.css
index 74708ab..4ab8767 100644
--- a/src/styles/style.css
+++ b/src/styles/style.css
@@ -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%;
}