feat: add post hiding
This commit is contained in:
1 parent
dae4f1fe73
commit
ac3222d987
12 files changed
+68
-11
No files matched your search
+1
-1
@@ -24,7 +24,7 @@
|
|||||||
"@vite-pwa/sveltekit": "^0.3.0",
|
"@vite-pwa/sveltekit": "^0.3.0",
|
||||||
"autoprefixer": "^10.4.16",
|
"autoprefixer": "^10.4.16",
|
||||||
"jsdom": "^22.1.0",
|
"jsdom": "^22.1.0",
|
||||||
"lemmy-js-client": "^0.19.0-rc.13",
|
"lemmy-js-client": "latest",
|
||||||
"markdown-it-container": "^3.0.0",
|
"markdown-it-container": "^3.0.0",
|
||||||
"markdown-it-sub": "^1.0.0",
|
"markdown-it-sub": "^1.0.0",
|
||||||
"markdown-it-sup": "^1.0.0",
|
"markdown-it-sup": "^1.0.0",
|
||||||
|
|||||||
@@ -107,7 +107,7 @@
|
|||||||
<PostBody body={post.post.body} {view} style="grid-area: body" />
|
<PostBody body={post.post.body} {view} style="grid-area: body" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if actions}
|
{#if actions}
|
||||||
<PostActions bind:post style="grid-area: actions;" />
|
<PostActions on:hide bind:post style="grid-area: actions;" />
|
||||||
{:else if view == 'compact'}
|
{:else if view == 'compact'}
|
||||||
<div class="flex flex-row items-center gap-2 text-sm">
|
<div class="flex flex-row items-center gap-2 text-sm">
|
||||||
<Badge>
|
<Badge>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PostView } from 'lemmy-js-client'
|
import type { PostView } from 'lemmy-js-client'
|
||||||
import PostVote from './PostVote.svelte'
|
import PostVote from './PostVote.svelte'
|
||||||
import { getInstance } from '$lib/lemmy.js'
|
import { getInstance, site } from '$lib/lemmy.js'
|
||||||
import {
|
import {
|
||||||
ArrowTopRightOnSquare,
|
ArrowTopRightOnSquare,
|
||||||
Bookmark,
|
Bookmark,
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
Share,
|
Share,
|
||||||
Trash,
|
Trash,
|
||||||
UserCircle,
|
UserCircle,
|
||||||
|
XMark,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
@@ -53,10 +54,12 @@
|
|||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { text } from '$lib/components/translate/translation'
|
import { text } from '$lib/components/translate/translation'
|
||||||
import Translation from '$lib/components/translate/Translation.svelte'
|
import Translation from '$lib/components/translate/Translation.svelte'
|
||||||
|
import { hidePost } from './helpers'
|
||||||
|
import { feature } from '$lib/version'
|
||||||
|
|
||||||
export let post: PostView
|
export let post: PostView
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ edit: PostView }>()
|
const dispatcher = createEventDispatcher<{ edit: PostView; hide: boolean }>()
|
||||||
|
|
||||||
let editing = false
|
let editing = false
|
||||||
let saving = false
|
let saving = false
|
||||||
@@ -312,6 +315,28 @@
|
|||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile.user?.local_user_view.person.id != post.creator.id}
|
{#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">
|
<MenuButton on:click={() => report(post)} color="danger-subtle">
|
||||||
<Icon src={Flag} width={16} mini slot="prefix" />
|
<Icon src={Flag} width={16} mini slot="prefix" />
|
||||||
{$t('moderation.report')}
|
{$t('moderation.report')}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@
|
|||||||
</Placeholder>
|
</Placeholder>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{: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)}
|
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
|
||||||
<li
|
<li
|
||||||
in:fly|global={{
|
in:fly|global={{
|
||||||
@@ -120,6 +120,9 @@
|
|||||||
viewPost != post.post.id
|
viewPost != post.post.id
|
||||||
? ''
|
? ''
|
||||||
: ''}"
|
: ''}"
|
||||||
|
on:hide={() => {
|
||||||
|
combinedPosts = combinedPosts.toSpliced(index, 1)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
slot="badges"
|
slot="badges"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getInstance } from '$lib/lemmy.js'
|
import { client, getInstance } from '$lib/lemmy.js'
|
||||||
import type { View } from '$lib/settings'
|
import type { View } from '$lib/settings'
|
||||||
import { isImage, isVideo } from '$lib/ui/image'
|
import { isImage, isVideo } from '$lib/ui/image'
|
||||||
import { findClosestNumber } from '$lib/util'
|
import { findClosestNumber } from '$lib/util'
|
||||||
@@ -74,3 +74,16 @@ export const iframeType = (post: Post): IframeType => {
|
|||||||
if (isYoutubeLink(post.url)) return 'youtube'
|
if (isYoutubeLink(post.url)) return 'youtube'
|
||||||
return 'none'
|
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
|
||||||
|
}
|
||||||
@@ -387,6 +387,8 @@
|
|||||||
"actions": "Actions",
|
"actions": "Actions",
|
||||||
"markRead": "Mark as Read",
|
"markRead": "Mark as Read",
|
||||||
"markUnread": "Mark as Unread",
|
"markUnread": "Mark as Unread",
|
||||||
|
"hide": "Hide",
|
||||||
|
"unhide": "Unhide",
|
||||||
"translate": "Translate",
|
"translate": "Translate",
|
||||||
"share": "Share",
|
"share": "Share",
|
||||||
"crosspost": "Crosspost",
|
"crosspost": "Crosspost",
|
||||||
@@ -629,6 +631,10 @@
|
|||||||
},
|
},
|
||||||
"lemmy": {
|
"lemmy": {
|
||||||
"title": "Lemmy",
|
"title": "Lemmy",
|
||||||
|
"showHiddenPosts": {
|
||||||
|
"title": "Show hidden posts",
|
||||||
|
"description": "Show the posts you've manually hidden."
|
||||||
|
},
|
||||||
"compactFeatured": {
|
"compactFeatured": {
|
||||||
"title": "Compact featured posts",
|
"title": "Compact featured posts",
|
||||||
"description": "Make featured posts more compact"
|
"description": "Make featured posts more compact"
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ interface Settings {
|
|||||||
posts: {
|
posts: {
|
||||||
deduplicateEmbed: boolean
|
deduplicateEmbed: boolean
|
||||||
compactFeatured: boolean
|
compactFeatured: boolean
|
||||||
|
showHidden: boolean
|
||||||
}
|
}
|
||||||
language: string | null
|
language: string | null
|
||||||
translator: string | undefined
|
translator: string | undefined
|
||||||
@@ -141,6 +142,7 @@ export const defaultSettings: Settings = {
|
|||||||
posts: {
|
posts: {
|
||||||
deduplicateEmbed: toBool(env.PUBLIC_DEDUPLICATE_EMBED) ?? true,
|
deduplicateEmbed: toBool(env.PUBLIC_DEDUPLICATE_EMBED) ?? true,
|
||||||
compactFeatured: toBool(env.PUBLIC_COMPACT_FEATURED) ?? true,
|
compactFeatured: toBool(env.PUBLIC_COMPACT_FEATURED) ?? true,
|
||||||
|
showHidden: false,
|
||||||
},
|
},
|
||||||
language: null,
|
language: null,
|
||||||
translator: undefined,
|
translator: undefined,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const FEATURES = {
|
|||||||
cursorPagination: '0.19.0',
|
cursorPagination: '0.19.0',
|
||||||
newTotp: '0.19.0',
|
newTotp: '0.19.0',
|
||||||
blockInstances: '0.19.0',
|
blockInstances: '0.19.0',
|
||||||
|
hidePosts: '0.19.4',
|
||||||
}
|
}
|
||||||
|
|
||||||
type Feature = keyof typeof FEATURES
|
type Feature = keyof typeof FEATURES
|
||||||
|
|||||||
+6
-5
@@ -11,12 +11,12 @@ export async function load({ url, fetch }) {
|
|||||||
const prevCursor = url.searchParams.get('prevCursor') as string | undefined
|
const prevCursor = url.searchParams.get('prevCursor') as string | undefined
|
||||||
const page = Number(url.searchParams.get('page')) || undefined
|
const page = Number(url.searchParams.get('page')) || undefined
|
||||||
|
|
||||||
|
const settings = get(userSettings)
|
||||||
|
|
||||||
const sort: SortType =
|
const sort: SortType =
|
||||||
(url.searchParams.get('sort') as SortType) ||
|
(url.searchParams.get('sort') as SortType) || settings.defaultSort.sort
|
||||||
get(userSettings).defaultSort.sort
|
|
||||||
const listingType: ListingType =
|
const listingType: ListingType =
|
||||||
(url.searchParams.get('type') as ListingType) ||
|
(url.searchParams.get('type') as ListingType) || settings.defaultSort.feed
|
||||||
get(userSettings).defaultSort.feed
|
|
||||||
|
|
||||||
const posts = await getClient(undefined, fetch).getPosts({
|
const posts = await getClient(undefined, fetch).getPosts({
|
||||||
limit: 20,
|
limit: 20,
|
||||||
@@ -24,6 +24,7 @@ export async function load({ url, fetch }) {
|
|||||||
sort: sort,
|
sort: sort,
|
||||||
type_: listingType,
|
type_: listingType,
|
||||||
page_cursor: cursor,
|
page_cursor: cursor,
|
||||||
|
show_hidden: settings.posts.showHidden,
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -41,6 +42,6 @@ export async function load({ url, fetch }) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
error(500, {
|
error(500, {
|
||||||
message: 'Failed to fetch homepage.',
|
message: 'Failed to fetch homepage.',
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,7 @@ export async function load({ params, fetch, url }) {
|
|||||||
page: page,
|
page: page,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
page_cursor: cursor,
|
page_cursor: cursor,
|
||||||
|
show_hidden: get(userSettings).posts.showHidden,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,6 +290,11 @@
|
|||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
<Section title={$t('settings.lemmy.title')}>
|
<Section title={$t('settings.lemmy.title')}>
|
||||||
|
<ToggleSetting
|
||||||
|
bind:checked={$userSettings.posts.showHidden}
|
||||||
|
title={$t('settings.lemmy.showHiddenPosts.title')}
|
||||||
|
description={$t('settings.lemmy.showHiddenPosts.description')}
|
||||||
|
/>
|
||||||
<ToggleSetting
|
<ToggleSetting
|
||||||
bind:checked={$userSettings.posts.compactFeatured}
|
bind:checked={$userSettings.posts.compactFeatured}
|
||||||
title={$t('settings.lemmy.compactFeatured.title')}
|
title={$t('settings.lemmy.compactFeatured.title')}
|
||||||
|
|||||||
Reference in new issue
Block a user