feat: add community filters

This commit is contained in:
Xyphyn committed 2023-08-23 17:10:41 -07:00
1 parent 693f2f9a08
commit 5507cf8254
6 files changed
+178 -33

No files matched your search

+13 -8
View File
@@ -12,6 +12,7 @@
export let options: T[] export let options: T[]
export let extractSelected: (item: T | null) => any export let extractSelected: (item: T | null) => any
export let extractName: (item: T) => string export let extractName: (item: T) => string
export let showWhenEmpty: boolean = false
const debounce = (fn: Function, ms = 300) => { const debounce = (fn: Function, ms = 300) => {
let timeoutId: ReturnType<typeof setTimeout> let timeoutId: ReturnType<typeof setTimeout>
@@ -37,13 +38,17 @@
}} }}
{...$$restProps} {...$$restProps}
/> />
<Menu open={options.length != 0} alignment="bottom-left"> <Menu open={options.length != 0 || showWhenEmpty} alignment="bottom-left">
{#each options as option} {#if query == ''}
<slot {extractName} {extractSelected} {option}> <slot {extractName} {extractSelected} {query} />
<MenuButton on:click={() => extractSelected(option)}> {:else}
{extractName(option)} {#each options as option}
</MenuButton> <slot {extractName} {extractSelected} {option} {query}>
</slot> <MenuButton on:click={() => extractSelected(option)}>
{/each} {extractName(option)}
</MenuButton>
</slot>
{/each}
{/if}
</Menu> </Menu>
</div> </div>
@@ -5,6 +5,7 @@
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import type { Community, ListingType } from 'lemmy-js-client' import type { Community, ListingType } from 'lemmy-js-client'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import { Icon, XCircle } from 'svelte-hero-icons'
let type: 'community' = 'community' let type: 'community' = 'community'
export let q: string = '' export let q: string = ''
@@ -12,6 +13,7 @@
export let jwt: string | undefined = undefined export let jwt: string | undefined = undefined
export let listing_type: ListingType = 'Subscribed' export let listing_type: ListingType = 'Subscribed'
export let items: Community[] | undefined = undefined export let items: Community[] | undefined = undefined
let showNone: boolean = false
const dispatcher = createEventDispatcher<{ select: Community }>() const dispatcher = createEventDispatcher<{ select: Community }>()
</script> </script>
@@ -20,8 +22,11 @@
<SearchInput <SearchInput
options={items || []} options={items || []}
on:search={async () => { on:search={async () => {
if (q == '') showNone = true
else showNone = false
const results = await getClient().search({ const results = await getClient().search({
q: q, q: q || ' ',
auth: jwt, auth: jwt,
type_: 'Communities', type_: 'Communities',
limit: 20, limit: 20,
@@ -40,15 +45,27 @@
let:extractName let:extractName
let:extractSelected let:extractSelected
let:option let:option
showWhenEmpty
{...$$restProps}
let:query
> >
<MenuButton on:click={() => extractSelected(option)}> {#if query == ''}
<Avatar url={option.icon} alt={option.title} width={24} /> <MenuButton on:click={() => dispatcher('select', undefined)}>
<div class="flex flex-col text-left"> <Icon src={XCircle} size="16" mini />
<span>{option.title}</span> <div class="flex flex-col text-left">
<span class="text-xs opacity-80"> <span>None</span>
{new URL(option.actor_id).hostname} </div>
</span> </MenuButton>
</div> {:else if option}
</MenuButton> <MenuButton on:click={() => extractSelected(option)}>
<Avatar url={option.icon} alt={option.title} width={24} />
<div class="flex flex-col text-left">
<span>{option.title}</span>
<span class="text-xs opacity-80">
{new URL(option.actor_id).hostname}
</span>
</div>
</MenuButton>
{/if}
</SearchInput> </SearchInput>
{/if} {/if}
+37
View File
@@ -5,6 +5,9 @@
import Pageination from '$lib/components/ui/Pageination.svelte' import Pageination from '$lib/components/ui/Pageination.svelte'
import { searchParam } from '$lib/util.js' import { searchParam } from '$lib/util.js'
import { page } from '$app/stores' 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 export let data
</script> </script>
@@ -15,6 +18,40 @@
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<h1 class="font-bold text-2xl">Modlog</h1> <h1 class="font-bold text-2xl">Modlog</h1>
<div class="flex flex-col gap-2">
<MultiSelect
options={[
'All',
'ModRemovePost',
'ModLockPost',
'ModFeaturePost',
'ModRemoveComment',
'ModRemoveCommunity',
'ModBanFromCommunity',
'ModAddCommunity',
'ModTransferCommunity',
'ModAdd',
'ModBan',
'ModHideCommunity',
'AdminPurgePerson',
'AdminPurgeCommunity',
'AdminPurgePost',
'AdminPurgeComment',
]}
selected={data.type}
on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')}
/>
<div class="max-w-sm">
<div class="block my-1 font-bold text-sm">Community</div>
<ObjectAutocomplete
placeholder="Filter by community"
jwt={$profile?.jwt}
listing_type="All"
on:select={(e) =>
searchParam($page.url, 'community', e.detail?.id.toString(), 'page')}
/>
</div>
</div>
{#if data.modlog} {#if data.modlog}
<div style="width:100%; overflow-x: auto;"> <div style="width:100%; overflow-x: auto;">
<table <table
+28 -2
View File
@@ -2,17 +2,31 @@ import { profile } from '$lib/auth.js'
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import type { import type {
Community, Community,
ModAddCommunityView,
ModBanFromCommunityView, ModBanFromCommunityView,
ModRemoveCommentView, ModRemoveCommentView,
ModRemovePostView, ModRemovePostView,
ModlogActionType,
ModlogListParams,
Person, Person,
} from 'lemmy-js-client' } from 'lemmy-js-client'
import { get } from 'svelte/store' import { get } from 'svelte/store'
export type ActionName =
| 'ban'
| 'postRemoval'
| 'commentRemoval'
| 'postLock'
| 'postFeature'
| 'modAdd'
| 'modRemove'
| 'Unknown'
type ModAction = type ModAction =
| ModBanFromCommunityView | ModBanFromCommunityView
| ModRemoveCommentView | ModRemoveCommentView
| ModRemovePostView | ModRemovePostView
| ModAddCommunityView
export interface ModLog { export interface ModLog {
reason?: string reason?: string
@@ -20,7 +34,7 @@ export interface ModLog {
content?: string content?: string
moderator?: Person moderator?: Person
community?: Community community?: Community
actionName: string actionName: ActionName
timestamp: number timestamp: number
link?: string link?: string
} }
@@ -59,6 +73,14 @@ export const _toModLog = (item: ModAction): ModLog => {
reason: item.mod_remove_post.reason, reason: item.mod_remove_post.reason,
link: `/post/${item.post.id}`, 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 { return {
@@ -71,12 +93,14 @@ export async function load({ url }) {
let community = Number(url.searchParams.get('community')) || undefined let community = Number(url.searchParams.get('community')) || undefined
let modId = Number(url.searchParams.get('mod_id')) || undefined let modId = Number(url.searchParams.get('mod_id')) || undefined
const page = Number(url.searchParams.get('page')) || 1 const page = Number(url.searchParams.get('page')) || 1
let type: ModlogActionType =
(url.searchParams.get('type') as ModlogActionType) || 'All'
const results = await getClient().getModlog({ const results = await getClient().getModlog({
auth: get(profile)?.jwt, auth: get(profile)?.jwt,
community_id: community, community_id: community,
limit: 40, limit: 40,
type_: 'All', type_: type,
page: page, page: page,
mod_person_id: modId, mod_person_id: modId,
}) })
@@ -85,6 +109,7 @@ export async function load({ url }) {
...results.banned_from_community, ...results.banned_from_community,
...results.removed_comments, ...results.removed_comments,
...results.removed_posts, ...results.removed_posts,
...results.added_to_community,
] ]
const moderationActions = moderation const moderationActions = moderation
@@ -93,6 +118,7 @@ export async function load({ url }) {
return { return {
page: page, page: page,
type: type,
modlog: moderationActions, modlog: moderationActions,
} }
} }
+71
View File
@@ -0,0 +1,71 @@
<script lang="ts">
import type { IconSource } from 'svelte-hero-icons'
import {
Icon,
QuestionMarkCircle,
Trash,
UserMinus,
UserPlus,
XCircle,
} from 'svelte-hero-icons'
import type { ActionName } from './+page.js'
export let action: ActionName
$: actionData = getAction(action)
const getAction = (
action: ActionName
): { icon: IconSource; text: string; class: string } => {
switch (action) {
case 'ban': {
return {
icon: XCircle,
class: 'text-red-600 dark:text-red-400',
text: 'Ban',
}
}
case 'commentRemoval': {
return {
icon: Trash,
class: 'text-red-600 dark:text-red-400',
text: 'Removal',
}
}
case 'postRemoval': {
return {
icon: Trash,
class: 'text-red-600 dark:text-red-400',
text: 'Removal',
}
}
case 'modAdd': {
return {
icon: UserPlus,
class: 'text-green-600 dark:text-green-400',
text: 'Added Mod',
}
}
case 'modRemove': {
return {
icon: UserMinus,
class: 'text-red-600 dark:text-red-400',
text: 'Removed Mod',
}
}
}
return {
icon: QuestionMarkCircle,
text: 'Unknown',
class: '',
}
}
</script>
<span class="font-bold">
<span class="flex items-center gap-1 {actionData.class}">
<Icon src={actionData.icon} size="16" mini class="inline flex-shrink-0" />
{actionData.text}
</span>
</span>
+2 -13
View File
@@ -7,6 +7,7 @@
import RelativeDate from '$lib/components/util/RelativeDate.svelte' import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import { Icon, Trash, XCircle } from 'svelte-hero-icons' import { Icon, Trash, XCircle } from 'svelte-hero-icons'
import type { ModLog } from './+page.js' import type { ModLog } from './+page.js'
import ModlogAction from './ModlogAction.svelte'
export let item: ModLog export let item: ModLog
</script> </script>
@@ -28,19 +29,7 @@
{/if} {/if}
</td> </td>
<td> <td>
<span class="font-bold"> <ModlogAction action={item.actionName} />
{#if item.actionName == 'ban'}
<span class="flex items-center gap-1 text-red-600 dark:text-red-400">
<Icon src={XCircle} size="16" mini class="inline flex-shrink-0" /> Ban
</span>
{:else if item.actionName == 'postRemoval' || item.actionName == 'commentRemoval'}
<span class="flex items-center gap-1 text-red-600 dark:text-red-400">
<Icon src={Trash} size="16" mini class="inline flex-shrink-0" /> Removal
</span>
{:else}
{item.actionName}
{/if}
</span>
</td> </td>
<td> <td>
{#if item.moderatee} {#if item.moderatee}