feat: add instance blocking

This commit is contained in:
Xylight committed 2023-12-15 15:30:11 -08:00
1 parent 0704ee86c2
commit 896175935e
8 files changed
+202 -47

No files matched your search

+1 -1
View File
@@ -56,7 +56,7 @@
<option value="Active">Active</option>
<option value="Hot">Hot</option>
{#if feature('scaledSort', $site?.version)}
<option value="Scaled">Rising</option>
<option value="Scaled">Scaled</option>
{/if}
<option value="TopAll">Top</option>
<option value="New">New</option>
@@ -23,6 +23,7 @@
import type { CommunityModeratorView, CommunityView } from 'lemmy-js-client'
import { Button } from 'mono-svelte'
import {
BuildingOffice2,
Calendar,
ChatBubbleOvalLeftEllipsis,
Check,
@@ -73,10 +74,24 @@
const blocked = community_view.blocked
try {
const loading = toast({
content: `${blocked ? 'Unblocking' : 'blocking'} community...`,
loading: true,
})
await getClient().blockCommunity({
community_id: community_view.community.id,
block: !blocked,
})
removeToast(loading)
toast({
content: `Successfully ${
blocked ? 'unblocked' : 'blocked'
} that community.`,
type: 'success',
})
} catch (error) {
toast({ content: error as any, type: 'error' })
}
@@ -108,6 +123,30 @@
toast({ content: e as any, type: 'error' })
}
}
async function blockInstance() {
if (!$profile?.jwt) return
try {
const loading = toast({
content: `Blocking instance...`,
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}
@@ -276,6 +315,12 @@
<Icon src={NoSymbol} size="16" mini slot="prefix" />
{community_view.blocked ? 'Unblock' : 'Block'}
</MenuButton>
{#if $profile?.user}
<MenuButton color="danger-subtle" size="lg" on:click={blockInstance}>
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
Block instance
</MenuButton>
{/if}
{#if $profile?.user && isAdmin($profile.user)}
<MenuButton
color="danger-subtle"
+15
View File
@@ -0,0 +1,15 @@
<script lang="ts">
import Avatar from './Avatar.svelte'
export let name: string
export let label: string | undefined = undefined
export let icon: string | undefined = undefined
</script>
<div class="flex flex-row gap-2 items-center">
<Avatar url={icon} width={32} />
<div class="flex flex-col">
<span class="font-medium">{name}</span>
<span class="text-sm">{label}</span>
</div>
</div>
+12 -3
View File
@@ -5,10 +5,13 @@
export let title: string
export let description: string | undefined = undefined
export let center: boolean = true
</script>
<div
class="text-slate-700 dark:text-zinc-300 flex flex-col justify-center items-center gap-2 {$$props.class}"
class="text-slate-700 dark:text-zinc-300 flex flex-col {center
? 'justify-center items-center'
: 'justify-start items-start'} gap-2 {$$props.class}"
>
{#if icon}
<div
@@ -17,12 +20,18 @@
<Icon src={icon} size="28" />
</div>
{/if}
<div class="flex flex-col gap-1 text-center">
<div
class="flex flex-col gap-1 {center
? 'text-center'
: 'text-left'} {$$props.class}"
>
<h1 class="text-slate-900 dark:text-zinc-100 text-lg font-medium">
{title}
</h1>
{#if description}
<p class="text-sm text-center font-normal">{description}</p>
<p class="text-sm {center ? 'text-center' : 'text-left'} font-normal">
{description}
</p>
{/if}
</div>
<slot />
+1 -4
View File
@@ -1,6 +1,3 @@
<span
{...$$restProps}
class="text-sm font-bold text-slate-600 dark:text-zinc-400 {$$props.class}"
>
<span {...$$restProps} class="text-lg font-semibold {$$props.class}">
<slot />
</span>