feat: add post hiding

This commit is contained in:
Xylight committed 2024-06-08 15:37:01 -07:00
1 parent dae4f1fe73
commit ac3222d987
12 files changed
+69 -12

No files matched your search

+1 -1
View File
@@ -107,7 +107,7 @@
<PostBody body={post.post.body} {view} style="grid-area: body" />
{/if}
{#if actions}
<PostActions bind:post style="grid-area: actions;" />
<PostActions on:hide bind:post style="grid-area: actions;" />
{:else if view == 'compact'}
<div class="flex flex-row items-center gap-2 text-sm">
<Badge>
@@ -1,7 +1,7 @@
<script lang="ts">
import type { PostView } from 'lemmy-js-client'
import PostVote from './PostVote.svelte'
import { getInstance } from '$lib/lemmy.js'
import { getInstance, site } from '$lib/lemmy.js'
import {
ArrowTopRightOnSquare,
Bookmark,
@@ -21,6 +21,7 @@
Share,
Trash,
UserCircle,
XMark,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { createEventDispatcher } from 'svelte'
@@ -53,10 +54,12 @@
import { t } from '$lib/translations'
import { text } from '$lib/components/translate/translation'
import Translation from '$lib/components/translate/Translation.svelte'
import { hidePost } from './helpers'
import { feature } from '$lib/version'
export let post: PostView
const dispatcher = createEventDispatcher<{ edit: PostView }>()
const dispatcher = createEventDispatcher<{ edit: PostView; hide: boolean }>()
let editing = false
let saving = false
@@ -312,6 +315,28 @@
</MenuButton>
{/if}
{#if $profile.user?.local_user_view.person.id != post.creator.id}
{#if feature('hidePosts', $site?.version)}
<MenuButton
on:click={async () => {
if (!$profile?.jwt) return
const hidden = await hidePost(
post.post.id,
!post.hidden,
$profile?.jwt
)
post.hidden = hidden
if (hidden) {
dispatcher('hide', hidden)
}
}}
color="danger-subtle"
>
<Icon slot="prefix" src={XMark} size="16" mini />
{post.hidden
? $t('post.actions.more.unhide')
: $t('post.actions.more.hide')}
</MenuButton>
{/if}
<MenuButton on:click={() => report(post)} color="danger-subtle">
<Icon src={Flag} width={16} mini slot="prefix" />
{$t('moderation.report')}
@@ -98,7 +98,7 @@
</Placeholder>
</div>
{:else}
{#each combinedPosts as post, index}
{#each combinedPosts as post, index (post.post.id)}
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
<li
in:fly|global={{
@@ -120,6 +120,9 @@
viewPost != post.post.id
? ''
: ''}"
on:hide={() => {
combinedPosts = combinedPosts.toSpliced(index, 1)
}}
>
<button
slot="badges"
+14 -1
View File
@@ -1,4 +1,4 @@
import { getInstance } from '$lib/lemmy.js'
import { client, getInstance } from '$lib/lemmy.js'
import type { View } from '$lib/settings'
import { isImage, isVideo } from '$lib/ui/image'
import { findClosestNumber } from '$lib/util'
@@ -74,3 +74,16 @@ export const iframeType = (post: Post): IframeType => {
if (isYoutubeLink(post.url)) return 'youtube'
return 'none'
}
export async function hidePost(
id: number,
hide: boolean,
jwt: string
): Promise<boolean> {
const res = await client({ auth: jwt }).hidePost({
hide: hide,
post_ids: [id],
})
return hide
}