fix: re-add actions to community header

This commit is contained in:
Xylight committed 2024-09-22 13:20:12 -07:00
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')}
@@ -1,7 +1,6 @@
<script lang="ts">
import { profile } from '$lib/auth'
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
import { t } from '$lib/translations'
import { fullCommunityName } from '$lib/util'
import type {
@@ -10,27 +9,33 @@
CommunityModeratorView,
SubscribedType,
} from 'lemmy-js-client'
import { Button, toast } from 'mono-svelte'
import { Button, toast, Menu, MenuButton, modal, action } from 'mono-svelte'
import {
Check,
Cog6Tooth,
Icon,
InformationCircle,
EllipsisHorizontal,
Plus,
Newspaper,
BuildingOffice2,
Fire,
NoSymbol,
} from 'svelte-hero-icons'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
import { userSettings } from '$lib/settings'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import ItemList from '../generic/ItemList.svelte'
import { userLink } from '$lib/lemmy/generic'
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
import { publishedToDate } from '$lib/components/util/date'
import { isAdmin } from '../moderation/moderation'
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
export let community: Community
export let subscribed: SubscribedType
export let counts: CommunityAggregates | undefined = undefined
export let moderators: CommunityModeratorView[] = []
export let blocked: boolean = false
</script>
<EntityHeader
@@ -149,5 +154,69 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
<Icon src={Cog6Tooth} size="16" mini />
</Button>
{/if}
<Menu placement="top-end">
<Button
rounding="xl"
size="custom"
slot="target"
style="height: 38px; width: 38px;"
>
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
</Button>
<MenuButton href="/modlog?community={community.id}">
<Icon src={Newspaper} size="16" mini />
{$t('cards.community.modlog')}
</MenuButton>
{#if $profile?.jwt}
<MenuButton
color="danger-subtle"
size="lg"
on:click={() => block(community.id, !blocked)}
>
<Icon src={NoSymbol} size="16" mini slot="prefix" />
{blocked
? $t('cards.community.unblock')
: $t('cards.community.block')}
</MenuButton>
{#if $profile?.user}
<MenuButton
color="danger-subtle"
size="lg"
on:click={() => blockInstance(community.instance_id)}
>
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
{$t('cards.community.blockInstance')}
</MenuButton>
{/if}
{#if $profile?.user && isAdmin($profile.user)}
<MenuButton
color="danger-subtle"
on:click={() =>
modal({
title: $t('admin.purgeCommunity.title'),
body: `${community.title}: ${$t('admin.purgeCommunity.warning')}`,
actions: [
action({
close: true,
content: $t('common.cancel'),
}),
action({
action: () => purgeCommunity(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')}
</MenuButton>
{/if}
{/if}
</Menu>
</div>
</EntityHeader>
+1
View File
@@ -81,6 +81,7 @@
<CommunityHeader
bind:community={community.community}
bind:subscribed={community.subscribed}
bind:blocked={community.blocked}
moderators={data.community.moderators}
counts={community.counts}
/>