feat: add user and community purging
This commit is contained in:
1 parent
b379fff441
commit
1422f964dd
1 file changed
+97
-29
@@ -11,7 +11,9 @@
|
|||||||
Calendar,
|
Calendar,
|
||||||
ChartBar,
|
ChartBar,
|
||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
|
EllipsisHorizontal,
|
||||||
Envelope,
|
Envelope,
|
||||||
|
Fire,
|
||||||
Icon,
|
Icon,
|
||||||
NoSymbol,
|
NoSymbol,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
@@ -23,9 +25,9 @@
|
|||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { isCommentView } from '$lib/lemmy/item.js'
|
import { isCommentView } from '$lib/lemmy/item.js'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { client, getClient } from '$lib/lemmy.js'
|
||||||
import { isBlocked } from '$lib/lemmy/user.js'
|
import { isBlocked } from '$lib/lemmy/user.js'
|
||||||
import { Menu, MenuButton, Popover, toast } from 'mono-svelte'
|
import { Menu, MenuButton, Popover, removeToast, toast } from 'mono-svelte'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.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'
|
||||||
@@ -78,6 +80,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let messaging = false
|
let messaging = false
|
||||||
|
|
||||||
|
let purgingUser = false
|
||||||
|
let purgeEnabled = false
|
||||||
|
$: if (purgingUser) {
|
||||||
|
purgeEnabled = false
|
||||||
|
setTimeout(() => {
|
||||||
|
purgeEnabled = true
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function purgeUser() {
|
||||||
|
purgingUser = false
|
||||||
|
const purgeToast = toast({ content: 'Purging user...', loading: true })
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client().purgePerson({
|
||||||
|
person_id: data.person_view.person.id,
|
||||||
|
})
|
||||||
|
removeToast(purgeToast)
|
||||||
|
toast({ content: 'Purged that user.', type: 'success' })
|
||||||
|
} catch (e) {
|
||||||
|
toast({ content: e as any, type: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -91,6 +117,34 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if purgingUser}
|
||||||
|
<Modal bind:open={purgingUser}>
|
||||||
|
<svelte:fragment slot="title">Purging User</svelte:fragment>
|
||||||
|
<p>
|
||||||
|
Purging user <span class="font-bold">
|
||||||
|
{data.person_view.person.name}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Are you sure you want to do this? (The button will enable in 3 seconds.)
|
||||||
|
</p>
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<Button size="lg" on:click={() => (purgingUser = false)} class="flex-1">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
color="danger"
|
||||||
|
on:click={purgeUser}
|
||||||
|
disabled={!purgeEnabled}
|
||||||
|
class="flex-1"
|
||||||
|
>
|
||||||
|
Purge
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="flex flex-col-reverse xl:flex-row gap-4 max-w-full w-full">
|
<div class="flex flex-col-reverse xl:flex-row gap-4 max-w-full w-full">
|
||||||
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
||||||
<div class="flex flex-row gap-4 flex-wrap justify-between">
|
<div class="flex flex-row gap-4 flex-wrap justify-between">
|
||||||
@@ -222,34 +276,48 @@
|
|||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<div class="flex flex-row gap-2 ml-auto">
|
||||||
size="lg"
|
{#if isAdmin($profile?.user)}
|
||||||
color="danger"
|
<Menu class="ml-auto" origin="bottom-right">
|
||||||
loading={blocking}
|
<Button size="square-md" slot="target">
|
||||||
disabled={blocking}
|
<ShieldIcon width={16} filled />
|
||||||
on:click={() => blockUser(data.person_view.person.id)}
|
</Button>
|
||||||
>
|
<MenuButton
|
||||||
<Icon slot="prefix" mini size="16" src={NoSymbol} />
|
color="danger-subtle"
|
||||||
{isBlocked($profile.user, data.person_view.person.id)
|
on:click={() =>
|
||||||
? 'Unblock'
|
ban(
|
||||||
: 'Block'}
|
data.person_view.person.banned,
|
||||||
</Button>
|
data.person_view.person
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon slot="prefix" mini size="16" src={ShieldExclamation} />
|
||||||
|
{data.person_view.person.banned ? 'Unban' : 'Ban'}
|
||||||
|
</MenuButton>
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
on:click={() => (purgingUser = !purgingUser)}
|
||||||
|
>
|
||||||
|
<Icon slot="prefix" mini size="16" src={Fire} />
|
||||||
|
Purge
|
||||||
|
</MenuButton>
|
||||||
|
</Menu>
|
||||||
|
{/if}
|
||||||
|
<Menu origin="bottom-right">
|
||||||
|
<Button size="square-md" slot="target">
|
||||||
|
<Icon src={EllipsisHorizontal} slot="prefix" size="16" mini />
|
||||||
|
</Button>
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
on:click={() => blockUser(data.person_view.person.id)}
|
||||||
|
>
|
||||||
|
<Icon slot="prefix" mini size="16" src={NoSymbol} />
|
||||||
|
{isBlocked($profile.user, data.person_view.person.id)
|
||||||
|
? 'Unblock'
|
||||||
|
: 'Block'}
|
||||||
|
</MenuButton>
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if isAdmin($profile?.user)}
|
|
||||||
<Menu class="ml-auto" origin="bottom-right">
|
|
||||||
<Button size="square-md" slot="target">
|
|
||||||
<ShieldIcon width={16} filled />
|
|
||||||
</Button>
|
|
||||||
<MenuButton
|
|
||||||
color="danger-subtle"
|
|
||||||
on:click={() =>
|
|
||||||
ban(data.person_view.person.banned, data.person_view.person)}
|
|
||||||
>
|
|
||||||
<Icon slot="prefix" 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">
|
||||||
|
|||||||
Reference in new issue
Block a user