feat: add instance blocking
This commit is contained in:
1 parent
0704ee86c2
commit
896175935e
8 files changed
+202
-47
No files matched your search
@@ -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"
|
||||
|
||||
@@ -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>
|
||||
@@ -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,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>
|
||||
@@ -11,7 +11,14 @@
|
||||
import { Button, Modal, toast } from 'mono-svelte'
|
||||
import { afterNavigate } from '$app/navigation'
|
||||
import { browser } from '$app/environment'
|
||||
import { ChartBar, EllipsisHorizontal, Icon } from 'svelte-hero-icons'
|
||||
import {
|
||||
ArrowRight,
|
||||
ChartBar,
|
||||
EllipsisHorizontal,
|
||||
Icon,
|
||||
XMark,
|
||||
} from 'svelte-hero-icons'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -89,7 +96,20 @@
|
||||
<div class="flex flex-row gap-4 max-w-full w-full items-end">
|
||||
<Sort selected={data.sort} />
|
||||
</div>
|
||||
<PostFeed community={true} posts={data.posts.posts} />
|
||||
{#if data.community.community_view.blocked}
|
||||
<Placeholder
|
||||
icon={XMark}
|
||||
title="Blocked"
|
||||
description="You've blocked this community."
|
||||
>
|
||||
<Button href="/profile/blocks">
|
||||
<Icon src={ArrowRight} size="16" mini slot="suffix" />
|
||||
Blocked Communities
|
||||
</Button>
|
||||
</Placeholder>
|
||||
{:else}
|
||||
<PostFeed community={true} posts={data.posts.posts} />
|
||||
{/if}
|
||||
|
||||
<Pageination
|
||||
page={data.page}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<div
|
||||
class="flex flex-col divide-y divide-zinc-800 [&>*]:py-3 first:p-0 last:py-0"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
@@ -1,17 +1,22 @@
|
||||
<script lang="ts">
|
||||
import type { CommunityBlockView, PersonBlockView } from 'lemmy-js-client'
|
||||
import type {
|
||||
CommunityBlockView,
|
||||
InstanceBlockView,
|
||||
PersonBlockView,
|
||||
} from 'lemmy-js-client'
|
||||
import type { PageData } from './$types.js'
|
||||
import EditableList from '$lib/components/ui/list/EditableList.svelte'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { Check, Icon, Trash } from 'svelte-hero-icons'
|
||||
import { Check, Icon, Trash, XMark } from 'svelte-hero-icons'
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import { flip } from 'svelte/animate'
|
||||
import { slide } from 'svelte/transition'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { Button } from 'mono-svelte'
|
||||
import Entity from '$lib/components/ui/Entity.svelte'
|
||||
|
||||
// sveltekit doesn't feel like making types work right now
|
||||
export let data: PageData & {
|
||||
@@ -53,22 +58,108 @@
|
||||
community_id: item.community.id,
|
||||
})
|
||||
}
|
||||
|
||||
async function unblockInstances(item: InstanceBlockView) {
|
||||
if (!$profile?.jwt) return
|
||||
if (!data.my_user?.instance_blocks) return
|
||||
|
||||
data.my_user.instance_blocks.splice(
|
||||
data.my_user.instance_blocks.findIndex(
|
||||
(i) => i.instance.id == item.instance.id
|
||||
),
|
||||
1
|
||||
)
|
||||
data.my_user.instance_blocks = data.my_user.instance_blocks
|
||||
|
||||
await getClient().blockInstance({
|
||||
block: false,
|
||||
instance_id: item.instance.id,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if data.community_blocks?.length > 0 || data.person_blocks?.length > 0}
|
||||
{#if data.community_blocks?.length > 0 || data.person_blocks?.length > 0 || (data.my_user?.instance_blocks?.length ?? 0) > 0}
|
||||
{#if data.my_user?.instance_blocks && (data.my_user?.instance_blocks?.length ?? 0) > 0}
|
||||
<div>
|
||||
<SectionTitle>Instances</SectionTitle>
|
||||
<EditableList let:action on:action={(i) => unblockInstances(i.detail)}>
|
||||
{#each data.my_user?.instance_blocks as block (block.instance.id)}
|
||||
<div
|
||||
class="flex flex-row gap-2 items-center py-4 justify-between"
|
||||
animate:flip={{ duration: 250 }}
|
||||
out:slide|local={{ axis: 'y' }}
|
||||
>
|
||||
<Entity
|
||||
icon={block.site?.icon}
|
||||
name={block.site?.name ?? block.instance.domain}
|
||||
label={block.instance.domain}
|
||||
/>
|
||||
<Button
|
||||
title="Unblock"
|
||||
size="square-md"
|
||||
on:click={() => action(block)}
|
||||
>
|
||||
<Icon src={XMark} mini size="16" slot="prefix" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
</EditableList>
|
||||
</div>
|
||||
{:else}
|
||||
<Placeholder
|
||||
description="Go to a community's page and click 'block instance' to stop seeing posts and
|
||||
comments from its instance."
|
||||
title="No blocked instances"
|
||||
center={false}
|
||||
/>
|
||||
{/if}
|
||||
{#if data.community_blocks?.length > 0}
|
||||
<div>
|
||||
<SectionTitle>Communities</SectionTitle>
|
||||
<EditableList let:action on:action={(i) => unblockCommunity(i.detail)}>
|
||||
{#each data.community_blocks as block (block.community.id)}
|
||||
<div
|
||||
class="flex flex-row gap-2 items-center py-2 justify-between"
|
||||
animate:flip={{ duration: 250 }}
|
||||
out:slide|local={{ axis: 'y' }}
|
||||
>
|
||||
<CommunityLink community={block.community} avatar />
|
||||
<Button
|
||||
title="Unblock"
|
||||
size="square-md"
|
||||
on:click={() => action(block)}
|
||||
>
|
||||
<Icon src={XMark} mini size="16" slot="prefix" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
</EditableList>
|
||||
</div>
|
||||
{:else}
|
||||
<Placeholder
|
||||
description="Go to a community's page and click 'block' to stop seeing posts and
|
||||
comments from it."
|
||||
title="No blocked communities"
|
||||
center={false}
|
||||
/>
|
||||
{/if}
|
||||
{#if data.person_blocks?.length > 0}
|
||||
<div>
|
||||
<SectionTitle>Users</SectionTitle>
|
||||
<EditableList let:action on:action={(i) => unblockUser(i.detail)}>
|
||||
{#each data.person_blocks as block (block.target.id)}
|
||||
<div
|
||||
class="flex flex-row gap-4 items-center py-4 justify-between"
|
||||
class="flex flex-row gap-2 items-center py-2 justify-between"
|
||||
animate:flip={{ duration: 250 }}
|
||||
out:slide|local={{ axis: 'y' }}
|
||||
>
|
||||
<UserLink user={block.target} avatar badges />
|
||||
<Button size="square-md" on:click={() => action(block)}>
|
||||
<Icon src={Trash} mini size="16" slot="prefix" />
|
||||
<Button
|
||||
title="Unblock"
|
||||
size="square-md"
|
||||
on:click={() => action(block)}
|
||||
>
|
||||
<Icon src={XMark} mini size="16" slot="prefix" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
@@ -78,43 +169,16 @@
|
||||
<Placeholder
|
||||
description="Go to a user's profile and click 'block' to stop seeing posts and
|
||||
comments from them."
|
||||
title="No user blocks"
|
||||
icon={Check}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if data.community_blocks?.length > 0}
|
||||
<div>
|
||||
<SectionTitle>Communities</SectionTitle>
|
||||
<EditableList let:action on:action={(i) => unblockCommunity(i.detail)}>
|
||||
{#each data.community_blocks as block (block.community.id)}
|
||||
<div
|
||||
class="flex flex-row gap-4 items-center py-4 justify-between"
|
||||
animate:flip={{ duration: 250 }}
|
||||
out:slide|local={{ axis: 'y' }}
|
||||
>
|
||||
<CommunityLink community={block.community} avatar />
|
||||
<Button size="square-md" on:click={() => action(block)}>
|
||||
<Icon src={Trash} mini size="16" slot="prefix" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
</EditableList>
|
||||
</div>
|
||||
{:else}
|
||||
<Placeholder
|
||||
description="Go to a community's page and click 'block' to stop seeing posts and
|
||||
comments from it."
|
||||
title="No community blocks"
|
||||
icon={Check}
|
||||
title="No blocked users"
|
||||
center={false}
|
||||
/>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="my-auto">
|
||||
<Placeholder
|
||||
description="Go to a community or user's page to stop seeing submissions from it."
|
||||
description="Go to a community or user's page and click 'block' to stop seeing submissions from it."
|
||||
title="No blocks"
|
||||
icon={Check}
|
||||
center={false}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
Reference in new issue
Block a user