diff --git a/src/lib/components/Input/Select.svelte b/src/lib/components/Input/Select.svelte index f3a0ee9..8f3127a 100644 --- a/src/lib/components/Input/Select.svelte +++ b/src/lib/components/Input/Select.svelte @@ -1,5 +1,7 @@
@@ -24,7 +29,8 @@ {/if} diff --git a/src/routes/report/[...url_hash]/+page.server.ts b/src/routes/report/[...url_hash]/+page.server.ts index b7ed125..6ad33c4 100644 --- a/src/routes/report/[...url_hash]/+page.server.ts +++ b/src/routes/report/[...url_hash]/+page.server.ts @@ -23,6 +23,9 @@ export const load: PageServerLoad = async ({ params }) => { }, reported: { name: report.reported?.username || null - } + }, + users: report.draft + ? (await User.findAll({ attributes: ['username'] })).map((u) => u.username) + : null }; }; diff --git a/src/routes/report/[...url_hash]/+page.svelte b/src/routes/report/[...url_hash]/+page.svelte index 20f4915..5e84214 100644 --- a/src/routes/report/[...url_hash]/+page.svelte +++ b/src/routes/report/[...url_hash]/+page.svelte @@ -19,7 +19,8 @@ (data.draft = false)} />
diff --git a/src/routes/report/[...url_hash]/+server.ts b/src/routes/report/[...url_hash]/+server.ts index 963031b..e56721c 100644 --- a/src/routes/report/[...url_hash]/+server.ts +++ b/src/routes/report/[...url_hash]/+server.ts @@ -1,15 +1,23 @@ import type { RequestHandler } from '@sveltejs/kit'; -import { Report } from '$lib/server/database'; +import { Report, User } from '$lib/server/database'; export const POST = (async ({ request, params }) => { const report = await Report.findOne({ where: { url_hash: params.url_hash } }); if (report == null) return new Response(null, { status: 400 }); - const data: { body: string } = await request.json(); + const data: { reported: string | null; subject: string; body: string } = await request.json(); + + const user = + data.reported != null ? await User.findOne({ where: { username: data.reported } }) : undefined; + if (user === null) { + return new Response(null, { status: 400 }); + } report.draft = false; - report.body = data.body || ''; + report.subject = data.subject ?? ''; + report.body = data.body ?? ''; + report.reported_id = user?.id; await report.save(); return new Response(null, { status: 200 }); diff --git a/src/routes/report/[...url_hash]/ReportDraft.svelte b/src/routes/report/[...url_hash]/ReportDraft.svelte index 77257d7..f3f52c4 100644 --- a/src/routes/report/[...url_hash]/ReportDraft.svelte +++ b/src/routes/report/[...url_hash]/ReportDraft.svelte @@ -4,34 +4,78 @@ import { env } from '$env/dynamic/public'; import { page } from '$app/stores'; import { createEventDispatcher } from 'svelte'; + import Search from '$lib/components/Input/Search.svelte'; + import Select from '$lib/components/Input/Select.svelte'; export let reporterName: string; export let reportedName: string | null; export let reason: string; + export let users: string[]; + + let oldReported = reportedName; + $: reportedName = oldReported; let body: string; + let userErrorModal: HTMLDialogElement; + let submitModal: HTMLDialogElement; + + let dispatch = createEventDispatcher(); async function submitReport() { await fetch(`${env.PUBLIC_BASE_PATH}/report/${$page.params.url_hash}`, { method: 'POST', body: JSON.stringify({ + reported: reportedName || null, + subject: reason, body: body }) }); } - let dispatch = createEventDispatcher(); - - let submitModal: HTMLDialogElement; + async function suggestNames(input: string): Promise<{ name: string; value: string }[]> { + let i = 0; + return users + .filter((v) => v.includes(input) && v != reporterName && i++ < 6) + .map((v) => { + return { name: v, value: v }; + }); + }

Report von {reporterName} gegen - {reportedName || 'unbekannt'} + {(reportedName ?? 'unbekannt') || oldReported}

-
submitModal.show()}> + { + if (reportedName != null && users.findIndex((u) => u === reportedName) === -1) { + userErrorModal.show(); + } else { + submitModal.show(); + } + }} + >
+
+ + {#if reportedName !== null} + + {/if} +
Report Grund @@ -52,6 +96,24 @@
+ + + + +