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 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<typeof setTimeout>
@@ -37,13 +38,17 @@
}}
{...$$restProps}
/>
<Menu open={options.length != 0} alignment="bottom-left">
{#each options as option}
<slot {extractName} {extractSelected} {option}>
<MenuButton on:click={() => extractSelected(option)}>
{extractName(option)}
</MenuButton>
</slot>
{/each}
<Menu open={options.length != 0 || showWhenEmpty} alignment="bottom-left">
{#if query == ''}
<slot {extractName} {extractSelected} {query} />
{:else}
{#each options as option}
<slot {extractName} {extractSelected} {option} {query}>
<MenuButton on:click={() => extractSelected(option)}>
{extractName(option)}
</MenuButton>
</slot>
{/each}
{/if}
</Menu>
</div>
@@ -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 }>()
</script>
@@ -20,8 +22,11 @@
<SearchInput
options={items || []}
on:search={async () => {
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
>
<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 query == ''}
<MenuButton on:click={() => dispatcher('select', undefined)}>
<Icon src={XCircle} size="16" mini />
<div class="flex flex-col text-left">
<span>None</span>
</div>
</MenuButton>
{:else if option}
<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>
{/if}
+37
View File
@@ -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
</script>
@@ -15,6 +18,40 @@
<div class="flex flex-col gap-4">
<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}
<div style="width:100%; overflow-x: auto;">
<table
+28 -2
View File
@@ -2,17 +2,31 @@ import { profile } from '$lib/auth.js'
import { getClient } from '$lib/lemmy.js'
import type {
Community,
ModAddCommunityView,
ModBanFromCommunityView,
ModRemoveCommentView,
ModRemovePostView,
ModlogActionType,
ModlogListParams,
Person,
} from 'lemmy-js-client'
import { get } from 'svelte/store'
export type ActionName =
| 'ban'
| 'postRemoval'
| 'commentRemoval'
| 'postLock'
| 'postFeature'
| 'modAdd'
| 'modRemove'
| 'Unknown'
type ModAction =
| ModBanFromCommunityView
| ModRemoveCommentView
| ModRemovePostView
| ModAddCommunityView
export interface ModLog {
reason?: string
@@ -20,7 +34,7 @@ export interface ModLog {
content?: string
moderator?: Person
community?: Community
actionName: string
actionName: ActionName
timestamp: number
link?: string
}
@@ -59,6 +73,14 @@ export const _toModLog = (item: ModAction): 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,
}
}
+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 { Icon, Trash, XCircle } from 'svelte-hero-icons'
import type { ModLog } from './+page.js'
import ModlogAction from './ModlogAction.svelte'
export let item: ModLog
</script>
@@ -28,19 +29,7 @@
{/if}
</td>
<td>
<span class="font-bold">
{#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>
<ModlogAction action={item.actionName} />
</td>
<td>
{#if item.moderatee}