Merge pull request #599 from Xyphyn/moderation-impr

feat: add view votes modal to comments/posts, close #243
This commit is contained in:
Xylight authored and GitHub committed 2025-06-26 01:56:01 +00:00
1 parent 6191fc7880
commit cd123d56cd
6 files changed
+193 -32

No files matched your search

@@ -1,7 +1,12 @@
<script lang="ts">
import type { CommentView, PostView } from 'lemmy-js-client'
import { amMod, ban, feature, isAdmin, remove } from './moderation'
import { profile } from '$lib/auth.svelte.js'
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
import { t } from '$lib/i18n/translations'
import { isCommentView } from '$lib/lemmy/item.js'
import type { CommentView } from 'lemmy-js-client'
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
import {
ArrowsUpDown,
Fire,
Icon,
Megaphone,
@@ -9,14 +14,10 @@
ShieldExclamation,
Trash,
} from 'svelte-hero-icons'
import { isCommentView } from '$lib/lemmy/item.js'
import { profile } from '$lib/auth.svelte.js'
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { amMod, ban, feature, isAdmin, remove, viewVotes } from './moderation'
interface Props {
item: PostView | CommentView
item: CommentView
}
let { item = $bindable(), ...rest }: Props = $props()
@@ -49,8 +50,6 @@
{item.comment.removed
? $t('moderation.restore')
: $t('moderation.remove')}
{:else}
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
{/if}
</MenuButton>
{#if profile.data?.user && profile.data.user?.local_user_view.person.id != item.creator.id}
@@ -67,7 +66,7 @@
? $t('moderation.ban.unbanFromCommunity')
: $t('moderation.ban.banFromCommunity')}
</MenuButton>
{:else if isCommentView(item)}
{:else}
<!--Comment made by self-->
<MenuButton
color="success-subtle"
@@ -89,19 +88,20 @@
? $t('moderation.unfeature')
: $t('moderation.feature')}
</MenuButton>
<MenuButton color="success-subtle" href="/modlog?user={item.creator.id}">
<Icon src={Newspaper} size="16" micro />
{$t('moderation.modlog.user')}
</MenuButton>
<MenuButton
color="success-subtle"
href="/modlog?comment={item.comment.id}"
>
<Icon src={Newspaper} size="16" micro />
{$t('moderation.modlog.comment')}
</MenuButton>
{/if}
<MenuButton color="success-subtle" href="/modlog?comment={item.comment.id}">
<Icon src={Newspaper} size="16" micro />
{$t('moderation.modlog.comment')}
</MenuButton>
<MenuButton color="success-subtle" href="/modlog?user={item.creator.id}">
<Icon src={Newspaper} size="16" micro />
{$t('moderation.modlog.user')}
</MenuButton>
<MenuButton color="blue-subtle" onclick={() => viewVotes(item)}>
<Icon src={ArrowsUpDown} size="16" micro />
{$t('moderation.votes')}
</MenuButton>
{/if}
{#if profile.data?.user && isAdmin(profile.data.user)}
@@ -30,3 +30,9 @@
/>
{/await}
{/if}
{#if $modals.votes.open}
{#await import('$lib/components/lemmy/moderation/ViewVotesModal.svelte') then { default: VotesModal }}
<VotesModal bind:open={$modals.votes.open} item={$modals.votes.item} />
{/await}
{/if}
@@ -6,6 +6,7 @@
import type { CommentView, PostView } from 'lemmy-js-client'
import { Button, Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
import {
ArrowsUpDown,
Fire,
Icon,
LockClosed,
@@ -15,7 +16,7 @@
ShieldExclamation,
Trash,
} from 'svelte-hero-icons'
import { amMod, ban, isAdmin, remove } from './moderation'
import { amMod, ban, isAdmin, remove, viewVotes } from './moderation'
import ShieldIcon from './ShieldIcon.svelte'
import { errorMessage } from '$lib/lemmy/error'
@@ -149,15 +150,19 @@
? $t('moderation.ban.unbanFromCommunity')
: $t('moderation.ban.banFromCommunity')}
</MenuButton>
<MenuButton color="success-subtle" href="/modlog?user={item.creator.id}">
<Icon src={Newspaper} size="16" micro />
{$t('moderation.modlog.user')}
</MenuButton>
<MenuButton color="success-subtle" href="/modlog?post={item.post.id}">
<Icon src={Newspaper} size="16" micro />
{$t('moderation.modlog.post')}
</MenuButton>
{/if}
<MenuButton color="success-subtle" href="/modlog?user={item.creator.id}">
<Icon src={Newspaper} size="16" micro />
{$t('moderation.modlog.user')}
</MenuButton>
<MenuButton color="success-subtle" href="/modlog?post={item.post.id}">
<Icon src={Newspaper} size="16" micro />
{$t('moderation.modlog.post')}
</MenuButton>
<MenuButton color="blue-subtle" onclick={() => viewVotes(item)}>
<Icon src={ArrowsUpDown} size="16" micro />
{$t('moderation.votes')}
</MenuButton>
{/if}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuDivider>{$t('admin.label')}</MenuDivider>
@@ -0,0 +1,130 @@
<script lang="ts">
import { t } from '$lib/i18n/translations'
import { client } from '$lib/lemmy.svelte'
import { isCommentView, isPostView } from '$lib/lemmy/item'
import type { CommentView, PostView, VoteView } from 'lemmy-js-client'
import { Button, Modal, Spinner } from 'mono-svelte'
import {
ArrowDownCircle,
ArrowUpCircle,
ChevronLeft,
ChevronRight,
Icon,
Newspaper,
} from 'svelte-hero-icons'
import UserLink from '../user/UserLink.svelte'
interface Props {
open: boolean
item?: PostView | CommentView | undefined
}
let { open = $bindable(), item = $bindable() }: Props = $props()
let page = $state(1)
async function loadVotes(page: number): Promise<VoteView[]> {
if (!item) return []
if (isPostView(item))
return await client()
.listPostLikes({ post_id: item.post.id, limit: 50, page: page })
.then(i => i.post_likes)
if (isCommentView(item))
return await client()
.listCommentLikes({
comment_id: item.comment.id,
limit: 50,
page: page,
})
.then(i => i.comment_likes)
return []
}
let votes: Promise<VoteView[]> = $derived(loadVotes(page))
</script>
<Modal bind:open title={$t('moderation.votes')}>
<div class="flex flex-col gap-1">
{#await votes}
<div class="self-center justify-self-center h-48 grid place-items-center">
<Spinner width={24} />
</div>
{:then votes}
<table class="w-full border-collapse overflow-y-auto table-fixed">
<thead>
<tr
class="border divide-x divide-slate-200 dark:divide-zinc-800 border-slate-200 dark:border-zinc-800 *:px-4 *:py-2"
>
<th style="width: 6%;"></th>
<th style="width: 60%;" class="text-left">
{$t('routes.admin.applications.user')}
</th>
<th style="width: 5%;"></th>
</tr>
</thead>
<tbody class="divide-y divide-slate-200 dark:divide-zinc-800">
{#each votes as vote}
<tr>
<td class="py-1 px-1 w-full">
<Icon
src={vote.score == 1 ? ArrowUpCircle : ArrowDownCircle}
mini
size="20"
class={vote.score == 1 ? 'text-blue-400' : 'text-red-400'}
aria-label={vote.score == 1
? $t('routes.profile.upvoted')
: $t('routes.profile.downvoted')}
/>
</td>
<td class="text-sm w-full overflow-hidden">
<UserLink
user={{
...vote.creator,
banned: vote.creator_banned_from_community,
}}
/>
</td>
<td class="text-sm w-full text-right">
<a
href="/modlog?user={vote.creator.id}"
data-sveltekit-preload-data="tap"
class="text-green-400 hover:underline flex flex-row items-center gap-1 font-medium text-xs"
aria-label={$t('moderation.modlog.user')}
>
<Icon src={Newspaper} size="18" micro />
</a>
</td>
</tr>
{/each}
</tbody>
</table>
{#if !(votes.length < 50 && page == 1)}
<div class="flex flex-row justify-center items-center gap-2">
<Button
onclick={() => page--}
color="ghost"
aria-label={$t('common.back')}
rounding="pill"
size="square-md"
disabled={page == 1}
>
<Icon src={ChevronLeft} size="20" mini />
</Button>
{page}
<Button
onclick={() => page++}
color="ghost"
aria-label={$t('common.next')}
rounding="pill"
size="square-md"
disabled={votes.length < 50}
>
<Icon src={ChevronRight} size="20" mini />
</Button>
</div>
{/if}
{/await}
</div>
</Modal>
@@ -27,6 +27,10 @@ interface Modals {
user: Person | undefined
community: Community | undefined
}
votes: {
open: boolean
item: PostView | CommentView | undefined
}
}
export const modals = writable<Modals>({
@@ -45,6 +49,10 @@ export const modals = writable<Modals>({
user: undefined,
community: undefined,
},
votes: {
open: false,
item: undefined,
},
})
export function report(item: PostView | CommentView | PrivateMessageView) {
@@ -87,6 +95,16 @@ export async function feature(featured: boolean, item: Comment, jwt: string) {
})
}
export async function viewVotes(item: PostView | CommentView) {
modals.update(m => ({
...m,
votes: {
open: true,
item: item,
},
}))
}
export const amMod = (me: MyUserInfo, community: Community) =>
me.moderates.map(c => c.community.id).includes(community.id) ||
(community.local && isAdmin(me))
+2
View File
@@ -40,6 +40,8 @@
dark:border-zinc-800 hover:bg-slate-200 dark:hover:bg-zinc-800 hover:border-slate-300
dark:hover:border-zinc-700`,
'blue-subtle': `text-blue-500 hover:bg-blue-500 hover:text-inherit!`,
none: '',
}