feat: add admin appointing and demoting
This commit is contained in:
1 parent
d13b1be332
commit
10af840273
2 files changed
+60
-22
No files matched your search
@@ -10,6 +10,7 @@
|
|||||||
export let avatarSize: number = 24
|
export let avatarSize: number = 24
|
||||||
export let badges: boolean = true
|
export let badges: boolean = true
|
||||||
export let inComment: boolean = false
|
export let inComment: boolean = false
|
||||||
|
export let showInstance: boolean = false
|
||||||
|
|
||||||
function linkFromCommunity(user: Person) {
|
function linkFromCommunity(user: Person) {
|
||||||
const domain = new URL(user.actor_id).hostname
|
const domain = new URL(user.actor_id).hostname
|
||||||
@@ -31,7 +32,7 @@
|
|||||||
class:font-bold={user.admin}
|
class:font-bold={user.admin}
|
||||||
>
|
>
|
||||||
{$userSettings.displayNames ? user.display_name ?? user.name : user.name}
|
{$userSettings.displayNames ? user.display_name ?? user.name : user.name}
|
||||||
{#if $userSettings.showInstances.user || ($userSettings.showInstances.comments && inComment)}
|
{#if $userSettings.showInstances.user || ($userSettings.showInstances.comments && inComment) || showInstance}
|
||||||
<span class="text-slate-500 dark:text-zinc-500 font-normal">
|
<span class="text-slate-500 dark:text-zinc-500 font-normal">
|
||||||
@{new URL(user.actor_id).hostname}
|
@{new URL(user.actor_id).hostname}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
NoSymbol,
|
NoSymbol,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
ShieldExclamation,
|
ShieldExclamation,
|
||||||
|
UserPlus,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
@@ -29,11 +30,13 @@
|
|||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { ban, isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
|
import { ban, isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
|
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||||
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
let blocking = false
|
let blocking = false
|
||||||
let banning = false
|
|
||||||
|
|
||||||
async function blockUser(block: number) {
|
async function blockUser(block: number) {
|
||||||
if (!$profile?.user || !$profile?.jwt) throw new Error('Unauthenticated')
|
if (!$profile?.user || !$profile?.jwt) throw new Error('Unauthenticated')
|
||||||
@@ -214,19 +217,6 @@
|
|||||||
<Icon slot="icon" solid size="16" src={Envelope} />
|
<Icon slot="icon" solid size="16" src={Envelope} />
|
||||||
Message
|
Message
|
||||||
</Button>
|
</Button>
|
||||||
{#if isAdmin($profile?.user)}
|
|
||||||
<Button
|
|
||||||
size="lg"
|
|
||||||
color="danger"
|
|
||||||
loading={banning}
|
|
||||||
disabled={banning}
|
|
||||||
on:click={() =>
|
|
||||||
ban(data.person_view.person.banned, data.person_view.person)}
|
|
||||||
>
|
|
||||||
<Icon slot="icon" mini size="16" src={ShieldExclamation} />
|
|
||||||
{data.person_view.person.banned ? 'Unban' : 'Ban'}
|
|
||||||
</Button>
|
|
||||||
{/if}
|
|
||||||
<Button
|
<Button
|
||||||
size="lg"
|
size="lg"
|
||||||
color="danger"
|
color="danger"
|
||||||
@@ -240,17 +230,64 @@
|
|||||||
: 'Block'}
|
: 'Block'}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
{#if isAdmin($profile?.user)}
|
||||||
|
<Menu let:toggleOpen class="ml-auto" alignment="bottom-right">
|
||||||
|
<Button size="square-md" on:click={toggleOpen} slot="button">
|
||||||
|
<ShieldIcon width={16} filled />
|
||||||
|
</Button>
|
||||||
|
{#if data.person_view.person.local}
|
||||||
|
<MenuButton
|
||||||
|
on:click={() => {
|
||||||
|
toast({
|
||||||
|
content: `Are you sure you want to ${
|
||||||
|
data.person_view.person.admin ? 'remove' : 'appoint'
|
||||||
|
} ${data.person_view.person.name} as an admin?`,
|
||||||
|
duration: 99999 * 1000,
|
||||||
|
type: 'info',
|
||||||
|
action: async () => {
|
||||||
|
if (!$profile?.jwt) return
|
||||||
|
await getClient()
|
||||||
|
.addAdmin({
|
||||||
|
auth: $profile.jwt,
|
||||||
|
added: !data.person_view.person.admin,
|
||||||
|
person_id: data.person_view.person.id,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
data.person_view.person.admin =
|
||||||
|
!data.person_view.person.admin
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
toast({
|
||||||
|
content: 'Failed to modify that user.',
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon slot="icon" mini size="16" src={UserPlus} />
|
||||||
|
{data.person_view.person.admin
|
||||||
|
? 'Remove admin'
|
||||||
|
: 'Appoint as admin'}
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
<MenuButton
|
||||||
|
color="dangerSecondary"
|
||||||
|
on:click={() =>
|
||||||
|
ban(data.person_view.person.banned, data.person_view.person)}
|
||||||
|
>
|
||||||
|
<Icon slot="icon" mini size="16" src={ShieldExclamation} />
|
||||||
|
{data.person_view.person.banned ? 'Unban' : 'Ban'}
|
||||||
|
</MenuButton>
|
||||||
|
</Menu>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<div>
|
<div>
|
||||||
<h1 class="font-bold text-lg">
|
<h1 class="font-bold text-lg">
|
||||||
{data.person_view.person.display_name ?? data.person_view.person.name}
|
<UserLink badges user={data.person_view.person} />
|
||||||
</h1>
|
</h1>
|
||||||
<span class="text-sm opacity-80 flex flex-row gap-0">
|
<span>{new URL(data.person_view.person.actor_id).hostname}</span>
|
||||||
{#if data.person_view.person.display_name}
|
|
||||||
{data.person_view.person.name}@
|
|
||||||
{/if}
|
|
||||||
{new URL(data.person_view.person.actor_id).hostname}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
{#if data.person_view.person.bio}
|
{#if data.person_view.person.bio}
|
||||||
<Markdown source={data.person_view.person.bio} />
|
<Markdown source={data.person_view.person.bio} />
|
||||||
|
|||||||
Reference in new issue
Block a user