feat: add community filters
This commit is contained in:
1 parent
693f2f9a08
commit
5507cf8254
6 files changed
+178
-33
No files matched your search
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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}
|
||||
|
||||
Reference in new issue
Block a user