impr: replace amMod, amModOfAny, isAdmin, with profile class getters
This commit is contained in:
18 files changed
+89
-89
No files matched your search
@@ -2,7 +2,8 @@
|
||||
import type { CommentView } from '$lib/api/types'
|
||||
import { profile } from '$lib/app/auth.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||
import { Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import {
|
||||
ArrowsUpDown,
|
||||
Fire,
|
||||
@@ -12,32 +13,22 @@
|
||||
ShieldExclamation,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons/dist'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
import { isCommentView } from '../legacy/item'
|
||||
import { amMod, ban, feature, isAdmin, remove, viewVotes } from './moderation'
|
||||
import ShieldIcon from './ShieldIcon.svelte'
|
||||
import { ban, feature, remove, viewVotes } from './moderation'
|
||||
|
||||
interface Props {
|
||||
item: CommentView
|
||||
target: Snippet<[Attachment]>
|
||||
}
|
||||
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
let { item = $bindable(), target, ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom" class="top-0 h-[26px] w-[26px] ">
|
||||
{#snippet target(attachment)}
|
||||
<Button
|
||||
{@attach attachment}
|
||||
class="w-[26px] h-[26px] hover:text-green-500! dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider showLabel>
|
||||
{#if !item.community.local && !amMod(profile.current.user, item.community)}
|
||||
<Menu {...rest} placement="bottom" {target}>
|
||||
{#if profile.isMod(item.community) || profile.isAdmin}
|
||||
<MenuDivider hidden>
|
||||
{#if !item.community.local && !profile.isMod(item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
@@ -98,7 +89,7 @@
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
{#if profile.isAdmin}
|
||||
<MenuDivider showLabel>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
} from 'svelte-hero-icons/dist'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
import { isCommentView, isPostView } from '../legacy/item'
|
||||
import { amMod, ban, isAdmin, remove, viewVotes } from './moderation'
|
||||
import { ban, remove, viewVotes } from './moderation'
|
||||
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
@@ -79,9 +79,9 @@
|
||||
{#snippet target(attachment)}
|
||||
{@render passedTarget(attachment, acting)}
|
||||
{/snippet}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
{#if profile.isMod(item.community) || profile.isAdmin}
|
||||
<MenuDivider showLabel>
|
||||
{#if !item.community.local && !amMod(profile.current.user, item.community)}
|
||||
{#if !item.community.local && !profile.isMod(item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
@@ -111,7 +111,7 @@
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
</span>
|
||||
{#if isAdmin(profile.current.user)}
|
||||
{#if profile.isAdmin}
|
||||
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -151,7 +151,7 @@
|
||||
{$t('moderation.votes')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
{#if profile.isAdmin}
|
||||
<MenuDivider showLabel>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import Comment from '../comment/Comment.svelte'
|
||||
import { isCommentView, isPostView } from '../legacy/item'
|
||||
import { Post } from '../post'
|
||||
import { amMod, isAdmin, removalTemplate } from './moderation'
|
||||
import { removalTemplate } from './moderation'
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
@@ -213,7 +213,7 @@
|
||||
bind:value={reason}
|
||||
/>
|
||||
|
||||
{#if !removed && profile.current?.user && (amMod(profile.current.user, item.community) || (isAdmin(profile.current.user) && item.community.local))}
|
||||
{#if !removed}
|
||||
<Switch bind:checked={commentReason}>
|
||||
{$t('moderation.removeSubmission.withReason')}
|
||||
</Switch>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import type {
|
||||
Comment,
|
||||
CommentView,
|
||||
Community,
|
||||
MyUserInfo,
|
||||
Person,
|
||||
PostView,
|
||||
PrivateMessageView,
|
||||
@@ -104,15 +104,6 @@ export async function viewVotes(item: PostView | CommentView) {
|
||||
}))
|
||||
}
|
||||
|
||||
export const amMod = (me: MyUserInfo, community: Community) =>
|
||||
me.moderates.map((c) => c.community.id).includes(community.id) ||
|
||||
(community.local && isAdmin(me))
|
||||
|
||||
export const amModOfAny = (me?: MyUserInfo) =>
|
||||
me && (me.moderates.length > 0 || isAdmin(me))
|
||||
|
||||
export const isAdmin = (me: MyUserInfo) => me.local_user_view.person.admin
|
||||
|
||||
export const removalTemplate = (
|
||||
input: string,
|
||||
content: {
|
||||
|
||||
Reference in new issue
Block a user