feat: improve modlog

This commit is contained in:
Xyphyn committed 2023-10-09 16:37:19 -07:00
1 parent d2b27803b4
commit 979a843b77
4 files changed
+135 -10

No files matched your search

@@ -0,0 +1,61 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import { getClient } from '$lib/lemmy.js'
import type { Community, ListingType, Person } from 'lemmy-js-client'
import { MenuButton, Search } from 'mono-svelte'
import { createEventDispatcher } from 'svelte'
import { Icon, XCircle } from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
export let q: string = ''
export let listing_type: ListingType = 'Subscribed'
export let showWhenEmpty: boolean = false
const dispatcher = createEventDispatcher<{ select: Person | undefined }>()
</script>
<Search
search={async (q) => {
const results = await getClient().search({
q: q || ' ',
type_: 'Users',
limit: 20,
listing_type: listing_type,
sort: 'TopAll',
})
return results.users.map((c) => c.person)
}}
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
on:select
bind:query={q}
{showWhenEmpty}
{...$$restProps}
let:item
let:select
>
<div class="w-full h-full" slot="noresults">
{#if showWhenEmpty}
<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}
<span class="mx-auto my-auto">No results.</span>
{/if}
</div>
<div in:fly|global={{ y: -4, opacity: 0 }}>
<MenuButton on:click={() => select(item)}>
<Avatar url={item.avatar} alt={item.name} width={24} />
<div class="flex flex-col text-left">
<span>{item.name}</span>
<span class="text-xs opacity-80">
{new URL(item.actor_id).hostname}
</span>
</div>
</MenuButton>
</div>
</Search>
+53 -8
View File
@@ -8,7 +8,15 @@
import ModlogItemCard from './item/ModlogItemCard.svelte'
import ModlogItemTable from './item/ModlogItemTable.svelte'
import { Select } from 'mono-svelte'
import { Bars3BottomRight, Icon, ViewColumns } from 'svelte-hero-icons'
import {
Bars3BottomRight,
Icon,
MagnifyingGlass,
ViewColumns,
} from 'svelte-hero-icons'
import UserAutocomplete from '$lib/components/lemmy/user/UserAutocomplete.svelte'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
export let data
@@ -65,13 +73,15 @@
<option value="undefined">Default</option>
</Select>
</div>
<div class="max-w-sm">
<div class="block my-1 font-bold text-sm">Community</div>
<div class="flex flex-col md:flex-row md:items-center gap-2 w-full">
<ObjectAutocomplete
placeholder="Filter by community"
jwt={$profile?.jwt}
listing_type="All"
showWhenEmpty={true}
label="Community"
class="flex-1"
q={$page.url.searchParams.get('community') ? 'Selected' : ''}
on:select={(e) =>
searchParam(
$page.url,
@@ -80,8 +90,37 @@
'page'
)}
/>
<UserAutocomplete
placeholder="Filter by user"
jwt={$profile?.jwt}
listing_type="All"
showWhenEmpty={true}
class="flex-1"
label="User"
q={$page.url.searchParams.get('user') ? 'Selected' : ''}
on:select={(e) =>
searchParam($page.url, 'user', e.detail?.id.toString() ?? '', 'page')}
/>
{#if $profile?.user && isAdmin($profile?.user)}
<UserAutocomplete
placeholder="Filter by moderator"
jwt={$profile?.jwt}
listing_type="All"
showWhenEmpty={true}
class="flex-1"
label="Moderator"
q={$page.url.searchParams.get('mod_id') ? 'Selected' : ''}
on:select={(e) =>
searchParam(
$page.url,
'mod_id',
e.detail?.id.toString() ?? '',
'page'
)}
/>
{/if}
</div>
{#if data.modlog}
{#if data.modlog && data.modlog.length > 0}
{#if $userSettings.modlogCardView ?? !window.matchMedia('(min-width: 1600px)').matches}
<div class="flex flex-col gap-4">
{#each data.modlog as modlog}
@@ -124,11 +163,17 @@
</table>
</div>
{/if}
<Pageination
page={data.page}
on:change={(e) => searchParam($page.url, 'page', e.detail.toString())}
/>
{:else}
<Placeholder
title="No results"
description="There are no mod logs with that filter. Try refining your search."
icon={MagnifyingGlass}
/>
{/if}
<Pageination
page={data.page}
on:change={(e) => searchParam($page.url, 'page', e.detail.toString())}
/>
</div>
<style lang="postcss">
+7 -2
View File
@@ -1,4 +1,5 @@
import { profile } from '$lib/auth.js'
import { publishedToDate } from '$lib/components/util/date.js'
import { getClient } from '$lib/lemmy.js'
import type {
AdminPurgeCommentView,
@@ -37,6 +38,8 @@ export type ActionName =
| 'postFeature'
| 'modAdd'
| 'modRemove'
| 'adminAdd'
| 'adminRemove'
| 'purge'
| 'Unknown'
@@ -69,7 +72,7 @@ export interface ModLog {
const fullUserName = (user: Person) =>
`${user.name}@${new URL(user.actor_id).hostname}`
const timestamp = (when: string) => Date.parse(`${when}Z`)
const timestamp = (when: string) => publishedToDate(when).getTime()
export const _toModLog = (item: ModAction): ModLog => {
if ('mod_ban_from_community' in item) {
@@ -186,7 +189,7 @@ export const _toModLog = (item: ModAction): ModLog => {
}
} else if ('mod_add' in item) {
return {
actionName: item.mod_add.removed ? 'modRemove' : 'modAdd',
actionName: item.mod_add.removed ? 'adminRemove' : 'adminAdd',
timestamp: timestamp(item.mod_add.when_),
moderator: item.moderator,
moderatee: item.modded_person,
@@ -201,6 +204,7 @@ export const _toModLog = (item: ModAction): ModLog => {
export async function load({ url }) {
let community = Number(url.searchParams.get('community')) || undefined
let user = Number(url.searchParams.get('user')) || undefined
let modId = Number(url.searchParams.get('mod_id')) || undefined
const page = Number(url.searchParams.get('page')) || 1
let type: ModlogActionType =
@@ -212,6 +216,7 @@ export async function load({ url }) {
type_: type,
page: page,
mod_person_id: modId,
other_person_id: user,
})
const moderation = [
+14
View File
@@ -129,6 +129,20 @@
text: 'Purge',
}
}
case 'adminAdd': {
return {
icon: UserPlus,
class: 'text-green-600 dark:text-green-400',
text: 'Added Admin',
}
}
case 'adminRemove': {
return {
icon: UserMinus,
class: 'text-red-600 dark:text-red-400',
text: 'Removed Admin',
}
}
}
return {