Merge pull request #628 from Xyphyn/post-feed-cache
impr: use posts from post feeds to preload
This commit is contained in:
4 files changed
+318
-236
No files matched your search
@@ -91,6 +91,7 @@
|
|||||||
MenuButton,
|
MenuButton,
|
||||||
modal,
|
modal,
|
||||||
removeToast,
|
removeToast,
|
||||||
|
Spinner,
|
||||||
toast,
|
toast,
|
||||||
} from 'mono-svelte'
|
} from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
@@ -111,29 +112,28 @@
|
|||||||
subscribing: false,
|
subscribing: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
async function subscribe() {
|
async function subscribe(community: CommunityView) {
|
||||||
if (!profile.current?.jwt) return
|
if (!profile.current?.jwt) return
|
||||||
loading.subscribing = true
|
loading.subscribing = true
|
||||||
const subscribed =
|
const subscribed =
|
||||||
community_view.subscribed == 'Subscribed' ||
|
community.subscribed == 'Subscribed' || community.subscribed == 'Pending'
|
||||||
community_view.subscribed == 'Pending'
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().followCommunity({
|
await getClient().followCommunity({
|
||||||
community_id: community_view.community.id,
|
community_id: community.community.id,
|
||||||
follow: !subscribed,
|
follow: !subscribed,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({ content: errorMessage(err as string), type: 'error' })
|
toast({ content: errorMessage(err as string), type: 'error' })
|
||||||
}
|
}
|
||||||
|
|
||||||
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
|
community.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
|
||||||
addSubscription(community_view.community, !subscribed)
|
addSubscription(community.community, !subscribed)
|
||||||
|
|
||||||
loading.subscribing = false
|
loading.subscribing = false
|
||||||
}
|
}
|
||||||
interface Props {
|
interface Props {
|
||||||
community_view: CommunityView
|
community_view: CommunityView | Promise<CommunityView>
|
||||||
moderators?: CommunityModeratorView[]
|
moderators?: CommunityModeratorView[]
|
||||||
class?: string
|
class?: string
|
||||||
}
|
}
|
||||||
@@ -145,200 +145,207 @@
|
|||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
{#await community_view}
|
||||||
class={[
|
<div class="w-full h-full grid place-items-center">
|
||||||
'min-w-full pt-0 text-slate-600 dark:text-zinc-400 flex flex-col gap-4 text-sm',
|
<Spinner width={24} />
|
||||||
clazz,
|
</div>
|
||||||
]}
|
{:then community_view}
|
||||||
>
|
<div
|
||||||
<Entity
|
class={[
|
||||||
name={community_view.community.title}
|
'min-w-full pt-0 text-slate-600 dark:text-zinc-400 flex flex-col gap-4 text-sm',
|
||||||
label="!{fullCommunityName(
|
clazz,
|
||||||
community_view.community.name,
|
]}
|
||||||
community_view.community.actor_id,
|
|
||||||
)}"
|
|
||||||
>
|
>
|
||||||
{#snippet customIcon()}
|
<Entity
|
||||||
<Avatar
|
name={community_view.community.title}
|
||||||
width={32}
|
label="!{fullCommunityName(
|
||||||
url={community_view.community.icon}
|
community_view.community.name,
|
||||||
alt={community_view.community.name}
|
community_view.community.actor_id,
|
||||||
circle={false}
|
)}"
|
||||||
/>
|
>
|
||||||
{/snippet}
|
{#snippet customIcon()}
|
||||||
</Entity>
|
<Avatar
|
||||||
|
width={32}
|
||||||
<div class="flex flex-col gap-1">
|
url={community_view.community.icon}
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
alt={community_view.community.name}
|
||||||
<Expandable bind:open={settings.expand.about} class="pt-0!">
|
circle={false}
|
||||||
{#snippet title()}
|
|
||||||
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
|
||||||
{$t('cards.site.about')}
|
|
||||||
<hr
|
|
||||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
{/snippet}
|
|
||||||
<Markdown source={community_view.community.description} />
|
|
||||||
</Expandable>
|
|
||||||
|
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
|
||||||
<Expandable bind:open={settings.expand.stats}>
|
|
||||||
{#snippet title()}
|
|
||||||
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
|
||||||
{$t('cards.site.stats')}
|
|
||||||
<hr
|
|
||||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
{/snippet}
|
|
||||||
<div class="flex flex-row gap-4 flex-wrap">
|
|
||||||
<LabelStat
|
|
||||||
label={$t('cards.community.members')}
|
|
||||||
content={community_view.counts.subscribers.toString()}
|
|
||||||
formatted
|
|
||||||
/>
|
/>
|
||||||
<LabelStat
|
{/snippet}
|
||||||
label={$t('content.posts')}
|
</Entity>
|
||||||
content={community_view.counts.posts.toString()}
|
|
||||||
formatted
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Expandable>
|
|
||||||
|
|
||||||
{#if moderators && moderators.length > 0}
|
<div class="flex flex-col gap-1">
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
<Expandable bind:open={settings.expand.team}>
|
<Expandable bind:open={settings.expand.about} class="pt-0!">
|
||||||
{#snippet title()}
|
{#snippet title()}
|
||||||
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||||
{$t('cards.community.moderators')}
|
{$t('cards.site.about')}
|
||||||
|
|
||||||
<hr
|
<hr
|
||||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
<ItemList
|
<Markdown source={community_view.community.description} />
|
||||||
items={moderators.map(m => ({
|
|
||||||
id: m.moderator.id,
|
|
||||||
name: m.moderator.name,
|
|
||||||
url: userLink(m.moderator),
|
|
||||||
avatar: m.moderator.avatar,
|
|
||||||
instance: new URL(m.moderator.actor_id).hostname,
|
|
||||||
}))}
|
|
||||||
/>
|
|
||||||
</Expandable>
|
</Expandable>
|
||||||
{/if}
|
|
||||||
</div>
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
<div class="flex flex-row items-center gap-1 sticky bottom-0 w-full">
|
<Expandable bind:open={settings.expand.stats}>
|
||||||
{#if profile.current?.jwt}
|
{#snippet title()}
|
||||||
<Button
|
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||||
disabled={loading.subscribing}
|
{$t('cards.site.stats')}
|
||||||
loading={loading.subscribing}
|
<hr
|
||||||
size="md"
|
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||||
rounding="pill"
|
/>
|
||||||
color={community_view.subscribed == 'Subscribed'
|
</span>
|
||||||
? 'secondary'
|
{/snippet}
|
||||||
: 'primary'}
|
<div class="flex flex-row gap-4 flex-wrap">
|
||||||
onclick={subscribe}
|
<LabelStat
|
||||||
class="px-4 relative z-[inherit]"
|
label={$t('cards.community.members')}
|
||||||
>
|
content={community_view.counts.subscribers.toString()}
|
||||||
{#snippet prefix()}
|
formatted
|
||||||
<Icon
|
|
||||||
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
|
||||||
mini
|
|
||||||
size="16"
|
|
||||||
/>
|
/>
|
||||||
{/snippet}
|
<LabelStat
|
||||||
{community_view.subscribed == 'Subscribed' ||
|
label={$t('content.posts')}
|
||||||
community_view.subscribed == 'Pending'
|
content={community_view.counts.posts.toString()}
|
||||||
? $t('cards.community.subscribed')
|
formatted
|
||||||
: $t('cards.community.subscribe')}
|
/>
|
||||||
</Button>
|
</div>
|
||||||
{/if}
|
</Expandable>
|
||||||
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
|
|
||||||
<Button
|
{#if moderators && moderators.length > 0}
|
||||||
href="/c/{fullCommunityName(
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
community_view.community.name,
|
<Expandable bind:open={settings.expand.team}>
|
||||||
community_view.community.actor_id,
|
{#snippet title()}
|
||||||
)}/settings"
|
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||||
size="square-md"
|
{$t('cards.community.moderators')}
|
||||||
rounding="pill"
|
|
||||||
>
|
<hr
|
||||||
{#snippet prefix()}
|
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||||
<Icon src={Cog6Tooth} mini size="16" />
|
/>
|
||||||
{/snippet}
|
</span>
|
||||||
</Button>
|
|
||||||
{/if}
|
|
||||||
<Menu placement="top-end">
|
|
||||||
{#snippet target()}
|
|
||||||
<Button size="square-md" rounding="pill">
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Button>
|
<ItemList
|
||||||
{/snippet}
|
items={moderators.map(m => ({
|
||||||
<MenuButton href="/modlog?community={community_view.community.id}">
|
id: m.moderator.id,
|
||||||
<Icon src={Newspaper} size="16" mini />
|
name: m.moderator.name,
|
||||||
{$t('cards.community.modlog')}
|
url: userLink(m.moderator),
|
||||||
</MenuButton>
|
avatar: m.moderator.avatar,
|
||||||
|
instance: new URL(m.moderator.actor_id).hostname,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Expandable>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-row items-center gap-1 sticky bottom-0 w-full">
|
||||||
{#if profile.current?.jwt}
|
{#if profile.current?.jwt}
|
||||||
<MenuButton
|
<Button
|
||||||
color="danger-subtle"
|
disabled={loading.subscribing}
|
||||||
size="lg"
|
loading={loading.subscribing}
|
||||||
onclick={() =>
|
size="md"
|
||||||
block(community_view.community.id, !community_view.blocked)}
|
rounding="pill"
|
||||||
|
color={community_view.subscribed == 'Subscribed'
|
||||||
|
? 'secondary'
|
||||||
|
: 'primary'}
|
||||||
|
onclick={() => subscribe(community_view)}
|
||||||
|
class="px-4 relative z-[inherit]"
|
||||||
>
|
>
|
||||||
{#snippet prefix()}
|
{#snippet prefix()}
|
||||||
<Icon src={NoSymbol} size="16" mini />
|
<Icon
|
||||||
|
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
||||||
|
mini
|
||||||
|
size="16"
|
||||||
|
/>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{community_view.blocked
|
{community_view.subscribed == 'Subscribed' ||
|
||||||
? $t('cards.community.unblock')
|
community_view.subscribed == 'Pending'
|
||||||
: $t('cards.community.block')}
|
? $t('cards.community.subscribed')
|
||||||
|
: $t('cards.community.subscribe')}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
|
||||||
|
<Button
|
||||||
|
href="/c/{fullCommunityName(
|
||||||
|
community_view.community.name,
|
||||||
|
community_view.community.actor_id,
|
||||||
|
)}/settings"
|
||||||
|
size="square-md"
|
||||||
|
rounding="pill"
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon src={Cog6Tooth} mini size="16" />
|
||||||
|
{/snippet}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
<Menu placement="top-end">
|
||||||
|
{#snippet target()}
|
||||||
|
<Button size="square-md" rounding="pill">
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
<MenuButton href="/modlog?community={community_view.community.id}">
|
||||||
|
<Icon src={Newspaper} size="16" mini />
|
||||||
|
{$t('cards.community.modlog')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if profile.current?.user}
|
{#if profile.current?.jwt}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
size="lg"
|
size="lg"
|
||||||
onclick={() => blockInstance(community_view.community.instance_id)}
|
|
||||||
>
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon src={BuildingOffice2} size="16" mini />
|
|
||||||
{/snippet}
|
|
||||||
{$t('cards.community.blockInstance')}
|
|
||||||
</MenuButton>
|
|
||||||
{/if}
|
|
||||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
|
||||||
<MenuButton
|
|
||||||
color="danger-subtle"
|
|
||||||
onclick={() =>
|
onclick={() =>
|
||||||
modal({
|
block(community_view.community.id, !community_view.blocked)}
|
||||||
title: $t('admin.purgeCommunity.title'),
|
|
||||||
body: `${community_view.community.title}: ${$t('admin.purgeCommunity.warning')}`,
|
|
||||||
actions: [
|
|
||||||
action({
|
|
||||||
close: true,
|
|
||||||
content: $t('common.cancel'),
|
|
||||||
}),
|
|
||||||
action({
|
|
||||||
action: () => purgeCommunity(community_view.community.id),
|
|
||||||
close: true,
|
|
||||||
content: $t('admin.purge'),
|
|
||||||
type: 'danger',
|
|
||||||
icon: Fire,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
dismissable: true,
|
|
||||||
type: 'error',
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
{#snippet prefix()}
|
{#snippet prefix()}
|
||||||
<Icon src={Fire} size="16" mini />
|
<Icon src={NoSymbol} size="16" mini />
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{$t('admin.purge')}
|
{community_view.blocked
|
||||||
|
? $t('cards.community.unblock')
|
||||||
|
: $t('cards.community.block')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
{#if profile.current?.user}
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
size="lg"
|
||||||
|
onclick={() =>
|
||||||
|
blockInstance(community_view.community.instance_id)}
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon src={BuildingOffice2} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
|
{$t('cards.community.blockInstance')}
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
onclick={() =>
|
||||||
|
modal({
|
||||||
|
title: $t('admin.purgeCommunity.title'),
|
||||||
|
body: `${community_view.community.title}: ${$t('admin.purgeCommunity.warning')}`,
|
||||||
|
actions: [
|
||||||
|
action({
|
||||||
|
close: true,
|
||||||
|
content: $t('common.cancel'),
|
||||||
|
}),
|
||||||
|
action({
|
||||||
|
action: () => purgeCommunity(community_view.community.id),
|
||||||
|
close: true,
|
||||||
|
content: $t('admin.purge'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: Fire,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
dismissable: true,
|
||||||
|
type: 'error',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon src={Fire} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
|
{$t('admin.purge')}
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
</Menu>
|
||||||
</Menu>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/await}
|
||||||
@@ -15,12 +15,12 @@
|
|||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
import { getClient } from '$lib/lemmy.svelte.js'
|
import { client } from '$lib/lemmy.svelte.js'
|
||||||
import { resumables } from '$lib/lemmy/item.js'
|
import { resumables } from '$lib/lemmy/item.js'
|
||||||
import { settings } from '$lib/settings.svelte.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { isImage } from '$lib/ui/image.js'
|
import { isImage } from '$lib/ui/image.js'
|
||||||
import { Button, toast } from 'mono-svelte'
|
import { Button, toast } from 'mono-svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount, untrack } from 'svelte'
|
||||||
import {
|
import {
|
||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
@@ -32,33 +32,51 @@
|
|||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import CommentProvider from './CommentProvider.svelte'
|
import CommentProvider from './CommentProvider.svelte'
|
||||||
import { ReactiveState } from '$lib/promise.svelte'
|
import { ReactiveState } from '$lib/promise.svelte'
|
||||||
|
import { postFeeds } from '$lib/lemmy/postfeed.svelte'
|
||||||
|
|
||||||
let { data } = $props()
|
let { data } = $props()
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(() => {
|
||||||
if (
|
|
||||||
!(data.post.value.post_view.read && settings.markPostsAsRead) &&
|
|
||||||
profile.current?.jwt
|
|
||||||
) {
|
|
||||||
getClient().markPostAsRead({
|
|
||||||
read: settings.markPostsAsRead,
|
|
||||||
post_ids: [data.post.value.post_view.post.id],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
resumables.add({
|
resumables.add({
|
||||||
name: data.post.value.post_view.post.name,
|
name: data.post.value.post_view.post.name,
|
||||||
type: 'post',
|
type: 'post',
|
||||||
url: page.url.toString(),
|
url: page.url.toString(),
|
||||||
avatar: data.post.value.post_view.post.thumbnail_url,
|
avatar: data.post.value.post_view.post.thumbnail_url,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (
|
||||||
|
!(data.post.value.post_view.read && settings.markPostsAsRead) &&
|
||||||
|
profile.current?.jwt
|
||||||
|
) {
|
||||||
|
client()
|
||||||
|
.markPostAsRead({
|
||||||
|
read: true,
|
||||||
|
post_ids: [data.post.value.post_view.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) {
|
||||||
|
untrack(() => {
|
||||||
|
const { id, index } = data.cachedFeed!
|
||||||
|
postFeeds.value[id].data.posts.posts[index] = data.post.value.post_view
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
|
|
||||||
async function reloadComments() {
|
async function reloadComments() {
|
||||||
loading = true
|
loading = true
|
||||||
data.comments.value = getClient().getComments({
|
data.comments.value = client().getComments({
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
@@ -117,7 +135,11 @@
|
|||||||
<PostMeta
|
<PostMeta
|
||||||
community={data.post.value.post_view.community}
|
community={data.post.value.post_view.community}
|
||||||
user={data.post.value.post_view.creator}
|
user={data.post.value.post_view.creator}
|
||||||
subscribed={data.post.value.community_view.subscribed}
|
subscribed={profile.current.user?.follows.find(
|
||||||
|
i => i.community.id == data.post.value.post_view.community.id,
|
||||||
|
)
|
||||||
|
? 'Subscribed'
|
||||||
|
: 'NotSubscribed'}
|
||||||
badges={{
|
badges={{
|
||||||
deleted: data.post.value.post_view.post.deleted,
|
deleted: data.post.value.post_view.post.deleted,
|
||||||
removed: data.post.value.post_view.post.removed,
|
removed: data.post.value.post_view.post.removed,
|
||||||
@@ -171,34 +193,36 @@
|
|||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{#if data.post.value.cross_posts?.length > 0}
|
{#await data.post.value.meta then meta}
|
||||||
{@const crossposts = data.post.value.cross_posts}
|
{@const crossposts = meta.cross_posts}
|
||||||
<Expandable
|
{#if crossposts?.length > 0}
|
||||||
class="text-base mt-2 w-full cursor-pointer"
|
<Expandable
|
||||||
open={crossposts?.length <= 3}
|
class="text-base mt-2 w-full cursor-pointer"
|
||||||
>
|
open={crossposts?.length <= 3}
|
||||||
{#snippet title()}
|
|
||||||
<div
|
|
||||||
class="flex items-center gap-1 w-full text-left text-base font-normal"
|
|
||||||
>
|
|
||||||
<span class="font-bold">{crossposts.length}</span>
|
|
||||||
{$t('routes.post.crosspostCount')}
|
|
||||||
<hr
|
|
||||||
class="flex-1 inline-block w-full border-slate-200 dark:border-zinc-800 mx-3"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{/snippet}
|
|
||||||
<div
|
|
||||||
class="divide-y! divide-slate-200 dark:divide-zinc-800 flex flex-col"
|
|
||||||
>
|
>
|
||||||
{#key crossposts}
|
{#snippet title()}
|
||||||
{#each crossposts as crosspost (crosspost.post.id)}
|
<div
|
||||||
<Post view="compact" post={crosspost} />
|
class="flex items-center gap-1 w-full text-left text-base font-normal"
|
||||||
{/each}
|
>
|
||||||
{/key}
|
<span class="font-bold">{crossposts.length}</span>
|
||||||
</div>
|
{$t('routes.post.crosspostCount')}
|
||||||
</Expandable>
|
<hr
|
||||||
{/if}
|
class="flex-1 inline-block w-full border-slate-200 dark:border-zinc-800 mx-3"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/snippet}
|
||||||
|
<div
|
||||||
|
class="divide-y! divide-slate-200 dark:divide-zinc-800 flex flex-col"
|
||||||
|
>
|
||||||
|
{#key crossposts}
|
||||||
|
{#each crossposts as crosspost (crosspost.post.id)}
|
||||||
|
<Post view="compact" post={crosspost} />
|
||||||
|
{/each}
|
||||||
|
{/key}
|
||||||
|
</div>
|
||||||
|
</Expandable>
|
||||||
|
{/if}
|
||||||
|
{/await}
|
||||||
</article>
|
</article>
|
||||||
{#if data.thread.value.showContext || data.thread.value.singleThread}
|
{#if data.thread.value.showContext || data.thread.value.singleThread}
|
||||||
<div
|
<div
|
||||||
@@ -266,7 +290,7 @@
|
|||||||
{@const comments = new ReactiveState(passedComments)}
|
{@const comments = new ReactiveState(passedComments)}
|
||||||
<CommentProvider
|
<CommentProvider
|
||||||
comments={comments.value}
|
comments={comments.value}
|
||||||
post={data.post.value}
|
post={data.post.value.post_view}
|
||||||
focus={data.thread.value.focus}
|
focus={data.thread.value.focus}
|
||||||
onupdate={reloadComments}
|
onupdate={reloadComments}
|
||||||
bind:sort={data.commentSort.value}
|
bind:sort={data.commentSort.value}
|
||||||
|
|||||||
@@ -2,10 +2,26 @@ import { resolveRoute } from '$app/paths'
|
|||||||
import { profile } from '$lib/auth.svelte.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||||
import { client } from '$lib/lemmy.svelte.js'
|
import { client } from '$lib/lemmy.svelte.js'
|
||||||
|
import { postFeeds } from '$lib/lemmy/postfeed.svelte.js'
|
||||||
import { ReactiveState, awaitIfServer } from '$lib/promise.svelte.js'
|
import { ReactiveState, awaitIfServer } from '$lib/promise.svelte.js'
|
||||||
import { settings } from '$lib/settings.svelte'
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { redirect } from '@sveltejs/kit'
|
import { redirect } from '@sveltejs/kit'
|
||||||
import type { GetComments } from 'lemmy-js-client'
|
import type {
|
||||||
|
GetComments,
|
||||||
|
PostView,
|
||||||
|
CommunityModeratorView,
|
||||||
|
CommunityView,
|
||||||
|
} from 'lemmy-js-client'
|
||||||
|
|
||||||
|
interface PartialPost {
|
||||||
|
post_view: PostView
|
||||||
|
meta: Promise<{
|
||||||
|
community_view: CommunityView
|
||||||
|
moderators: Array<CommunityModeratorView>
|
||||||
|
cross_posts: Array<PostView>
|
||||||
|
post_view: PostView
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
|
||||||
function buildContext(thread?: string) {
|
function buildContext(thread?: string) {
|
||||||
let parentId: number | undefined
|
let parentId: number | undefined
|
||||||
@@ -27,6 +43,33 @@ function buildContext(thread?: string) {
|
|||||||
return { parentId, showContext, max_depth, focus: thread?.split('.').at(-1) }
|
return { parentId, showContext, max_depth, focus: thread?.split('.').at(-1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findInFeed(
|
||||||
|
postId: number,
|
||||||
|
feedId: 'main' | 'community',
|
||||||
|
):
|
||||||
|
| {
|
||||||
|
post_view: PostView
|
||||||
|
feedData?: {
|
||||||
|
id: 'main' | 'community'
|
||||||
|
index: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| undefined {
|
||||||
|
const index = postFeeds.value[feedId]?.data.posts.posts.findIndex(
|
||||||
|
i => i.post.id == postId,
|
||||||
|
)
|
||||||
|
|
||||||
|
if ((index ?? -1) == -1) return
|
||||||
|
|
||||||
|
return {
|
||||||
|
post_view: postFeeds.value[feedId]?.data.posts.posts[index],
|
||||||
|
feedData: {
|
||||||
|
id: feedId,
|
||||||
|
index: index,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function load({ params, url, fetch }) {
|
export async function load({ params, url, fetch }) {
|
||||||
if (profile.current.instance != params.instance)
|
if (profile.current.instance != params.instance)
|
||||||
redirect(302, resolveRoute('/post/[instance]/[id]/confirm', params))
|
redirect(302, resolveRoute('/post/[instance]/[id]/confirm', params))
|
||||||
@@ -34,14 +77,19 @@ export async function load({ params, url, fetch }) {
|
|||||||
// TODO use Lemmy profile default settings
|
// TODO use Lemmy profile default settings
|
||||||
const sort = settings?.defaultSort?.comments ?? 'Hot'
|
const sort = settings?.defaultSort?.comments ?? 'Hot'
|
||||||
|
|
||||||
const { parentId, showContext, max_depth, focus } = buildContext(
|
const { parentId, showContext, focus } = buildContext(
|
||||||
url.searchParams.get('thread') || undefined,
|
url.searchParams.get('thread') || undefined,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const cachedPost =
|
||||||
|
findInFeed(Number(params.id), 'main') ??
|
||||||
|
findInFeed(Number(params.id), 'community')
|
||||||
|
|
||||||
|
const max_depth = (cachedPost?.post_view.counts.comments ?? 0) > 100 ? 1 : 3
|
||||||
|
|
||||||
const commentParams: GetComments = {
|
const commentParams: GetComments = {
|
||||||
post_id: Number(params.id),
|
post_id: Number(params.id),
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
limit: 50,
|
|
||||||
page: 1,
|
page: 1,
|
||||||
max_depth: max_depth,
|
max_depth: max_depth,
|
||||||
saved_only: false,
|
saved_only: false,
|
||||||
@@ -50,26 +98,34 @@ export async function load({ params, url, fetch }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const comments = client({ func: fetch }).getComments(commentParams)
|
const comments = client({ func: fetch }).getComments(commentParams)
|
||||||
const post = await client({ func: fetch }).getPost({
|
const post = client({ func: fetch }).getPost({
|
||||||
id: Number(params.id),
|
id: Number(params.id),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const partialPost: PartialPost = {
|
||||||
|
post_view: cachedPost ? cachedPost.post_view : (await post).post_view,
|
||||||
|
meta: post.then(i => ({
|
||||||
|
...i,
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
thread: new ReactiveState({
|
thread: new ReactiveState({
|
||||||
showContext: showContext,
|
showContext: showContext,
|
||||||
singleThread: parentId != undefined,
|
singleThread: parentId != undefined,
|
||||||
focus,
|
focus,
|
||||||
}),
|
}),
|
||||||
post: new ReactiveState(post),
|
post: new ReactiveState(partialPost),
|
||||||
commentSort: new ReactiveState(sort),
|
commentSort: new ReactiveState(sort),
|
||||||
comments: new ReactiveState((await awaitIfServer(comments)).data),
|
comments: new ReactiveState((await awaitIfServer(comments)).data),
|
||||||
slots: {
|
slots: {
|
||||||
sidebar: {
|
sidebar: {
|
||||||
component: CommunityCard,
|
component: CommunityCard,
|
||||||
props: {
|
props: {
|
||||||
community_view: post.community_view,
|
community_view: post.then(i => i.community_view),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
cachedFeed: cachedPost?.feedData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
import type {
|
import type {
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
GetCommentsResponse,
|
GetCommentsResponse,
|
||||||
GetPostResponse,
|
PostView,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { Button, Option, Select } from 'mono-svelte'
|
import { Button, Option, Select } from 'mono-svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
post: GetPostResponse
|
post: PostView
|
||||||
comments: GetCommentsResponse
|
comments: GetCommentsResponse
|
||||||
sort?: CommentSortType
|
sort?: CommentSortType
|
||||||
onupdate?: () => void
|
onupdate?: () => void
|
||||||
@@ -68,13 +68,12 @@
|
|||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
rounding="xl"
|
rounding="xl"
|
||||||
disabled={(post.post_view.post.locked ||
|
disabled={(post.post.locked || post.banned_from_community) &&
|
||||||
post.post_view.banned_from_community) &&
|
|
||||||
!(
|
!(
|
||||||
profile.current?.user?.local_user_view.local_user.admin ||
|
profile.current?.user?.local_user_view.local_user.admin ||
|
||||||
profile.current?.user?.moderates
|
profile.current?.user?.moderates
|
||||||
.map(c => c.community.id)
|
.map(c => c.community.id)
|
||||||
.includes(post.community_view.community.id)
|
.includes(post.community.id)
|
||||||
)}
|
)}
|
||||||
onclick={() => (commenting = true)}
|
onclick={() => (commenting = true)}
|
||||||
>
|
>
|
||||||
@@ -116,7 +115,7 @@
|
|||||||
</EndPlaceholder>
|
</EndPlaceholder>
|
||||||
{:else}
|
{:else}
|
||||||
<CommentForm
|
<CommentForm
|
||||||
postId={post.post_view.post.id}
|
postId={post.post.id}
|
||||||
oncomment={comment => {
|
oncomment={comment => {
|
||||||
comments.comments.unshift(comment.comment_view)
|
comments.comments.unshift(comment.comment_view)
|
||||||
}}
|
}}
|
||||||
@@ -157,15 +156,11 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if virtualize}
|
{#if virtualize}
|
||||||
<CommentListVirtualizer
|
<CommentListVirtualizer post={post.post} nodes={tree} scrollTo={focus} />
|
||||||
post={post.post_view.post}
|
|
||||||
nodes={tree}
|
|
||||||
scrollTo={focus}
|
|
||||||
/>
|
|
||||||
{:else}
|
{:else}
|
||||||
<div class="divide-y divide-slate-200 dark:divide-zinc-800">
|
<div class="divide-y divide-slate-200 dark:divide-zinc-800">
|
||||||
<div class="-mx-3 sm:-mx-6 px-3 sm:px-6">
|
<div class="-mx-3 sm:-mx-6 px-3 sm:px-6">
|
||||||
<Comments nodes={tree} post={post.post_view.post} />
|
<Comments nodes={tree} post={post.post} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
Reference in new issue
Block a user