From bfc4ef6ffe2c5645af82f4f4d7d98abe535bfdd6 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Mon, 7 Aug 2023 13:22:37 -0700 Subject: [PATCH 1/7] feat: add admin configuration --- package.json | 2 +- src/lib/components/input/Checkbox.svelte | 15 +++ src/lib/components/input/MultiSelect.svelte | 70 ++++++----- src/lib/components/input/SelectMenu.svelte | 31 +++-- src/lib/components/ui/Navbar.svelte | 28 ++++- src/lib/components/ui/menu/Menu.svelte | 11 +- src/lib/components/ui/menu/menu.ts | 7 ++ src/routes/admin/+layout.svelte | 18 +++ src/routes/admin/+layout.ts | 21 ++++ src/routes/admin/+page.svelte | 1 + src/routes/admin/applications/+page.svelte | 0 src/routes/admin/config/+page.svelte | 129 ++++++++++++++++++++ src/routes/admin/config/+page.ts | 5 + src/style/app.css | 2 + 14 files changed, 287 insertions(+), 53 deletions(-) create mode 100644 src/lib/components/input/Checkbox.svelte create mode 100644 src/lib/components/ui/menu/menu.ts create mode 100644 src/routes/admin/+layout.svelte create mode 100644 src/routes/admin/+layout.ts create mode 100644 src/routes/admin/+page.svelte create mode 100644 src/routes/admin/applications/+page.svelte create mode 100644 src/routes/admin/config/+page.svelte create mode 100644 src/routes/admin/config/+page.ts diff --git a/package.json b/package.json index 9989b405..a0846599 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "photon-lemmy", - "version": "0.4.35", + "version": "0.5.0-beta.1", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/lib/components/input/Checkbox.svelte b/src/lib/components/input/Checkbox.svelte new file mode 100644 index 00000000..b0a2d27e --- /dev/null +++ b/src/lib/components/input/Checkbox.svelte @@ -0,0 +1,15 @@ + + + diff --git a/src/lib/components/input/MultiSelect.svelte b/src/lib/components/input/MultiSelect.svelte index 5ea08b39..2d8610cc 100644 --- a/src/lib/components/input/MultiSelect.svelte +++ b/src/lib/components/input/MultiSelect.svelte @@ -1,40 +1,61 @@ -
+
{#each options.slice(0, 4) as option, index} {/each} {#if options.length > 4} @@ -56,14 +77,3 @@ {/if}
- - diff --git a/src/lib/components/input/SelectMenu.svelte b/src/lib/components/input/SelectMenu.svelte index 965f8898..3f37887c 100644 --- a/src/lib/components/input/SelectMenu.svelte +++ b/src/lib/components/input/SelectMenu.svelte @@ -1,25 +1,42 @@ - - +{#if label} +
{label}
+{/if} + +
+ +
{#each options as option, index} - (selected = option)}> + { + selected = option + dispatcher('select', option) + }} + > {optionNames[index] || option} {/each} diff --git a/src/lib/components/ui/Navbar.svelte b/src/lib/components/ui/Navbar.svelte index 9ddec68d..39598043 100644 --- a/src/lib/components/ui/Navbar.svelte +++ b/src/lib/components/ui/Navbar.svelte @@ -3,7 +3,10 @@ import Button from '$lib/components/input/Button.svelte' import Link from '$lib/components/input/Link.svelte' import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte' - import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js' + import { + amModOfAny, + isAdmin, + } from '$lib/components/lemmy/moderation/moderation.js' import Avatar from '$lib/components/ui/Avatar.svelte' import Logo from '$lib/components/ui/Logo.svelte' import Spinner from '$lib/components/ui/loader/Spinner.svelte' @@ -17,6 +20,7 @@ Beaker, Bookmark, Cog6Tooth, + CommandLine, GlobeAlt, Icon, Inbox, @@ -82,10 +86,22 @@
+ {#if $profile?.user && isAdmin($profile.user)} + + {/if} {#if amModOfAny($profile?.user)} {/if} + diff --git a/src/routes/admin/config/+page.ts b/src/routes/admin/config/+page.ts new file mode 100644 index 00000000..02dd8a8a --- /dev/null +++ b/src/routes/admin/config/+page.ts @@ -0,0 +1,5 @@ +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 }) {} diff --git a/src/style/app.css b/src/style/app.css index fc23c5eb..67680ca6 100644 --- a/src/style/app.css +++ b/src/style/app.css @@ -5,11 +5,13 @@ :root { @apply bg-slate-50 dark:bg-zinc-950 text-slate-900 dark:text-zinc-100 !important; + accent-color: #000; } @media (prefers-color-scheme: dark) { :root { color-scheme: dark; + accent-color: #fff; } } From 01b4102c739290f719a6af2e3f2222c66924169d Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Mon, 7 Aug 2023 14:19:46 -0700 Subject: [PATCH 2/7] 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 }) {} From 45f58404988664cba9f9eb009ea6b68d4d02213c Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Mon, 7 Aug 2023 14:47:45 -0700 Subject: [PATCH 3/7] feat: add tagline managing --- src/routes/admin/+layout.svelte | 4 +- src/routes/admin/taglines/+page.svelte | 138 +++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 src/routes/admin/taglines/+page.svelte diff --git a/src/routes/admin/+layout.svelte b/src/routes/admin/+layout.svelte index 6b755a63..41452c3c 100644 --- a/src/routes/admin/+layout.svelte +++ b/src/routes/admin/+layout.svelte @@ -7,8 +7,8 @@
{ goto(e.detail) diff --git a/src/routes/admin/taglines/+page.svelte b/src/routes/admin/taglines/+page.svelte new file mode 100644 index 00000000..0926c585 --- /dev/null +++ b/src/routes/admin/taglines/+page.svelte @@ -0,0 +1,138 @@ + + +{#if taglines.length > 0} +
+

Taglines

+ +
+ { + taglines.splice( + taglines.findIndex((i) => i == e.detail), + 1 + ) + + // hack for reactivity + taglines = taglines + }} + > + {#each taglines as tagline} +
+ + +
+ +
+
+ {/each} +
+
{ + if (newTagline == '' || !data.site) return + + taglines = [...taglines, newTagline] + + newTagline = '' + }} + > + + + + +{:else} +
+ + + No taglines +
+
{ + if (newTagline == '' || !data.site) return + + taglines = [...taglines, newTagline] + + newTagline = '' + }} + > + + + + + + +
+
+
+{/if} From 51344294ff0b0079137867048bbd687ad71e06d9 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Mon, 7 Aug 2023 14:48:04 -0700 Subject: [PATCH 4/7] misc: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a0846599..959fa132 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "photon-lemmy", - "version": "0.5.0-beta.1", + "version": "0.5.0-beta.3", "private": true, "scripts": { "dev": "vite dev", From c922d5e14350c07b9025fd3f8d9da5db5e10ffed Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Mon, 7 Aug 2023 14:56:49 -0700 Subject: [PATCH 5/7] misc: design tweaks --- src/lib/components/ui/Navbar.svelte | 2 +- src/lib/components/ui/Placeholder.svelte | 6 +++--- src/routes/+page.svelte | 10 ++++++---- src/routes/admin/applications/+page.svelte | 2 +- src/routes/admin/taglines/+page.svelte | 2 +- src/routes/inbox/+page.svelte | 17 ++++++++--------- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/lib/components/ui/Navbar.svelte b/src/lib/components/ui/Navbar.svelte index 39598043..0ff2de98 100644 --- a/src/lib/components/ui/Navbar.svelte +++ b/src/lib/components/ui/Navbar.svelte @@ -91,7 +91,7 @@ href="/admin" aria-label="Admin" class="max-md:w-9 max-md:h-8 max-md:!p-0 - hover:text-inherit + dark:text-zinc-300 text-slate-700 hover:text-inherit hover:bg-slate-200 hover:dark:bg-zinc-900 relative" > diff --git a/src/lib/components/ui/Placeholder.svelte b/src/lib/components/ui/Placeholder.svelte index 124b2789..a379a06a 100644 --- a/src/lib/components/ui/Placeholder.svelte +++ b/src/lib/components/ui/Placeholder.svelte @@ -1,12 +1,12 @@
{#if $$slots.title} -

+

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

+

{/if}
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 71f59d37..b86d6b29 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -68,10 +68,12 @@ {/if} - searchParam($page.url, 'page', p.detail.toString())} - /> +
+ searchParam($page.url, 'page', p.detail.toString())} + /> +