impr: add more options to moderation page (#604)

* feat: allow filtering by community on modpage

* feat: add arbitrary banning

* temp

* feat: combine reports on reports page

* design: clarify report design

* fix: update lang key for navbar moderation
This commit is contained in:
Xylight authored and GitHub committed 2025-07-06 22:43:26 +00:00
1 parent 5b8f9d15af
commit 412977a484
16 files changed
+621 -190

No files matched your search

@@ -25,10 +25,11 @@
Newspaper,
NoSymbol,
Plus,
ShieldCheck,
} from 'svelte-hero-icons'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import ItemList from '../generic/ItemList.svelte'
import { isAdmin } from '../moderation/moderation'
import { amMod, isAdmin } from '../moderation/moderation'
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
interface Props {
@@ -37,6 +38,7 @@
counts?: CommunityAggregates | undefined
moderators?: CommunityModeratorView[]
blocked?: boolean
banner?: boolean
class?: string
}
@@ -46,12 +48,13 @@
counts = undefined,
moderators = [],
blocked = false,
banner = !(settings.nsfwBlur && community.nsfw),
class: clazz = '',
}: Props = $props()
</script>
<EntityHeader
banner={settings.nsfwBlur && community.nsfw ? undefined : community.banner}
banner={banner ? community.banner : undefined}
avatar={community.icon}
name={community.title}
url="/c/{fullCommunityName(community.name, community.actor_id)}"
@@ -178,6 +181,15 @@
<Icon src={Newspaper} size="16" mini />
{$t('cards.community.modlog')}
</MenuButton>
{#if profile.data.user && amMod(profile.data.user, community)}
<MenuButton
color="success-subtle"
href="/moderation?community={community.id}"
>
<Icon src={ShieldCheck} size="16" micro />
{$t('routes.moderation.feed')}
</MenuButton>
{/if}
{#if profile.data?.jwt}
<MenuButton
color="danger-subtle"
@@ -21,6 +21,7 @@
} from 'svelte-hero-icons'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import { settings } from '$lib/settings.svelte'
import type { Snippet } from 'svelte'
let showInfo = $state(false)
interface Props {
@@ -29,6 +30,7 @@
showCounts?: boolean
class?: string
icon?: import('svelte').Snippet
children?: Snippet
}
let {
@@ -37,6 +39,7 @@
showCounts = true,
class: clazz = 'py-4 flex flex-col gap-4 text-sm max-w-full relative',
icon,
children,
}: Props = $props()
</script>
@@ -137,66 +140,70 @@
</div>
</div>
</a>
<div class="flex flex-row items-center gap-2">
<Button
size="square-md"
rounding="pill"
color="ghost"
onclick={() => (showInfo = !showInfo)}
>
<Icon src={InformationCircle} size="16" mini />
</Button>
<Subscribe {community}>
{#snippet children({ subscribe, subscribing })}
<Button
disabled={subscribing || !profile.data?.jwt}
loading={subscribing}
onclick={async () => {
const res = await subscribe()
{#if children}
{@render children?.()}
{:else}
<div class="flex flex-row items-center gap-2">
<Button
size="square-md"
rounding="pill"
color="ghost"
onclick={() => (showInfo = !showInfo)}
>
<Icon src={InformationCircle} size="16" mini />
</Button>
<Subscribe {community}>
{#snippet children({ subscribe, subscribing })}
<Button
disabled={subscribing || !profile.data?.jwt}
loading={subscribing}
onclick={async () => {
const res = await subscribe()
if (res) {
const newSubscribed =
res.community_view.subscribed != 'NotSubscribed'
? 'Subscribed'
: 'NotSubscribed'
if (res) {
const newSubscribed =
res.community_view.subscribed != 'NotSubscribed'
? 'Subscribed'
: 'NotSubscribed'
community.subscribed = newSubscribed
addSubscription(
community.community,
newSubscribed == 'Subscribed',
)
}
}}
size="custom"
title={isSubscribed(community.subscribed)
? $t('cards.community.subscribed')
: $t('cards.community.subscribe')}
color={isSubscribed(community.subscribed)
? 'elevatedLow'
: 'primary'}
class="{isSubscribed(community.subscribed)
? 'text-slate-600 dark:text-zinc-400'
: ''}
community.subscribed = newSubscribed
addSubscription(
community.community,
newSubscribed == 'Subscribed',
)
}
}}
size="custom"
title={isSubscribed(community.subscribed)
? $t('cards.community.subscribed')
: $t('cards.community.subscribe')}
color={isSubscribed(community.subscribed)
? 'elevatedLow'
: 'primary'}
class="{isSubscribed(community.subscribed)
? 'text-slate-600 dark:text-zinc-400'
: ''}
aspect-square h-8.5 @md:px-2 @md:min-w-30 @md:aspect-auto @md:rounded-full"
>
{#snippet prefix()}
<Icon
src={isSubscribed(community.subscribed) ? Check : Plus}
size="16"
micro
/>
{/snippet}
<span class="hidden @md:block">
{#if isSubscribed(community.subscribed)}
{$t('cards.community.subscribed')}
{:else}
{$t('cards.community.subscribe')}
{/if}
</span>
</Button>
{/snippet}
</Subscribe>
</div>
>
{#snippet prefix()}
<Icon
src={isSubscribed(community.subscribed) ? Check : Plus}
size="16"
micro
/>
{/snippet}
<span class="hidden @md:block">
{#if isSubscribed(community.subscribed)}
{$t('cards.community.subscribed')}
{:else}
{$t('cards.community.subscribe')}
{/if}
</span>
</Button>
{/snippet}
</Subscribe>
</div>
{/if}
</div>
{#if showCounts}
<div class="flex flex-row gap-3 items-center justify-center">
+1 -1
View File
@@ -138,7 +138,7 @@
</MenuButton>
{#if amModOfAny(profile.data.user)}
<MenuButton href="/moderation" icon={ShieldCheck}>
{$t('routes.moderation.reports')}
{$t('routes.moderation.feed')}
{#snippet suffix()}
{@render notifBadge($notifications.reports)}
{/snippet}
@@ -11,6 +11,7 @@
import { Home, Icon, MagnifyingGlass } from 'svelte-hero-icons'
import { getGroups, type Action, type Group } from './actions.svelte'
import CommandItem from './CommandItem.svelte'
import { fuzzySearch } from '$lib/util.svelte'
interface Props {
open?: boolean
@@ -37,38 +38,6 @@
let breadcrumbs: Action[] = $state([])
let input = $state<HTMLInputElement>()
function fuzzySearch(text: string, pattern: string): number {
const textLower = text.toLowerCase()
const patternLower = pattern.toLowerCase()
let score = 0
let lastIndex = -1
let consecutiveBonus = 0
for (let i = 0; i < patternLower.length; i++) {
const index = textLower.indexOf(patternLower[i], lastIndex + 1)
if (index === -1) return 0
score += 1
if (index === lastIndex + 1) {
consecutiveBonus++
score += consecutiveBonus
} else {
consecutiveBonus = 0
}
lastIndex = index
}
// Bonus for matching start of words
if (textLower.startsWith(patternLower)) {
score += 2
} else if (textLower.includes(' ' + patternLower)) {
score += 1
}
return score
}
const debounce = (fn: Function, ms = 300) => {
let timeoutId: ReturnType<typeof setTimeout>
// eslint-disable-next-line
+7 -1
View File
@@ -333,7 +333,13 @@
"resolvedBy": "Resolved by",
"markAll": "Mark page resolved",
"markAllComplete": "Batch action completed.",
"reports": "Reports"
"feed": "Reports",
"manage": {
"title": "Manage",
"modlogs": "Recent moderation logs",
"ban": "Ban",
"unban": "Unban"
}
},
"admin": {
"title": "Administration",
+2
View File
@@ -9,6 +9,7 @@ import type {
Post,
PostReportView,
PostView,
PrivateMessage,
PrivateMessageReportView,
PrivateMessageView,
} from 'lemmy-js-client'
@@ -25,6 +26,7 @@ export type Result =
| PostReportView
| CommentReportView
| PrivateMessageReportView
| PrivateMessage
export function getItemPublished(item: Result) {
// reports... why
+32
View File
@@ -186,3 +186,35 @@ export function escapeHtml(input: string): string {
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
}
export function fuzzySearch(text: string, pattern: string): number {
const textLower = text.toLowerCase()
const patternLower = pattern.toLowerCase()
let score = 0
let lastIndex = -1
let consecutiveBonus = 0
for (let i = 0; i < patternLower.length; i++) {
const index = textLower.indexOf(patternLower[i], lastIndex + 1)
if (index === -1) return 0
score += 1
if (index === lastIndex + 1) {
consecutiveBonus++
score += consecutiveBonus
} else {
consecutiveBonus = 0
}
lastIndex = index
}
// Bonus for matching start of words
if (textLower.startsWith(patternLower)) {
score += 2
} else if (textLower.includes(' ' + patternLower)) {
score += 1
}
return score
}