From 01b4102c739290f719a6af2e3f2222c66924169d Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Mon, 7 Aug 2023 14:19:46 -0700 Subject: [PATCH] feat: add admin application viewing --- src/lib/components/input/MultiSelect.svelte | 2 +- src/lib/components/ui/Card.svelte | 8 +- src/lib/components/ui/Placeholder.svelte | 6 +- src/lib/components/ui/SectionTitle.svelte | 3 + src/routes/admin/+layout.svelte | 2 +- src/routes/admin/+page.svelte | 2 +- src/routes/admin/+page.ts | 5 + src/routes/admin/applications/+page.svelte | 46 ++++++++ src/routes/admin/applications/+page.ts | 26 +++++ .../admin/applications/Application.svelte | 105 ++++++++++++++++++ src/routes/admin/config/+page.ts | 5 - 11 files changed, 199 insertions(+), 11 deletions(-) create mode 100644 src/lib/components/ui/SectionTitle.svelte create mode 100644 src/routes/admin/+page.ts create mode 100644 src/routes/admin/applications/+page.ts create mode 100644 src/routes/admin/applications/Application.svelte diff --git a/src/lib/components/input/MultiSelect.svelte b/src/lib/components/input/MultiSelect.svelte index 2d8610cc..3f4db050 100644 --- a/src/lib/components/input/MultiSelect.svelte +++ b/src/lib/components/input/MultiSelect.svelte @@ -23,7 +23,7 @@ ? 'pb-1' : 'bg-slate-100 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 rounded-lg p-1' } - gap-2 + gap-1 ${$$props.class} ` diff --git a/src/lib/components/ui/Card.svelte b/src/lib/components/ui/Card.svelte index 6d229dbd..f08c31ad 100644 --- a/src/lib/components/ui/Card.svelte +++ b/src/lib/components/ui/Card.svelte @@ -2,10 +2,14 @@ type CardColor = 'default' | 'warning' | 'error' export let cardColor: CardColor = 'default' + export let elevation: 0 | 1 = 1 + const getColor = (color: CardColor) => { switch (color) { case 'default': - return 'border border-slate-200 dark:border-zinc-800 dark:bg-zinc-900' + return elevation == 0 + ? 'border border-slate-200 dark:border-zinc-900 bg-slate-100 dark:bg-zinc-950' + : 'border border-slate-200 dark:border-zinc-800 bg-white dark:bg-zinc-900' case 'warning': return 'border border-yellow-300 dark:bg-yellow-950/30 dark:border-yellow-900 bg-yellow-50' } @@ -16,7 +20,7 @@
diff --git a/src/lib/components/ui/Placeholder.svelte b/src/lib/components/ui/Placeholder.svelte index 931374c9..124b2789 100644 --- a/src/lib/components/ui/Placeholder.svelte +++ b/src/lib/components/ui/Placeholder.svelte @@ -3,6 +3,10 @@ > {#if $$slots.title} -

{/if} +

+ {/if} + {#if $$slots.description} +

+ {/if}
diff --git a/src/lib/components/ui/SectionTitle.svelte b/src/lib/components/ui/SectionTitle.svelte new file mode 100644 index 00000000..8169bc73 --- /dev/null +++ b/src/lib/components/ui/SectionTitle.svelte @@ -0,0 +1,3 @@ + + + diff --git a/src/routes/admin/+layout.svelte b/src/routes/admin/+layout.svelte index e910dd9b..6b755a63 100644 --- a/src/routes/admin/+layout.svelte +++ b/src/routes/admin/+layout.svelte @@ -4,7 +4,7 @@ import MultiSelect from '$lib/components/input/MultiSelect.svelte' -
+
{ + throw redirect(300, '/admin/config') +} diff --git a/src/routes/admin/applications/+page.svelte b/src/routes/admin/applications/+page.svelte index e69de29b..837e4195 100644 --- a/src/routes/admin/applications/+page.svelte +++ b/src/routes/admin/applications/+page.svelte @@ -0,0 +1,46 @@ + + +

Applications

+ + searchParam($page.url, 'unreadOnly', e.detail.toString(), 'page')} +/> +{#if data.applications && data.applications.length > 0} +
+ {#each data.applications as application (application.registration_application.id)} + + {/each} +
+ {#if data.applications.length >= 40} +
+ searchParam($page.url, 'page', p.detail.toString())} + /> +
+ {/if} +{:else} + + + No applications + You're all caught up for now. + +{/if} diff --git a/src/routes/admin/applications/+page.ts b/src/routes/admin/applications/+page.ts new file mode 100644 index 00000000..95216789 --- /dev/null +++ b/src/routes/admin/applications/+page.ts @@ -0,0 +1,26 @@ +import { profile } from '$lib/auth.js' +import { getClient } from '$lib/lemmy.js' +import { get } from 'svelte/store' + +export async function load({ data, fetch, url }) { + if (!get(profile)) return + + const { jwt } = get(profile)! + if (!jwt) return + + const page = Number(url.searchParams.get('page')) || 1 + const unreadOnly = (url.searchParams.get('unreadOnly') || 'true') == 'true' + + const res = await getClient(undefined, fetch).listRegistrationApplications({ + auth: jwt, + page: page, + limit: 40, + unread_only: unreadOnly, + }) + + return { + unreadOnly: unreadOnly, + page: page, + applications: res.registration_applications, + } +} diff --git a/src/routes/admin/applications/Application.svelte b/src/routes/admin/applications/Application.svelte new file mode 100644 index 00000000..5a6614e6 --- /dev/null +++ b/src/routes/admin/applications/Application.svelte @@ -0,0 +1,105 @@ + + + +
+ User + + + +
+
+ Application +

{application.registration_application.answer}

+
+
+ {#if application.admin} +
+ + {application.creator_local_user.accepted_application + ? 'Approved' + : 'Denied'} by + + +
+
+ {/if} +
+ + +
+
+ diff --git a/src/routes/admin/config/+page.ts b/src/routes/admin/config/+page.ts index 02dd8a8a..e69de29b 100644 --- a/src/routes/admin/config/+page.ts +++ b/src/routes/admin/config/+page.ts @@ -1,5 +0,0 @@ -import { profile } from '$lib/auth.js' -import { getClient, site as siteStore } from '$lib/lemmy.js' -import { get } from 'svelte/store' - -export async function load({ fetch }) {}