cleanup: use ReactiveState to provide $state with sveltekit (#492)
This commit is contained in:
1 parent
589db4dcc7
commit
7c46e616f8
18 files changed
+168
-168
No files matched your search
@@ -29,7 +29,7 @@ export const addSubscription = (
|
||||
if (subscribe && index == -1) {
|
||||
profile.data.user?.follows.push({
|
||||
// @ts-ignore
|
||||
follower: p.user.follows[0]?.follower,
|
||||
follower: profile.data.user.follows[0]?.follower,
|
||||
community: community,
|
||||
})
|
||||
} else {
|
||||
|
||||
@@ -7,3 +7,11 @@ export const awaitIfServer = async <T>(
|
||||
): Promise<{
|
||||
data: Promise<T> | T
|
||||
}> => ({ data: browser ? promise : await promise })
|
||||
|
||||
export class ReactiveState<T> {
|
||||
value = $state<T>()!
|
||||
|
||||
constructor(initialValue: T) {
|
||||
this.value = initialValue as NonNullable<T>
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,16 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{data.community.community_view.community.title}</title>
|
||||
<title>{data.community.value.community_view.community.title}</title>
|
||||
|
||||
<meta
|
||||
name="og:title"
|
||||
content={data.community.community_view.community.title}
|
||||
content={data.community.value.community_view.community.title}
|
||||
/>
|
||||
{#if data.community.community_view.community.description}
|
||||
{#if data.community.value.community_view.community.description}
|
||||
<meta
|
||||
name="og:description"
|
||||
content={data.community.community_view.community.description}
|
||||
content={data.community.value.community_view.community.description}
|
||||
/>
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte'
|
||||
|
||||
export async function load(req: any) {
|
||||
const community = await getClient(undefined, req.fetch).getCommunity({
|
||||
@@ -7,7 +8,7 @@ export async function load(req: any) {
|
||||
})
|
||||
|
||||
return {
|
||||
community: community,
|
||||
community: new ReactiveState(community),
|
||||
slots: {
|
||||
sidebar: {
|
||||
component: CommunityCard,
|
||||
|
||||
@@ -21,11 +21,7 @@
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
|
||||
let { data: pageData } = $props()
|
||||
let data = $state(pageData)
|
||||
$effect(() => {
|
||||
data = pageData
|
||||
})
|
||||
let { data } = $props()
|
||||
|
||||
let sidebar: boolean = $state(false)
|
||||
|
||||
@@ -33,14 +29,14 @@
|
||||
if (browser)
|
||||
setSessionStorage(
|
||||
'lastSeenCommunity',
|
||||
data.community.community_view.community,
|
||||
data.community.value.community_view.community,
|
||||
)
|
||||
|
||||
resumables.add({
|
||||
name: data.community.community_view.community.title,
|
||||
name: data.community.value.community_view.community.title,
|
||||
type: 'community',
|
||||
url: page.url.toString(),
|
||||
avatar: data.community.community_view.community.icon,
|
||||
avatar: data.community.value.community_view.community.icon,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -60,8 +56,8 @@
|
||||
{/snippet}
|
||||
<div>
|
||||
<CommunityCard
|
||||
bind:community_view={data.community.community_view}
|
||||
moderators={data.community.moderators}
|
||||
bind:community_view={data.community.value.community_view}
|
||||
moderators={data.community.value.moderators}
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
@@ -71,11 +67,11 @@
|
||||
<Header pageHeader>
|
||||
<div class="flex flex-col w-full">
|
||||
<CommunityHeader
|
||||
bind:community={data.community.community_view.community}
|
||||
bind:subscribed={data.community.community_view.subscribed}
|
||||
blocked={data.community.community_view.blocked}
|
||||
moderators={data.community.moderators}
|
||||
counts={data.community.community_view.counts}
|
||||
bind:community={data.community.value.community_view.community}
|
||||
bind:subscribed={data.community.value.community_view.subscribed}
|
||||
blocked={data.community.value.community_view.blocked}
|
||||
moderators={data.community.value.moderators}
|
||||
counts={data.community.value.community_view.counts}
|
||||
class="w-full relative"
|
||||
/>
|
||||
</div>
|
||||
@@ -85,7 +81,7 @@
|
||||
</Header>
|
||||
|
||||
{#if profile.data.user}
|
||||
{#if !data.community.discussion_languages.every( (l) => profile.data.user?.discussion_languages.includes(l), ) && profile.data.user.discussion_languages.length > 0}
|
||||
{#if !data.community.value.discussion_languages.every( (l) => profile.data.user?.discussion_languages.includes(l), ) && profile.data.user.discussion_languages.length > 0}
|
||||
<Note class="!p-1 !pl-3 flex-col md:flex-row">
|
||||
{$t('routes.community.languageWarning')}
|
||||
<Button
|
||||
@@ -104,7 +100,7 @@
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if data.community.community_view.blocked}
|
||||
{#if data.community.value.community_view.blocked}
|
||||
<Placeholder
|
||||
icon={XMark}
|
||||
title="Blocked"
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
let communityUrl = $derived(
|
||||
`/c/${fullCommunityName(
|
||||
data.community.community_view.community.name,
|
||||
data.community.community_view.community.actor_id,
|
||||
data.community.value.community_view.community.name,
|
||||
data.community.value.community_view.community.actor_id,
|
||||
)}`,
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -10,23 +10,26 @@
|
||||
<Header pageHeader>
|
||||
<span>Settings</span>
|
||||
{#snippet extended()}
|
||||
<CommunityTitle community={data.community.community_view.community} />
|
||||
<CommunityTitle
|
||||
community={data.community.value.community_view.community}
|
||||
/>
|
||||
{/snippet}
|
||||
</Header>
|
||||
<CommunityForm
|
||||
edit={data.community.community_view.community.id}
|
||||
edit={data.community.value.community_view.community.id}
|
||||
formData={{
|
||||
name: data.community.community_view.community.name,
|
||||
displayName: data.community.community_view.community.title,
|
||||
nsfw: data.community.community_view.community.nsfw,
|
||||
name: data.community.value.community_view.community.name,
|
||||
displayName: data.community.value.community_view.community.title,
|
||||
nsfw: data.community.value.community_view.community.nsfw,
|
||||
postsLockedToModerators:
|
||||
data.community.community_view.community.posting_restricted_to_mods,
|
||||
sidebar: data.community.community_view.community.description ?? '',
|
||||
icon: data.community.community_view.community.icon,
|
||||
banner: data.community.community_view.community.banner,
|
||||
visibility: data.community.community_view.community.visibility,
|
||||
data.community.value.community_view.community
|
||||
.posting_restricted_to_mods,
|
||||
sidebar: data.community.value.community_view.community.description ?? '',
|
||||
icon: data.community.value.community_view.community.icon,
|
||||
banner: data.community.value.community_view.community.banner,
|
||||
visibility: data.community.value.community_view.community.visibility,
|
||||
submitting: false,
|
||||
languages: data.community.discussion_languages,
|
||||
languages: data.community.value.discussion_languages,
|
||||
}}
|
||||
>
|
||||
{#snippet formtitle()}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
data: PageData
|
||||
}
|
||||
|
||||
let { data: pageData }: Props = $props()
|
||||
let data = $state(pageData)
|
||||
let { data }: Props = $props()
|
||||
|
||||
let formData = $state({
|
||||
newModerator: '',
|
||||
@@ -33,10 +32,10 @@
|
||||
const addModRes = await getClient().addModToCommunity({
|
||||
added: true,
|
||||
person_id: Number(formData.newModerator),
|
||||
community_id: data.community.community_view.community.id,
|
||||
community_id: data.community.value.community_view.community.id,
|
||||
})
|
||||
|
||||
data.community.moderators = addModRes.moderators
|
||||
data.community.value.moderators = addModRes.moderators
|
||||
toast({
|
||||
content: $t('toast.addMod'),
|
||||
type: 'success',
|
||||
@@ -52,10 +51,10 @@
|
||||
const addModRes = await getClient().addModToCommunity({
|
||||
added: true,
|
||||
person_id: res.person.person.id,
|
||||
community_id: data.community.community_view.community.id,
|
||||
community_id: data.community.value.community_view.community.id,
|
||||
})
|
||||
|
||||
data.community.moderators = addModRes.moderators
|
||||
data.community.value.moderators = addModRes.moderators
|
||||
|
||||
toast({
|
||||
content: $t('toast.addMod'),
|
||||
@@ -86,11 +85,11 @@
|
||||
try {
|
||||
const res = await getClient().addModToCommunity({
|
||||
added: false,
|
||||
community_id: data.community.community_view.community.id,
|
||||
community_id: data.community.value.community_view.community.id,
|
||||
person_id: id,
|
||||
})
|
||||
|
||||
data.community.moderators = res.moderators
|
||||
data.community.value.moderators = res.moderators
|
||||
|
||||
toast({
|
||||
content: $t('toast.updateMods'),
|
||||
@@ -107,7 +106,7 @@
|
||||
|
||||
<Header pageHeader>Moderators</Header>
|
||||
<ul class="divide-y divide-slate-200 dark:divide-zinc-800">
|
||||
{#each data.community.moderators as moderator (moderator.moderator.id)}
|
||||
{#each data.community.value.moderators as moderator (moderator.moderator.id)}
|
||||
<div
|
||||
class="py-4 flex items-center gap-2 justify-between"
|
||||
animate:flip={{ duration: 300 }}
|
||||
|
||||
@@ -34,17 +34,14 @@
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
let communities = $state(data.communities)
|
||||
$effect(() => {
|
||||
communities = data.communities
|
||||
})
|
||||
|
||||
let search = $state(data.query || '')
|
||||
let searchElement = $state<HTMLInputElement>()
|
||||
let form = $state<HTMLFormElement>()
|
||||
|
||||
let showTop = $derived(
|
||||
(data.query ?? '' != '') && data.communities.length > 0 && data.page == 1,
|
||||
(data.query ?? '' != '') &&
|
||||
data.communities.value.length > 0 &&
|
||||
data.page == 1,
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -124,7 +121,7 @@
|
||||
<ul
|
||||
class="flex flex-col divide-y divide-slate-100 dark:divide-zinc-800 my-6 h-full"
|
||||
>
|
||||
{#if communities.length == 0}
|
||||
{#if data.communities.value.length == 0}
|
||||
<Placeholder
|
||||
icon={QuestionMarkCircle}
|
||||
title={$t('routes.search.noResults.title')}
|
||||
@@ -139,7 +136,7 @@
|
||||
<div
|
||||
class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 !border-0"
|
||||
>
|
||||
{#each communities.slice(0, 3) as community, index (community.community.id)}
|
||||
{#each data.communities.value.slice(0, 3) as community, index (community.community.id)}
|
||||
<div
|
||||
class="h-full"
|
||||
in:fly|global={{
|
||||
@@ -167,13 +164,13 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if communities.slice(showTop ? 3 : 0).length > 0}
|
||||
{#if data.communities.value.slice(showTop ? 3 : 0).length > 0}
|
||||
<SectionTitle class="!border-0 pb-2">
|
||||
{$t('routes.search.other')}
|
||||
</SectionTitle>
|
||||
{/if}
|
||||
{#if communities}
|
||||
{@const sliced = communities.slice(showTop ? 3 : 0)}
|
||||
{#if data.communities.value}
|
||||
{@const sliced = data.communities.value.slice(showTop ? 3 : 0)}
|
||||
<div class="-mx-4 sm:-mx-6 h-full">
|
||||
{#each sliced as community, index (community.community.id)}
|
||||
<div
|
||||
@@ -193,7 +190,7 @@
|
||||
{/if}
|
||||
</ul>
|
||||
{/if}
|
||||
{#if communities.length > 0}
|
||||
{#if data.communities.value.length > 0}
|
||||
<div class="sticky z-30 mx-auto max-w-full bottom-22 lg:bottom-6">
|
||||
<Tabs routes={[]} class="mx-auto">
|
||||
<Pageination
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte.js'
|
||||
import { client, getClient } from '$lib/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte'
|
||||
import {
|
||||
type ListCommunitiesResponse,
|
||||
type ListingType,
|
||||
@@ -35,7 +36,7 @@ export async function load({ url, fetch }) {
|
||||
})
|
||||
|
||||
return {
|
||||
...communities,
|
||||
communities: new ReactiveState(communities.communities),
|
||||
type: type,
|
||||
sort: sort,
|
||||
query: query,
|
||||
|
||||
@@ -26,11 +26,6 @@
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
let inbox = $state(data.data)
|
||||
$effect(() => {
|
||||
inbox = data.data
|
||||
})
|
||||
|
||||
let markingAsRead = $state(false)
|
||||
|
||||
async function markAllAsRead() {
|
||||
@@ -167,7 +162,7 @@ items-center px-2 w-max top-6 lg:top-22"
|
||||
<div
|
||||
class="flex flex-col list-none flex-1 h-full divide-y divide-slate-200 dark:divide-zinc-900 *:py-4"
|
||||
>
|
||||
{#if !inbox || (inbox?.length ?? 0) == 0}
|
||||
{#if !data.inbox?.value || (data.inbox.value?.length ?? 0) == 0}
|
||||
<Placeholder
|
||||
icon={Inbox}
|
||||
title={$t('routes.inbox.empty.title')}
|
||||
@@ -175,7 +170,7 @@ items-center px-2 w-max top-6 lg:top-22"
|
||||
class="self-center justify-self-center my-auto"
|
||||
/>
|
||||
{:else}
|
||||
{#each inbox as item, index (item.id)}
|
||||
{#each data.inbox.value as item, index (item.id)}
|
||||
<div
|
||||
class="-mx-4 sm:-mx-6 px-4 sm:px-6
|
||||
{item.read ? '' : 'bg-yellow-50/50 dark:bg-blue-500/5'}"
|
||||
@@ -187,17 +182,19 @@ items-center px-2 w-max top-6 lg:top-22"
|
||||
delay: index * 50,
|
||||
}}
|
||||
>
|
||||
<InboxItem bind:item={inbox[index]} />
|
||||
<InboxItem bind:item={data.inbox.value[index]} />
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
{#if !(data.page == 1 && (data?.data?.length ?? 0) == 0)}
|
||||
{#if !(data.page == 1 && (data?.inbox?.value.length ?? 0) == 0)}
|
||||
<div
|
||||
class="sticky z-30 mx-auto max-w-full self-end mt-auto bottom-22 lg:bottom-6"
|
||||
>
|
||||
<Tabs routes={[]} class="mx-auto">
|
||||
<Pageination
|
||||
hasMore={!(!inbox || (inbox?.length ?? 0) < (data?.limit ?? 0))}
|
||||
hasMore={!(
|
||||
!data.inbox || (data.inbox.value?.length ?? 0) < (data?.limit ?? 0)
|
||||
)}
|
||||
page={data.page}
|
||||
href={(page) => `?page=${page}`}
|
||||
/>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
generalizePersonMention,
|
||||
generalizePrivateMessage,
|
||||
} from '$lib/lemmy/inbox.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||
@@ -61,7 +62,7 @@ export async function load({ url, fetch }) {
|
||||
unreadOnly: unreadOnly,
|
||||
type: type,
|
||||
page: page,
|
||||
data: data,
|
||||
inbox: new ReactiveState(data),
|
||||
limit: 20,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { client } from '$lib/lemmy.svelte.js'
|
||||
import { awaitIfServer } from '$lib/promise.js'
|
||||
import { awaitIfServer } from '$lib/promise.svelte.js'
|
||||
|
||||
export async function load({ fetch, url }) {
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { client } from '$lib/lemmy.svelte.js'
|
||||
import { awaitIfServer } from '$lib/promise.js'
|
||||
import { awaitIfServer } from '$lib/promise.svelte.js'
|
||||
|
||||
export async function load({ fetch, params }) {
|
||||
const creator = Number(params.user_id)
|
||||
|
||||
@@ -54,11 +54,7 @@
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import CommentProvider from './CommentProvider.svelte'
|
||||
|
||||
let { data: loaded = $bindable() } = $props()
|
||||
let data = $state(loaded)
|
||||
$effect(() => {
|
||||
data = loaded
|
||||
})
|
||||
let { data } = $props()
|
||||
|
||||
const updateActions = () => {
|
||||
// @ts-ignore
|
||||
@@ -68,10 +64,10 @@
|
||||
name: $t('post.actions.vote.upvote'),
|
||||
icon: ArrowUp,
|
||||
handle: async () => {
|
||||
data.post.post_view.my_vote = (
|
||||
data.post.value.post_view.my_vote = (
|
||||
await client().likePost({
|
||||
post_id: data.post.post_view.post.id,
|
||||
score: data.post.post_view.my_vote == 1 ? 0 : 1,
|
||||
post_id: data.post.value.post_view.post.id,
|
||||
score: data.post.value.post_view.my_vote == 1 ? 0 : 1,
|
||||
})
|
||||
).post_view.my_vote
|
||||
},
|
||||
@@ -80,54 +76,54 @@
|
||||
name: $t('post.actions.vote.downvote'),
|
||||
icon: ArrowDown,
|
||||
handle: async () => {
|
||||
data.post.post_view.my_vote = (
|
||||
data.post.value.post_view.my_vote = (
|
||||
await client().likePost({
|
||||
post_id: data.post.post_view.post.id,
|
||||
score: data.post.post_view.my_vote == -1 ? 0 : -1,
|
||||
post_id: data.post.value.post_view.post.id,
|
||||
score: data.post.value.post_view.my_vote == -1 ? 0 : -1,
|
||||
})
|
||||
).post_view.my_vote
|
||||
},
|
||||
},
|
||||
{
|
||||
name: data.post.post_view.saved
|
||||
name: data.post.value.post_view.saved
|
||||
? $t('post.actions.unsave')
|
||||
: $t('post.actions.save'),
|
||||
handle: async () => {
|
||||
data.post.post_view.saved = (
|
||||
data.post.value.post_view.saved = (
|
||||
await client().savePost({
|
||||
post_id: data.post.post_view.post.id,
|
||||
save: !data.post.post_view.saved,
|
||||
post_id: data.post.value.post_view.post.id,
|
||||
save: !data.post.value.post_view.saved,
|
||||
})
|
||||
).post_view.saved
|
||||
},
|
||||
icon: data.post.post_view.saved ? BookmarkSlash : Bookmark,
|
||||
icon: data.post.value.post_view.saved ? BookmarkSlash : Bookmark,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (data.post) updateActions()
|
||||
if (data.post.value) updateActions()
|
||||
})
|
||||
|
||||
onMount(async () => {
|
||||
if (
|
||||
!(data.post.post_view.read && settings.markPostsAsRead) &&
|
||||
!(data.post.value.post_view.read && settings.markPostsAsRead) &&
|
||||
profile.data?.jwt
|
||||
) {
|
||||
getClient().markPostAsRead({
|
||||
read: settings.markPostsAsRead,
|
||||
post_ids: [data.post.post_view.post.id],
|
||||
post_ids: [data.post.value.post_view.post.id],
|
||||
// @ts-ignore
|
||||
post_id: data.post.post_view.post.id,
|
||||
post_id: data.post.value.post_view.post.id,
|
||||
})
|
||||
}
|
||||
|
||||
resumables.add({
|
||||
name: data.post.post_view.post.name,
|
||||
name: data.post.value.post_view.post.name,
|
||||
type: 'post',
|
||||
url: page.url.toString(),
|
||||
avatar: data.post.post_view.post.thumbnail_url,
|
||||
avatar: data.post.value.post_view.post.thumbnail_url,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -139,7 +135,7 @@
|
||||
|
||||
try {
|
||||
const res = await getClient().resolveObject({
|
||||
q: data.post.post_view.post.ap_id,
|
||||
q: data.post.value.post_view.post.ap_id,
|
||||
})
|
||||
|
||||
if (res.post) {
|
||||
@@ -154,21 +150,20 @@
|
||||
}
|
||||
|
||||
let commentsPage = 1
|
||||
let commentSort: CommentSortType = $state(data.commentSort)
|
||||
let loading = $state(false)
|
||||
|
||||
async function reloadComments() {
|
||||
loading = true
|
||||
data.comments = getClient().getComments({
|
||||
data.comments.value = getClient().getComments({
|
||||
page: 1,
|
||||
limit: 25,
|
||||
type_: 'All',
|
||||
post_id: data.post.post_view.post.id,
|
||||
sort: commentSort,
|
||||
max_depth: data.post.post_view.counts.comments > 100 ? 1 : 3,
|
||||
post_id: data.post.value.post_view.post.id,
|
||||
sort: data.commentSort.value,
|
||||
max_depth: data.post.value.post_view.counts.comments > 100 ? 1 : 3,
|
||||
})
|
||||
loading = false
|
||||
data.thread.singleThread = false
|
||||
data.thread.value.singleThread = false
|
||||
commentsPage = 1
|
||||
}
|
||||
|
||||
@@ -180,35 +175,41 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{data.post.post_view.post.name}</title>
|
||||
<meta property="og:title" content={data.post.post_view.post.name} />
|
||||
<meta property="twitter:title" content={data.post.post_view.post.name} />
|
||||
<title>{data.post.value.post_view.post.name}</title>
|
||||
<meta property="og:title" content={data.post.value.post_view.post.name} />
|
||||
<meta
|
||||
property="twitter:title"
|
||||
content={data.post.value.post_view.post.name}
|
||||
/>
|
||||
<meta property="og:url" content={page.url.toString()} />
|
||||
{#if isImage(data.post.post_view.post.url)}
|
||||
<meta property="og:image" content={data.post.post_view.post.url} />
|
||||
<meta property="twitter:card" content={data.post.post_view.post.url} />
|
||||
{:else if data.post.post_view.post.thumbnail_url}
|
||||
{#if isImage(data.post.value.post_view.post.url)}
|
||||
<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.post_view.post.thumbnail_url}
|
||||
content={data.post.value.post_view.post.thumbnail_url}
|
||||
/>
|
||||
<meta
|
||||
property="twitter:card"
|
||||
content={data.post.post_view.post.thumbnail_url}
|
||||
content={data.post.value.post_view.post.thumbnail_url}
|
||||
/>
|
||||
{/if}
|
||||
{#if data.post.post_view.post.body}
|
||||
{#if data.post.value.post_view.post.body}
|
||||
<meta
|
||||
property="description"
|
||||
content={data.post.post_view.post.body.slice(0, 500)}
|
||||
content={data.post.value.post_view.post.body.slice(0, 500)}
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={data.post.post_view.post.body.slice(0, 500)}
|
||||
content={data.post.value.post_view.post.body.slice(0, 500)}
|
||||
/>
|
||||
<meta
|
||||
property="twitter:description"
|
||||
content={data.post.post_view.post.body.slice(0, 500)}
|
||||
content={data.post.value.post_view.post.body.slice(0, 500)}
|
||||
/>
|
||||
{/if}
|
||||
</svelte:head>
|
||||
@@ -255,26 +256,26 @@
|
||||
<header class="flex flex-col gap-2">
|
||||
<div class="flex flex-row justify-between items-center gap-2 flex-wrap">
|
||||
<PostMeta
|
||||
community={data.post.post_view.community}
|
||||
user={data.post.post_view.creator}
|
||||
bind:subscribed={data.post.community_view.subscribed}
|
||||
community={data.post.value.post_view.community}
|
||||
user={data.post.value.post_view.creator}
|
||||
bind:subscribed={data.post.value.community_view.subscribed}
|
||||
badges={{
|
||||
deleted: data.post.post_view.post.deleted,
|
||||
removed: data.post.post_view.post.removed,
|
||||
locked: data.post.post_view.post.locked,
|
||||
deleted: data.post.value.post_view.post.deleted,
|
||||
removed: data.post.value.post_view.post.removed,
|
||||
locked: data.post.value.post_view.post.locked,
|
||||
featured:
|
||||
data.post.post_view.post.featured_community ||
|
||||
data.post.post_view.post.featured_local,
|
||||
nsfw: data.post.post_view.post.nsfw,
|
||||
saved: data.post.post_view.saved,
|
||||
admin: data.post.post_view.creator_is_admin,
|
||||
moderator: data.post.post_view.creator_is_moderator,
|
||||
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,
|
||||
}}
|
||||
published={publishedToDate(data.post.post_view.post.published)}
|
||||
edited={data.post.post_view.post.updated}
|
||||
title={data.post.post_view.post.name}
|
||||
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}
|
||||
style="width: max-content;"
|
||||
tags={parseTags(data.post.post_view.post.name).tags}
|
||||
tags={parseTags(data.post.value.post_view.post.name).tags}
|
||||
/>
|
||||
<Button onclick={() => history.back()} size="square-md">
|
||||
{#snippet prefix()}
|
||||
@@ -284,26 +285,26 @@
|
||||
</div>
|
||||
<h1 class="font-bold text-xl font-display leading-5">
|
||||
<Markdown
|
||||
source={parseTags(data.post.post_view.post.name).title ??
|
||||
data.post.post_view.post.name}
|
||||
source={parseTags(data.post.value.post_view.post.name).title ??
|
||||
data.post.value.post_view.post.name}
|
||||
inline
|
||||
/>
|
||||
</h1>
|
||||
</header>
|
||||
<PostMedia
|
||||
type={mediaType(data.post.post_view.post.url)}
|
||||
post={data.post.post_view.post}
|
||||
type={mediaType(data.post.value.post_view.post.url)}
|
||||
post={data.post.value.post_view.post}
|
||||
opened
|
||||
view="cozy"
|
||||
/>
|
||||
{#if data.post.post_view.post.body}
|
||||
{#if data.post.value.post_view.post.body}
|
||||
<div class="text-base text-slate-800 dark:text-zinc-300 leading-[1.5]">
|
||||
<Markdown source={data.post.post_view.post.body} />
|
||||
<Markdown source={data.post.value.post_view.post.body} />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="w-full relative">
|
||||
<PostActions
|
||||
bind:post={data.post.post_view}
|
||||
bind:post={data.post.value.post_view}
|
||||
onedit={() =>
|
||||
toast({
|
||||
content: 'The post was edited successfully.',
|
||||
@@ -311,16 +312,16 @@
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
{#if data.post.cross_posts?.length > 0}
|
||||
{#if data.post.value.cross_posts?.length > 0}
|
||||
<Expandable
|
||||
class="text-base mt-2 w-full cursor-pointer"
|
||||
open={data.post.cross_posts?.length <= 3}
|
||||
open={data.post.value.cross_posts?.length <= 3}
|
||||
>
|
||||
{#snippet title()}
|
||||
<div
|
||||
class="flex items-center gap-1 w-full text-left text-base font-normal"
|
||||
>
|
||||
<span class="font-bold">{data.post.cross_posts.length}</span>
|
||||
<span class="font-bold">{data.post.value.cross_posts.length}</span>
|
||||
{$t('routes.post.crosspostCount')}
|
||||
<hr
|
||||
class="flex-1 inline-block w-full border-slate-200 dark:border-zinc-800 mx-3"
|
||||
@@ -330,14 +331,14 @@
|
||||
<div
|
||||
class="!divide-y divide-slate-200 dark:divide-zinc-800 flex flex-col"
|
||||
>
|
||||
{#each data.post.cross_posts as crosspost}
|
||||
{#each data.post.value.cross_posts as crosspost}
|
||||
<Post view="compact" actions={false} post={crosspost} />
|
||||
{/each}
|
||||
</div>
|
||||
</Expandable>
|
||||
{/if}
|
||||
</article>
|
||||
{#if data.thread.showContext || data.thread.singleThread}
|
||||
{#if data.thread.value.showContext || data.thread.value.singleThread}
|
||||
<div
|
||||
class="sticky mx-auto z-50 max-w-lg w-full min-w-0 flex 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
|
||||
@@ -345,7 +346,7 @@
|
||||
>
|
||||
<p class="font-medium text-sm flex items-center gap-2">
|
||||
<Icon src={InformationCircle} mini size="20" />
|
||||
{data.thread.showContext
|
||||
{data.thread.value.showContext
|
||||
? $t('routes.post.thread.part')
|
||||
: $t('routes.post.thread.single')}
|
||||
</p>
|
||||
@@ -354,13 +355,13 @@
|
||||
rounding="pill"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
href={data.thread.showContext
|
||||
? `/comment/${page.params.instance}/${data.thread.showContext}`
|
||||
href={data.thread.value.showContext
|
||||
? `/comment/${page.params.instance}/${data.thread.value.showContext}`
|
||||
: undefined}
|
||||
class="hover:bg-white/50 dark:hover:bg-zinc-800/30"
|
||||
onclick={data.thread.singleThread ? reloadComments : undefined}
|
||||
onclick={data.thread.value.singleThread ? reloadComments : undefined}
|
||||
>
|
||||
{data.thread.showContext
|
||||
{data.thread.value.showContext
|
||||
? $t('routes.post.thread.context')
|
||||
: $t('routes.post.thread.allComments')}
|
||||
</Button>
|
||||
@@ -370,12 +371,12 @@
|
||||
<header>
|
||||
<div class="text-base">
|
||||
<span class="font-bold">
|
||||
<FormattedNumber number={data.post.post_view.counts.comments} />
|
||||
<FormattedNumber number={data.post.value.post_view.counts.comments} />
|
||||
</span>
|
||||
{$t('routes.post.commentCount')}
|
||||
</div>
|
||||
</header>
|
||||
{#await data.comments}
|
||||
{#await data.comments.value}
|
||||
<div class="flex flex-col gap-4">
|
||||
{#each new Array(10) as empty, index}
|
||||
<div
|
||||
@@ -396,11 +397,11 @@
|
||||
</div>
|
||||
{:then comments}
|
||||
<CommentProvider
|
||||
post={data.post}
|
||||
{comments}
|
||||
focus={data.thread.focus}
|
||||
post={data.post.value}
|
||||
focus={data.thread.value.focus}
|
||||
onupdate={reloadComments}
|
||||
bind:sort={commentSort}
|
||||
bind:sort={data.commentSort.value}
|
||||
/>
|
||||
{#if comments.comments.length == 0}
|
||||
<Placeholder
|
||||
@@ -410,10 +411,10 @@
|
||||
></Placeholder>
|
||||
{/if}
|
||||
{/await}
|
||||
{#if data.post.post_view.counts.comments > 5}
|
||||
{#if data.post.value.post_view.counts.comments > 5}
|
||||
<EndPlaceholder>
|
||||
<span class="text-black dark:text-white font-bold">
|
||||
{data.post.post_view.counts.comments}
|
||||
{data.post.value.post_view.counts.comments}
|
||||
</span>
|
||||
{$t('routes.post.commentCount')}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { awaitIfServer } from '$lib/promise.js'
|
||||
import { awaitIfServer } from '$lib/promise.svelte.js'
|
||||
import { SSR_ENABLED, settings } from '$lib/settings.svelte'
|
||||
import type { GetComments } from 'lemmy-js-client'
|
||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
const thread = url.searchParams.get('thread')
|
||||
@@ -49,14 +50,14 @@ export async function load({ params, url, fetch }) {
|
||||
})
|
||||
|
||||
return {
|
||||
thread: {
|
||||
thread: new ReactiveState({
|
||||
showContext: showContext,
|
||||
singleThread: parentId != undefined,
|
||||
focus: thread?.split('.').at(-1),
|
||||
},
|
||||
post: post,
|
||||
commentSort: sort,
|
||||
comments: (await awaitIfServer(comments)).data,
|
||||
}),
|
||||
post: new ReactiveState(post),
|
||||
commentSort: new ReactiveState(sort),
|
||||
comments: new ReactiveState((await awaitIfServer(comments)).data),
|
||||
slots: {
|
||||
sidebar: {
|
||||
component: CommunityCard,
|
||||
|
||||
@@ -46,12 +46,6 @@
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
let results = $state(data.results)
|
||||
|
||||
$effect(() => {
|
||||
results = data.results
|
||||
})
|
||||
|
||||
let query = $state(data.query || '')
|
||||
let searchElement: HTMLInputElement | undefined = $state()
|
||||
let form = $state<HTMLFormElement>()
|
||||
@@ -213,7 +207,7 @@
|
||||
<div
|
||||
class="flex flex-col mt-4 divide-slate-200 dark:divide-zinc-800 !divide-y"
|
||||
>
|
||||
{#each data.results as result}
|
||||
{#each data.results.value as result}
|
||||
{#if isPostView(result)}
|
||||
<Post post={result} />
|
||||
{:else if isCommentView(result)}
|
||||
@@ -234,7 +228,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
<div class="mt-4"></div>
|
||||
{#if data.results.length > 0}
|
||||
{#if data.results.value.length > 0}
|
||||
<Pageination bind:page={pageNum} href={(page) => `?page=${page}`} />
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { client, getClient } from '$lib/lemmy.svelte.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
import type {
|
||||
CommentView,
|
||||
CommunityView,
|
||||
@@ -55,7 +56,7 @@ export async function load({ url, fetch }) {
|
||||
sort: sort,
|
||||
page: page,
|
||||
query: query,
|
||||
results: everything,
|
||||
results: new ReactiveState(everything),
|
||||
streamed: {
|
||||
object: profile.data?.jwt
|
||||
? getClient(undefined, fetch).resolveObject({
|
||||
|
||||
Reference in new issue
Block a user