From 5507cf8254948e9620a609559fcfa7c96bcf1775 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Wed, 23 Aug 2023 17:10:41 -0700 Subject: [PATCH] feat: add community filters --- src/lib/components/input/SearchInput.svelte | 21 +++--- .../lemmy/ObjectAutocomplete.svelte | 37 +++++++--- src/routes/modlog/+page.svelte | 37 ++++++++++ src/routes/modlog/+page.ts | 30 +++++++- src/routes/modlog/ModlogAction.svelte | 71 +++++++++++++++++++ src/routes/modlog/ModlogItem.svelte | 15 +--- 6 files changed, 178 insertions(+), 33 deletions(-) create mode 100644 src/routes/modlog/ModlogAction.svelte diff --git a/src/lib/components/input/SearchInput.svelte b/src/lib/components/input/SearchInput.svelte index 4b1dea24..b1cbe3e7 100644 --- a/src/lib/components/input/SearchInput.svelte +++ b/src/lib/components/input/SearchInput.svelte @@ -12,6 +12,7 @@ export let options: T[] export let extractSelected: (item: T | null) => any export let extractName: (item: T) => string + export let showWhenEmpty: boolean = false const debounce = (fn: Function, ms = 300) => { let timeoutId: ReturnType @@ -37,13 +38,17 @@ }} {...$$restProps} /> - - {#each options as option} - - extractSelected(option)}> - {extractName(option)} - - - {/each} + + {#if query == ''} + + {:else} + {#each options as option} + + extractSelected(option)}> + {extractName(option)} + + + {/each} + {/if} diff --git a/src/lib/components/lemmy/ObjectAutocomplete.svelte b/src/lib/components/lemmy/ObjectAutocomplete.svelte index 4d73977f..1b193017 100644 --- a/src/lib/components/lemmy/ObjectAutocomplete.svelte +++ b/src/lib/components/lemmy/ObjectAutocomplete.svelte @@ -5,6 +5,7 @@ import { getClient } from '$lib/lemmy.js' import type { Community, ListingType } from 'lemmy-js-client' import { createEventDispatcher } from 'svelte' + import { Icon, XCircle } from 'svelte-hero-icons' let type: 'community' = 'community' export let q: string = '' @@ -12,6 +13,7 @@ export let jwt: string | undefined = undefined export let listing_type: ListingType = 'Subscribed' export let items: Community[] | undefined = undefined + let showNone: boolean = false const dispatcher = createEventDispatcher<{ select: Community }>() @@ -20,8 +22,11 @@ { + if (q == '') showNone = true + else showNone = false + const results = await getClient().search({ - q: q, + q: q || ' ', auth: jwt, type_: 'Communities', limit: 20, @@ -40,15 +45,27 @@ let:extractName let:extractSelected let:option + showWhenEmpty + {...$$restProps} + let:query > - extractSelected(option)}> - -
- {option.title} - - {new URL(option.actor_id).hostname} - -
-
+ {#if query == ''} + dispatcher('select', undefined)}> + +
+ None +
+
+ {:else if option} + extractSelected(option)}> + +
+ {option.title} + + {new URL(option.actor_id).hostname} + +
+
+ {/if}
{/if} diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index 0d967633..7af93e99 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -5,6 +5,9 @@ import Pageination from '$lib/components/ui/Pageination.svelte' import { searchParam } from '$lib/util.js' import { page } from '$app/stores' + import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte' + import { profile } from '$lib/auth.js' + import MultiSelect from '$lib/components/input/MultiSelect.svelte' export let data @@ -15,6 +18,40 @@

Modlog

+
+ searchParam($page.url, 'type', e.detail, 'page')} + /> +
+
Community
+ + searchParam($page.url, 'community', e.detail?.id.toString(), 'page')} + /> +
+
{#if data.modlog}
{ reason: item.mod_remove_post.reason, link: `/post/${item.post.id}`, } + } else if ('mod_add_community' in item) { + return { + actionName: item.mod_add_community.removed ? 'modRemove' : 'modAdd', + community: item.community, + timestamp: Date.parse(`${item.mod_add_community.when_}Z`), + moderator: item.moderator, + moderatee: item.modded_person, + } } return { @@ -71,12 +93,14 @@ export async function load({ url }) { let community = Number(url.searchParams.get('community')) || undefined let modId = Number(url.searchParams.get('mod_id')) || undefined const page = Number(url.searchParams.get('page')) || 1 + let type: ModlogActionType = + (url.searchParams.get('type') as ModlogActionType) || 'All' const results = await getClient().getModlog({ auth: get(profile)?.jwt, community_id: community, limit: 40, - type_: 'All', + type_: type, page: page, mod_person_id: modId, }) @@ -85,6 +109,7 @@ export async function load({ url }) { ...results.banned_from_community, ...results.removed_comments, ...results.removed_posts, + ...results.added_to_community, ] const moderationActions = moderation @@ -93,6 +118,7 @@ export async function load({ url }) { return { page: page, + type: type, modlog: moderationActions, } } diff --git a/src/routes/modlog/ModlogAction.svelte b/src/routes/modlog/ModlogAction.svelte new file mode 100644 index 00000000..d138f821 --- /dev/null +++ b/src/routes/modlog/ModlogAction.svelte @@ -0,0 +1,71 @@ + + + + + + {actionData.text} + + diff --git a/src/routes/modlog/ModlogItem.svelte b/src/routes/modlog/ModlogItem.svelte index e5372650..539e31af 100644 --- a/src/routes/modlog/ModlogItem.svelte +++ b/src/routes/modlog/ModlogItem.svelte @@ -7,6 +7,7 @@ import RelativeDate from '$lib/components/util/RelativeDate.svelte' import { Icon, Trash, XCircle } from 'svelte-hero-icons' import type { ModLog } from './+page.js' + import ModlogAction from './ModlogAction.svelte' export let item: ModLog @@ -28,19 +29,7 @@ {/if}
- - {#if item.actionName == 'ban'} - - Ban - - {:else if item.actionName == 'postRemoval' || item.actionName == 'commentRemoval'} - - Removal - - {:else} - {item.actionName} - {/if} - + {#if item.moderatee}