impr: switch to refactored feed handler (#654)
* impr: use refactored feed handler for main & community * refactor: re-add post preloading to feed handler * fix: remove unused setting & improve consistency of postmedia compact
This commit is contained in:
1 parent
2d01124bbf
commit
9460eec7e1
26 files changed
+489
-467
No files matched your search
@@ -1,6 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import {
|
||||
mediaType,
|
||||
parseTags,
|
||||
Post,
|
||||
PostActions,
|
||||
postLink,
|
||||
PostMedia,
|
||||
PostMeta,
|
||||
} from '$lib/components/lemmy/post'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
@@ -8,10 +18,7 @@
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { resumables } from '$lib/lemmy/item.js'
|
||||
import { postFeeds } from '$lib/lemmy/postfeed.svelte'
|
||||
import { ReactiveState } from '$lib/util.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { Button, toast } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
@@ -24,49 +31,26 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
import CommentProvider from './CommentProvider.svelte'
|
||||
import {
|
||||
mediaType,
|
||||
parseTags,
|
||||
Post,
|
||||
PostActions,
|
||||
postLink,
|
||||
PostMedia,
|
||||
PostMeta,
|
||||
} from '$lib/components/lemmy/post'
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
onMount(() => {
|
||||
data.meta.then((i) => data.post == i.post_view)
|
||||
|
||||
resumables.add({
|
||||
name: data.post.value.post_view.post.name,
|
||||
name: data.post.post.name,
|
||||
type: 'post',
|
||||
url: page.url.toString(),
|
||||
avatar: data.post.value.post_view.post.thumbnail_url,
|
||||
avatar: data.post.post.thumbnail_url,
|
||||
})
|
||||
|
||||
if (
|
||||
!(data.post.value.post_view.read && settings.markPostsAsRead) &&
|
||||
profile.current?.jwt
|
||||
) {
|
||||
if (!(data.post.read && settings.markPostsAsRead) && profile.current?.jwt) {
|
||||
client()
|
||||
.markPostAsRead({
|
||||
read: true,
|
||||
post_ids: [data.post.value.post_view.post.id],
|
||||
post_ids: [data.post.post.id],
|
||||
})
|
||||
.then(() => (data.post.value.post_view.read = true))
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
data.post.value.meta.then(
|
||||
(res) => (data.post.value.post_view = res.post_view),
|
||||
)
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (data.cachedFeed && data.post.value.post_view) {
|
||||
const { id, index } = data.cachedFeed!
|
||||
postFeeds.value[id].data.posts.posts[index] = data.post.value.post_view
|
||||
.then(() => (data.post.read = true))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -74,59 +58,48 @@
|
||||
|
||||
async function reloadComments() {
|
||||
loading = true
|
||||
data.comments.value = client().getComments({
|
||||
page: 1,
|
||||
limit: 25,
|
||||
type_: 'All',
|
||||
post_id: data.post.value.post_view.post.id,
|
||||
sort: settings.defaultSort.comments,
|
||||
max_depth: data.post.value.post_view.counts.comments > 100 ? 1 : 3,
|
||||
})
|
||||
data.comments = client()
|
||||
.getComments({
|
||||
page: 1,
|
||||
limit: 25,
|
||||
type_: 'All',
|
||||
post_id: data.post.post.id,
|
||||
sort: settings.defaultSort.comments,
|
||||
max_depth: data.post.counts.comments > 100 ? 1 : 3,
|
||||
})
|
||||
.then((i) => i.comments)
|
||||
loading = false
|
||||
data.thread.value.singleThread = false
|
||||
data.thread.singleThread = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>
|
||||
{data.post.value.post_view.community.title} | {data.post.value.post_view
|
||||
.post.name}
|
||||
{data.post.community.title} | {data.post.post.name}
|
||||
</title>
|
||||
<meta property="og:title" content={data.post.value.post_view.post.name} />
|
||||
{#if !data.post.value.post_view.post.local}
|
||||
<meta property="og:title" content={data.post.post.name} />
|
||||
{#if !data.post.post.local}
|
||||
<meta name="robots" content="noindex, follow" />
|
||||
{/if}
|
||||
<link rel="canonical" href={data.post.value.post_view.post.ap_id} />
|
||||
{#if data.post.value.post_view.post.body}
|
||||
<meta
|
||||
property="description"
|
||||
content={data.post.value.post_view.post.body.slice(0, 500)}
|
||||
/>
|
||||
<link rel="canonical" href={data.post.post.ap_id} />
|
||||
{#if data.post.post.body}
|
||||
<meta property="description" content={data.post.post.body.slice(0, 500)} />
|
||||
<meta
|
||||
property="og:description"
|
||||
content={data.post.value.post_view.post.body.slice(0, 500)}
|
||||
content={data.post.post.body.slice(0, 500)}
|
||||
/>
|
||||
<meta
|
||||
property="twitter:description"
|
||||
content={data.post.value.post_view.post.body.slice(0, 500)}
|
||||
content={data.post.post.body.slice(0, 500)}
|
||||
/>
|
||||
{/if}
|
||||
<meta property="og:url" content={page.url.toString()} />
|
||||
{#if mediaType(data.post.value.post_view.post.url) == 'image'}
|
||||
<meta property="og:image" content={data.post.value.post_view.post.url} />
|
||||
<meta
|
||||
property="twitter:card"
|
||||
content={data.post.value.post_view.post.url}
|
||||
/>
|
||||
{:else if data.post.value.post_view.post.thumbnail_url}
|
||||
<meta
|
||||
property="og:image"
|
||||
content={data.post.value.post_view.post.thumbnail_url}
|
||||
/>
|
||||
<meta
|
||||
property="twitter:card"
|
||||
content={data.post.value.post_view.post.thumbnail_url}
|
||||
/>
|
||||
{#if mediaType(data.post.post.url) == 'image'}
|
||||
<meta property="og:image" content={data.post.post.url} />
|
||||
<meta property="twitter:card" content={data.post.post.url} />
|
||||
{:else if data.post.post.thumbnail_url}
|
||||
<meta property="og:image" content={data.post.post.thumbnail_url} />
|
||||
<meta property="twitter:card" content={data.post.post.thumbnail_url} />
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
@@ -134,54 +107,52 @@
|
||||
<header class="flex flex-col gap-2">
|
||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||
<PostMeta
|
||||
community={data.post.value.post_view.community}
|
||||
user={data.post.value.post_view.creator}
|
||||
community={data.post.community}
|
||||
user={data.post.creator}
|
||||
subscribed={profile.current.user?.follows.find(
|
||||
(i) => i.community.id == data.post.value.post_view.community.id,
|
||||
(i) => i.community.id == data.post.community.id,
|
||||
)
|
||||
? 'Subscribed'
|
||||
: 'NotSubscribed'}
|
||||
badges={{
|
||||
deleted: data.post.value.post_view.post.deleted,
|
||||
removed: data.post.value.post_view.post.removed,
|
||||
locked: data.post.value.post_view.post.locked,
|
||||
deleted: data.post.post.deleted,
|
||||
removed: data.post.post.removed,
|
||||
locked: data.post.post.locked,
|
||||
featured:
|
||||
data.post.value.post_view.post.featured_community ||
|
||||
data.post.value.post_view.post.featured_local,
|
||||
nsfw: data.post.value.post_view.post.nsfw,
|
||||
saved: data.post.value.post_view.saved,
|
||||
admin: data.post.value.post_view.creator_is_admin,
|
||||
moderator: data.post.value.post_view.creator_is_moderator,
|
||||
data.post.post.featured_community || data.post.post.featured_local,
|
||||
nsfw: data.post.post.nsfw,
|
||||
saved: data.post.saved,
|
||||
admin: data.post.creator_is_admin,
|
||||
moderator: data.post.creator_is_moderator,
|
||||
}}
|
||||
published={publishedToDate(data.post.value.post_view.post.published)}
|
||||
edited={data.post.value.post_view.post.updated}
|
||||
title={data.post.value.post_view.post.name}
|
||||
published={publishedToDate(data.post.post.published)}
|
||||
edited={data.post.post.updated}
|
||||
title={data.post.post.name}
|
||||
style="width: max-content;"
|
||||
tags={parseTags(data.post.value.post_view.post.name).tags}
|
||||
tags={parseTags(data.post.post.name).tags}
|
||||
/>
|
||||
</div>
|
||||
<h1 class="font-medium text-xl leading-5">
|
||||
<Markdown
|
||||
source={parseTags(data.post.value.post_view.post.name).title ??
|
||||
data.post.value.post_view.post.name}
|
||||
source={parseTags(data.post.post.name).title ?? data.post.post.name}
|
||||
inline
|
||||
/>
|
||||
</h1>
|
||||
</header>
|
||||
<PostMedia
|
||||
type={mediaType(data.post.value.post_view.post.url)}
|
||||
post={data.post.value.post_view.post}
|
||||
type={mediaType(data.post.post.url)}
|
||||
post={data.post.post}
|
||||
opened
|
||||
view="cozy"
|
||||
/>
|
||||
{#if data.post.value.post_view.post.body}
|
||||
{#if data.post.post.body}
|
||||
<div class="text-base text-slate-800 dark:text-zinc-300 leading-normal">
|
||||
<Markdown source={data.post.value.post_view.post.body} />
|
||||
<Markdown source={data.post.post.body} />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="w-full relative">
|
||||
<PostActions
|
||||
post={data.post.value.post_view}
|
||||
bind:post={data.post}
|
||||
onedit={() =>
|
||||
toast({
|
||||
content: 'The post was edited successfully.',
|
||||
@@ -189,7 +160,7 @@
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
{#await data.post.value.meta then meta}
|
||||
{#await data.meta then meta}
|
||||
{@const crossposts = meta.cross_posts}
|
||||
{#if crossposts?.length > 0}
|
||||
<Expandable class="text-base mt-2 w-full cursor-pointer">
|
||||
@@ -216,8 +187,8 @@
|
||||
{/if}
|
||||
{/await}
|
||||
</article>
|
||||
{#await data.comments.value then comments}
|
||||
{#if data.thread.value.showContext || data.thread.value.singleThread}
|
||||
{#await data.comments then comments}
|
||||
{#if data.thread.showContext || data.thread.singleThread}
|
||||
<div
|
||||
class="sticky mx-auto z-50 max-w-md min-w-0 flex flex-col items-center overflow-auto gap-1
|
||||
bg-slate-50/50 dark:bg-zinc-900/50 backdrop-blur-xl border border-slate-200/50 dark:border-zinc-800/50
|
||||
@@ -228,17 +199,17 @@
|
||||
rounding="pill"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
href={data.thread.value.showContext
|
||||
href={data.thread.showContext
|
||||
? `/comment/${
|
||||
// split first comment path to get 5 before
|
||||
comments.comments[0].comment.path.split('.').slice(-5)[1]
|
||||
comments[0].comment.path.split('.').slice(-5)[1]
|
||||
}`
|
||||
: data.thread.value.singleThread
|
||||
? postLink(data.post.value.post_view.post)
|
||||
: data.thread.singleThread
|
||||
? postLink(data.post.post)
|
||||
: undefined}
|
||||
class="hover:bg-white/50 dark:hover:bg-zinc-800/30"
|
||||
>
|
||||
{data.thread.value.showContext
|
||||
{data.thread.showContext
|
||||
? $t('routes.post.thread.context')
|
||||
: $t('routes.post.thread.allComments')}
|
||||
{#snippet suffix()}
|
||||
@@ -254,7 +225,7 @@
|
||||
{$t('routes.post.commentCount')}
|
||||
{#snippet action()}
|
||||
<span class="font-bold">
|
||||
<FormattedNumber number={data.post.value.post_view.counts.comments} />
|
||||
<FormattedNumber number={data.post.counts.comments} />
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
@@ -266,7 +237,7 @@
|
||||
</Button>
|
||||
</noscript>
|
||||
{/if}
|
||||
{#await data.comments.value}
|
||||
{#await data.comments}
|
||||
<div class="flex flex-col gap-4">
|
||||
{#each new Array(10) as _, index}
|
||||
{_}
|
||||
@@ -286,17 +257,16 @@
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:then passedComments}
|
||||
{@const comments = new ReactiveState(passedComments)}
|
||||
{:then comments}
|
||||
<CommentProvider
|
||||
comments={comments.value}
|
||||
post={data.post.value.post_view}
|
||||
focus={data.thread.value.focus}
|
||||
{comments}
|
||||
post={data.post}
|
||||
focus={data.thread.focus}
|
||||
onupdate={reloadComments}
|
||||
bind:sort={data.commentSort.value}
|
||||
bind:sort={data.params.comments.sort}
|
||||
virtualize={!page.url.searchParams.get('noVirtualize')}
|
||||
/>
|
||||
{#if comments.value.comments.length == 0}
|
||||
{#if comments.length == 0}
|
||||
<Placeholder
|
||||
icon={ChatBubbleLeftRight}
|
||||
title={$t('routes.post.emptyComments.title')}
|
||||
@@ -304,13 +274,12 @@
|
||||
></Placeholder>
|
||||
{/if}
|
||||
{/await}
|
||||
{#if data.post.value.post_view.counts.comments > 5}
|
||||
{#if data.post.counts.comments > 5}
|
||||
<EndPlaceholder>
|
||||
{$t('routes.post.commentCount')}
|
||||
|
||||
{#snippet action()}
|
||||
<span class="text-black dark:text-white font-bold">
|
||||
{data.post.value.post_view.counts.comments}
|
||||
{data.post.counts.comments}
|
||||
</span>
|
||||
<Button
|
||||
color="tertiary"
|
||||
|
||||
Reference in new issue
Block a user