fix: re-add actions to community header
This commit is contained in:
1 parent
98767a41f5
commit
38e5c7dcad
3 files changed
+181
-118
No files matched your search
@@ -1,3 +1,70 @@
|
||||
<script lang="ts" context="module">
|
||||
export async function block(id: number, block: boolean) {
|
||||
try {
|
||||
const loading = toast({
|
||||
content: ``,
|
||||
loading: true,
|
||||
})
|
||||
|
||||
await getClient().blockCommunity({
|
||||
community_id: id,
|
||||
block: block,
|
||||
})
|
||||
|
||||
removeToast(loading)
|
||||
|
||||
toast({
|
||||
content: !block
|
||||
? t.get('toast.unblockedCommunity')
|
||||
: t.get('toast.blockedCommunity'),
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
return block
|
||||
} catch (error) {
|
||||
toast({ content: error as any, type: 'error' })
|
||||
return !block
|
||||
}
|
||||
}
|
||||
|
||||
export async function purgeCommunity(id: number) {
|
||||
const purgeToast = toast({ content: '', loading: true })
|
||||
|
||||
try {
|
||||
await client().purgeCommunity({
|
||||
community_id: id,
|
||||
})
|
||||
removeToast(purgeToast)
|
||||
toast({ content: t.get('toast.purgedCommunity'), type: 'success' })
|
||||
} catch (e) {
|
||||
toast({ content: e as any, type: 'error' })
|
||||
}
|
||||
}
|
||||
|
||||
export async function blockInstance(id: number) {
|
||||
try {
|
||||
const loading = toast({
|
||||
content: ``,
|
||||
loading: true,
|
||||
})
|
||||
|
||||
await getClient().blockInstance({
|
||||
instance_id: id,
|
||||
block: true,
|
||||
})
|
||||
|
||||
removeToast(loading)
|
||||
|
||||
toast({
|
||||
content: `Successfully blocked that instance.`,
|
||||
type: 'success',
|
||||
})
|
||||
} catch (error) {
|
||||
toast({ content: error as any, type: 'error' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import {
|
||||
@@ -7,7 +74,15 @@
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
||||
import { Menu, MenuButton, Modal, removeToast, toast } from 'mono-svelte'
|
||||
import {
|
||||
Menu,
|
||||
MenuButton,
|
||||
Modal,
|
||||
removeToast,
|
||||
toast,
|
||||
modal,
|
||||
action,
|
||||
} from 'mono-svelte'
|
||||
import { client, getClient } from '$lib/lemmy.js'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { fullCommunityName } from '$lib/util.js'
|
||||
@@ -27,7 +102,6 @@
|
||||
NoSymbol,
|
||||
Plus,
|
||||
} from 'svelte-hero-icons'
|
||||
import CommunityLink from './CommunityLink.svelte'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
||||
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
||||
@@ -66,117 +140,8 @@
|
||||
|
||||
loading.subscribing = false
|
||||
}
|
||||
async function block() {
|
||||
if (!$profile?.jwt) return
|
||||
loading.blocking = true
|
||||
const blocked = community_view.blocked
|
||||
|
||||
try {
|
||||
const loading = toast({
|
||||
content: ``,
|
||||
loading: true,
|
||||
})
|
||||
|
||||
await getClient().blockCommunity({
|
||||
community_id: community_view.community.id,
|
||||
block: !blocked,
|
||||
})
|
||||
|
||||
removeToast(loading)
|
||||
|
||||
toast({
|
||||
content: blocked
|
||||
? $t('toast.unblockedCommunity')
|
||||
: $t('toast.blockedCommunity'),
|
||||
type: 'success',
|
||||
})
|
||||
} catch (error) {
|
||||
toast({ content: error as any, type: 'error' })
|
||||
}
|
||||
|
||||
community_view.blocked = !blocked
|
||||
loading.blocking = false
|
||||
}
|
||||
|
||||
let purgingCommunity = false
|
||||
let purgeEnabled = false
|
||||
$: if (purgingCommunity) {
|
||||
purgeEnabled = false
|
||||
setTimeout(() => {
|
||||
purgeEnabled = true
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
async function purgeCommunity() {
|
||||
purgingCommunity = false
|
||||
const purgeToast = toast({ content: '', loading: true })
|
||||
|
||||
try {
|
||||
await client().purgeCommunity({
|
||||
community_id: community_view.community.id,
|
||||
})
|
||||
removeToast(purgeToast)
|
||||
toast({ content: $t('toast.purgedCommunity'), type: 'success' })
|
||||
} catch (e) {
|
||||
toast({ content: e as any, type: 'error' })
|
||||
}
|
||||
}
|
||||
|
||||
async function blockInstance() {
|
||||
if (!$profile?.jwt) return
|
||||
try {
|
||||
const loading = toast({
|
||||
content: ``,
|
||||
loading: true,
|
||||
})
|
||||
|
||||
await getClient().blockInstance({
|
||||
instance_id: community_view.community.instance_id,
|
||||
block: true,
|
||||
})
|
||||
|
||||
removeToast(loading)
|
||||
|
||||
toast({
|
||||
content: `Successfully blocked that instance.`,
|
||||
type: 'success',
|
||||
})
|
||||
} catch (error) {
|
||||
toast({ content: error as any, type: 'error' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if purgingCommunity}
|
||||
<Modal bind:open={purgingCommunity}>
|
||||
<svelte:fragment slot="title">
|
||||
{$t('admin.purgeCommunity.title')}
|
||||
</svelte:fragment>
|
||||
<CommunityLink avatar community={community_view.community} />
|
||||
<p>
|
||||
{$t('admin.purgeCommunity.warning')}
|
||||
</p>
|
||||
<div class="flex flex-row gap-2">
|
||||
<Button
|
||||
size="lg"
|
||||
on:click={() => (purgingCommunity = false)}
|
||||
class="flex-1"
|
||||
>
|
||||
{$t('common.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
size="lg"
|
||||
color="danger"
|
||||
on:click={purgeCommunity}
|
||||
disabled={!purgeEnabled}
|
||||
class="flex-1"
|
||||
>
|
||||
{$t('admin.purge')}
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<StickyCard
|
||||
class="min-w-full pt-0 text-slate-600 dark:text-zinc-400 {$$props.class}"
|
||||
>
|
||||
@@ -290,14 +255,23 @@
|
||||
{$t('cards.community.modlog')}
|
||||
</MenuButton>
|
||||
{#if $profile?.jwt}
|
||||
<MenuButton color="danger-subtle" size="lg" on:click={block}>
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
on:click={() =>
|
||||
block(community_view.community.id, !community_view.blocked)}
|
||||
>
|
||||
<Icon src={NoSymbol} size="16" mini slot="prefix" />
|
||||
{community_view.blocked
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
</MenuButton>
|
||||
{#if $profile?.user}
|
||||
<MenuButton color="danger-subtle" size="lg" on:click={blockInstance}>
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
on:click={() => blockInstance(community_view.community.instance_id)}
|
||||
>
|
||||
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
@@ -305,7 +279,26 @@
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
on:click={() => (purgingCommunity = !purgingCommunity)}
|
||||
on:click={() =>
|
||||
modal({
|
||||
title: $t('admin.purgeCommunity.title'),
|
||||
body: `${community_view.community.title}: ${$t('admin.purgeCommunity.warning')}`,
|
||||
actions: [
|
||||
action({
|
||||
close: true,
|
||||
content: $t('common.cancel'),
|
||||
}),
|
||||
action({
|
||||
action: () => purgeCommunity(community_view.community.id),
|
||||
close: true,
|
||||
content: $t('admin.purge'),
|
||||
type: 'danger',
|
||||
icon: Fire,
|
||||
}),
|
||||
],
|
||||
dismissable: true,
|
||||
type: 'error',
|
||||
})}
|
||||
>
|
||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||
{$t('admin.purge')}
|
||||
|
||||
Reference in new issue
Block a user