feat: add block page
This commit is contained in:
1 parent
e8f7501c62
commit
661d9b1003
5 files changed
+86
-3
No files matched your search
@@ -0,0 +1 @@
|
||||
<slot />
|
||||
@@ -0,0 +1,7 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load() {
|
||||
return (await getClient().getSite({ auth: get(profile)?.jwt })).my_user
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<script lang="ts">
|
||||
import type { CommunityBlockView, 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 Button from '$lib/components/input/Button.svelte'
|
||||
import { Icon, Trash } from 'svelte-hero-icons'
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
|
||||
// sveltekit doesn't feel like making types work right now
|
||||
export let data: PageData & {
|
||||
person_blocks: PersonBlockView[]
|
||||
community_blocks: CommunityBlockView[]
|
||||
}
|
||||
|
||||
async function unblockUser(item: PersonBlockView) {
|
||||
if (!$profile?.jwt) return
|
||||
|
||||
data.person_blocks.splice(
|
||||
data.person_blocks.findIndex((i) => i.target.id == item.target.id),
|
||||
1
|
||||
)
|
||||
// hack to get reactivity working
|
||||
data.person_blocks = data.person_blocks
|
||||
|
||||
await getClient().blockPerson({
|
||||
auth: $profile.jwt,
|
||||
block: false,
|
||||
person_id: item.target.id,
|
||||
})
|
||||
}
|
||||
|
||||
async function unblockCommunity(item: CommunityBlockView) {
|
||||
if (!$profile?.jwt) return
|
||||
|
||||
data.community_blocks.splice(
|
||||
data.community_blocks.findIndex(
|
||||
(i) => i.community.id == item.community.id
|
||||
),
|
||||
1
|
||||
)
|
||||
|
||||
// hack to get reactivity working
|
||||
data.community_blocks = data.community_blocks
|
||||
|
||||
await getClient().blockCommunity({
|
||||
auth: $profile.jwt,
|
||||
block: false,
|
||||
community_id: item.community.id,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<SectionTitle>Users</SectionTitle>
|
||||
<EditableList let:action on:action={(i) => unblockUser(i.detail)}>
|
||||
{#each data.person_blocks as block}
|
||||
<div class="flex flex-row gap-4 items-center py-4 justify-between">
|
||||
<UserLink user={block.target} avatar badges />
|
||||
<Button size="square-md" on:click={() => action(block.target)}>
|
||||
<Icon src={Trash} mini size="16" slot="icon" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
</EditableList>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<SectionTitle>Communities</SectionTitle>
|
||||
<EditableList let:action on:action={(i) => unblockCommunity(i.detail)}>
|
||||
{#each data.community_blocks as block}
|
||||
<div class="flex flex-row gap-4 items-center py-4 justify-between">
|
||||
<CommunityLink community={block.community} avatar />
|
||||
<Button size="square-md" on:click={() => action(block.community)}>
|
||||
<Icon src={Trash} mini size="16" slot="icon" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
</EditableList>
|
||||
</div>
|
||||
@@ -0,0 +1,94 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { SaveUserSettings } from 'lemmy-js-client'
|
||||
|
||||
export let data
|
||||
|
||||
let formData: Omit<SaveUserSettings, 'auth'> | undefined = {
|
||||
...data.local_user_view?.local_user,
|
||||
...data.local_user_view?.person,
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!formData || !$profile?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
const res = await getClient().saveUserSettings({
|
||||
auth: $profile.jwt,
|
||||
...formData,
|
||||
})
|
||||
toast({
|
||||
content: 'Saved your user settings.',
|
||||
type: 'success',
|
||||
})
|
||||
if (res.verify_email_sent) {
|
||||
toast({
|
||||
content: 'A verification email was sent.',
|
||||
type: 'info',
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
loading = false
|
||||
}
|
||||
|
||||
let loading = false
|
||||
</script>
|
||||
|
||||
<form class="flex flex-col gap-4 h-full" on:submit|preventDefault={save}>
|
||||
<h1 class="font-bold text-2xl">User settings</h1>
|
||||
{#if data.local_user_view?.local_user && formData}
|
||||
<TextInput
|
||||
label="Display name"
|
||||
bind:value={formData.display_name}
|
||||
placeholder="Optional"
|
||||
/>
|
||||
<MarkdownEditor
|
||||
images={false}
|
||||
bind:value={formData.bio}
|
||||
label="Bio"
|
||||
previewButton
|
||||
/>
|
||||
<TextInput label="Email" bind:value={formData.email} />
|
||||
<TextInput
|
||||
label="Matrix User"
|
||||
bind:value={formData.matrix_user_id}
|
||||
placeholder="@user:example.com"
|
||||
/>
|
||||
<Checkbox bind:checked={formData.show_nsfw}>Show NSFW content</Checkbox>
|
||||
<Checkbox bind:checked={formData.show_scores}>Show Scores</Checkbox>
|
||||
<Checkbox bind:checked={formData.bot_account}>Bot Account</Checkbox>
|
||||
<Checkbox bind:checked={formData.show_bot_accounts}>
|
||||
Show Bot Accounts
|
||||
</Checkbox>
|
||||
<Checkbox bind:checked={formData.show_read_posts}>Show Read Posts</Checkbox>
|
||||
|
||||
<Button
|
||||
submit
|
||||
size="lg"
|
||||
color="primary"
|
||||
class="mt-auto"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
{:else}
|
||||
<Card cardColor="warning" class="p-5">
|
||||
The API didn't return your user settings.
|
||||
</Card>
|
||||
{/if}
|
||||
</form>
|
||||
Reference in new issue
Block a user