diff --git a/src/lib/lemmy/report.ts b/src/lib/components/lemmy/moderation/report.ts similarity index 100% rename from src/lib/lemmy/report.ts rename to src/lib/components/lemmy/moderation/report.ts diff --git a/src/lib/components/lemmy/post/PostMeta.svelte b/src/lib/components/lemmy/post/PostMeta.svelte index d0ef2ed0..6ae18c87 100644 --- a/src/lib/components/lemmy/post/PostMeta.svelte +++ b/src/lib/components/lemmy/post/PostMeta.svelte @@ -78,6 +78,7 @@ type IconSource, } from 'svelte-hero-icons' import { CommunityLink } from '../community' + import { SvelteMap } from 'svelte/reactivity' interface Props { community?: Community @@ -134,7 +135,7 @@ color: 'red-subtle' | 'yellow-subtle' | 'green-subtle' label: string } - > = new Map([ + > = new SvelteMap([ [ 'nsfw', { diff --git a/src/lib/components/lemmy/post/actions/PostActions.svelte b/src/lib/components/lemmy/post/actions/PostActions.svelte index af614743..b85567f5 100644 --- a/src/lib/components/lemmy/post/actions/PostActions.svelte +++ b/src/lib/components/lemmy/post/actions/PostActions.svelte @@ -184,7 +184,7 @@ {:then { default: PostActionsMenu }} - + {/await} {/if} {/snippet} diff --git a/src/lib/components/lemmy/post/actions/PostActionsMenu.svelte b/src/lib/components/lemmy/post/actions/PostActionsMenu.svelte index 57b2c756..856bde9e 100644 --- a/src/lib/components/lemmy/post/actions/PostActionsMenu.svelte +++ b/src/lib/components/lemmy/post/actions/PostActionsMenu.svelte @@ -32,7 +32,7 @@ editing: boolean } - let { post, onhide, editing = $bindable() }: Props = $props() + let { post = $bindable(), onhide, editing = $bindable() }: Props = $props() function share(global: boolean = true) { const link = global diff --git a/src/lib/components/lemmy/post/feed/VirtualFeed.svelte b/src/lib/components/lemmy/post/feed/VirtualFeed.svelte index 7a846a70..81712015 100644 --- a/src/lib/components/lemmy/post/feed/VirtualFeed.svelte +++ b/src/lib/components/lemmy/post/feed/VirtualFeed.svelte @@ -1,17 +1,13 @@ - - - {data.community.value.community_view.community.title} - - - {#if data.community.value.community_view.community.description} - - {/if} - -{@render children?.()} diff --git a/src/routes/c/[name]/+page.svelte b/src/routes/c/[name]/+page.svelte index f26c1ce6..d2206e58 100644 --- a/src/routes/c/[name]/+page.svelte +++ b/src/routes/c/[name]/+page.svelte @@ -2,22 +2,22 @@ import { browser } from '$app/environment' import { navigating, page } from '$app/state' import { profile } from '$lib/auth.svelte.js' + import { site } from '$lib/client/lemmy.svelte' import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte' import CommunityHeader from '$lib/components/lemmy/community/CommunityHeader.svelte' import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte' import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte' + import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post' import { Header } from '$lib/components/ui/layout' import Pageination from '$lib/components/ui/layout/Pageination.svelte' import Placeholder from '$lib/components/ui/Placeholder.svelte' import { t } from '$lib/i18n/translations.js' - import { site } from '$lib/client/lemmy.svelte' import { resumables } from '$lib/lemmy/item' import { setSessionStorage } from '$lib/session.js' import { settings } from '$lib/settings.svelte.js' import { Badge, Button, Modal, Note } from 'mono-svelte' import { onDestroy, onMount } from 'svelte' import { ArrowRight, ChartBar, Icon, Plus, XMark } from 'svelte-hero-icons' - import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post' let { data } = $props() @@ -27,14 +27,14 @@ if (browser) setSessionStorage( 'lastSeenCommunity', - data.community.value.community_view.community, + data.community.community_view.community, ) resumables.add({ - name: data.community.value.community_view.community.title, + name: data.community.community_view.community.title, type: 'community', url: page.url.toString(), - avatar: data.community.value.community_view.community.icon, + avatar: data.community.community_view.community.icon, }) }) @@ -47,6 +47,21 @@ }) + + {data.community.community_view.community.title} + + + {#if data.community.community_view.community.description} + + {/if} + + {#if sidebar} {#snippet customTitle()} @@ -54,8 +69,8 @@ {/snippet}
@@ -64,11 +79,11 @@
{#snippet extended()}
- +
{/snippet}
{#if profile.current.user} - {#if !data.community.value.discussion_languages.every( (l) => profile.current.user?.discussion_languages.includes(l), ) && profile.current.user.discussion_languages.length > 0} - {@const missing = data.community.value.discussion_languages.filter( + {#if !data.community.discussion_languages.every( (l) => profile.current.user?.discussion_languages.includes(l), ) && profile.current.user.discussion_languages.length > 0} + {@const missing = data.community.discussion_languages.filter( (i) => !profile.current.user?.discussion_languages.includes(i), )} @@ -118,7 +133,7 @@ {/if} {/if} -{#if data.community.value.community_view.blocked} +{#if data.community.community_view.blocked} data.client.lastSeen ?? 0, (v) => (data.client.lastSeen = v) + } + bind:params={data.params} + virtualList={{ itemHeights: data.client?.itemHeights ?? [] }} /> {/if} @@ -146,8 +163,7 @@ class="mt-auto" > typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`} > diff --git a/src/routes/c/[name]/+page.ts b/src/routes/c/[name]/+page.ts index 9dbc288d..2cf6a094 100644 --- a/src/routes/c/[name]/+page.ts +++ b/src/routes/c/[name]/+page.ts @@ -1,26 +1,47 @@ -import { postFeed } from '$lib/lemmy/postfeed.svelte.js' import { settings } from '$lib/settings.svelte' import type { SortType } from '$lib/client/types' +import { feed } from '$lib/lemmy/feeds/feed.svelte.js' +import { client } from '$lib/client/lemmy.svelte.js' +import { CommunityCard } from '$lib/components/lemmy/community' -export async function load({ params, fetch, url }) { +export async function load({ params, fetch, url, route }) { const cursor: string | undefined = url.searchParams.get('cursor') as | string | undefined - const page = Number(url.searchParams.get('page')) || undefined const sort: SortType = (url.searchParams.get('sort') as SortType) || settings.defaultSort.sort - return await postFeed({ - id: 'community', - url: url, - request: { - page: page, - page_cursor: cursor, - sort: sort, - limit: 20, - community_name: params.name, - }, - fetch: fetch, + const feedData = await feed(route.id, async (p) => { + const postPromise = client({ func: fetch }).getPosts(p) + const communityPromise = client({ func: fetch }).getCommunity({ + name: p.community_name, + }) + + return { + community: await communityPromise, + posts: (await postPromise).posts, + next_page: (await postPromise).next_page, + params: p, + client: {}, + } + }).load({ + community_name: params.name, + sort: sort, + limit: 20, + page_cursor: cursor, }) + + return { + ...feedData, + slots: { + sidebar: { + component: CommunityCard, + props: { + community_view: feedData.community.community_view, + moderators: feedData.community.moderators, + }, + }, + }, + } } diff --git a/src/routes/c/[name]/settings/+layout.svelte b/src/routes/c/[name]/settings/+layout.svelte index ccce3fb9..30bcd86f 100644 --- a/src/routes/c/[name]/settings/+layout.svelte +++ b/src/routes/c/[name]/settings/+layout.svelte @@ -19,6 +19,21 @@ ) + + {data.community.value.community_view.community.title} + + + {#if data.community.value.community_view.community.description} + + {/if} + +
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 } - {data.post.value.post_view.community.title} | {data.post.value.post_view - .post.name} + {data.post.community.title} | {data.post.post.name} - - {#if !data.post.value.post_view.post.local} + + {#if !data.post.post.local} {/if} - - {#if data.post.value.post_view.post.body} - + + {#if data.post.post.body} + {/if} - {#if mediaType(data.post.value.post_view.post.url) == 'image'} - - - {:else if data.post.value.post_view.post.thumbnail_url} - - + {#if mediaType(data.post.post.url) == 'image'} + + + {:else if data.post.post.thumbnail_url} + + {/if} @@ -134,54 +107,52 @@
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} />

- {#if data.post.value.post_view.post.body} + {#if data.post.post.body}
- +
{/if}
toast({ content: 'The post was edited successfully.', @@ -189,7 +160,7 @@ })} />
- {#await data.post.value.meta then meta} + {#await data.meta then meta} {@const crossposts = meta.cross_posts} {#if crossposts?.length > 0} @@ -216,8 +187,8 @@ {/if} {/await} -{#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}
- {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()} - + {/snippet} @@ -266,7 +237,7 @@ {/if} - {#await data.comments.value} + {#await data.comments}
{#each new Array(10) as _, index} {_} @@ -286,17 +257,16 @@
{/each}
- {:then passedComments} - {@const comments = new ReactiveState(passedComments)} + {:then comments} - {#if comments.value.comments.length == 0} + {#if comments.length == 0} {/if} {/await} - {#if data.post.value.post_view.counts.comments > 5} + {#if data.post.counts.comments > 5} {$t('routes.post.commentCount')} - {#snippet action()} - {data.post.value.post_view.counts.comments} + {data.post.counts.comments}