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

+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,
}
}