impr: enhance preload logic
This commit is contained in:
4 files changed
+38
-24
No files matched your search
+1
-1
@@ -13,7 +13,7 @@
|
||||
>
|
||||
<svg width="50" height="50"><use width="50" height="50" xlink:href='/img/logo-isolated.svg' href="/img/logo-isolated.svg"></use></svg>
|
||||
</div>
|
||||
<div style="display: contents;">
|
||||
<div style="display: contents;" data-sveltekit-preload-code>
|
||||
%sveltekit.body%
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -9,7 +9,10 @@ import type {
|
||||
GetPersonDetailsResponse,
|
||||
GetPost,
|
||||
GetPosts,
|
||||
ListCommunitiesResponse,
|
||||
ListingType,
|
||||
PostView,
|
||||
SortType,
|
||||
TopicView,
|
||||
} from '$lib/api/types'
|
||||
import { profile } from '$lib/app/auth.svelte'
|
||||
@@ -28,9 +31,7 @@ export class Feed<Params, Response> {
|
||||
}
|
||||
|
||||
async load(params: Params) {
|
||||
if (
|
||||
!recursiveEqual(params, this.#lastParams)
|
||||
) {
|
||||
if (!recursiveEqual(params, this.#lastParams)) {
|
||||
this.#data = undefined
|
||||
}
|
||||
this.#lastParams = params
|
||||
@@ -103,6 +104,15 @@ export interface FeedTypes {
|
||||
}
|
||||
},
|
||||
]
|
||||
'/explore/communities': [
|
||||
{
|
||||
type: ListingType
|
||||
sort: SortType
|
||||
query: string
|
||||
page: number
|
||||
},
|
||||
ListCommunitiesResponse,
|
||||
]
|
||||
'/f/[id]': [
|
||||
GetPosts,
|
||||
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
let { data } = $props()
|
||||
|
||||
let showTop = $derived(
|
||||
(data.query ?? '' != '') &&
|
||||
data.communities.value.length > 0 &&
|
||||
data.page == 1,
|
||||
(data.query ?? '' != '') && data.communities.length > 0 && data.page == 1,
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -40,7 +38,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<ul class="flex flex-col h-full">
|
||||
{#if data.communities.value.length == 0}
|
||||
{#if data.communities.length == 0}
|
||||
<Placeholder
|
||||
icon={QuestionMarkCircle}
|
||||
title={$t('routes.search.noResults.title')}
|
||||
@@ -55,7 +53,7 @@
|
||||
<div
|
||||
class="grid md:grid-cols-2 lg:grid-cols-3 gap-4 items-center mb-6 border-0!"
|
||||
>
|
||||
{#each data.communities.value.slice(0, 3) as community, index (community.community.id)}
|
||||
{#each data.communities.slice(0, 3) as community, index (community.community.id)}
|
||||
<div
|
||||
class="h-full"
|
||||
in:fly|global={{
|
||||
@@ -73,13 +71,13 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if data.communities.value.slice(showTop ? 3 : 0).length > 0}
|
||||
{#if data.communities.slice(showTop ? 3 : 0).length > 0}
|
||||
<EndPlaceholder size="lg" margin="md">
|
||||
{$t('routes.search.other')}
|
||||
</EndPlaceholder>
|
||||
{/if}
|
||||
{#if data.communities.value}
|
||||
{@const sliced = data.communities.value.slice(showTop ? 3 : 0)}
|
||||
{#if data.communities}
|
||||
{@const sliced = data.communities.slice(showTop ? 3 : 0)}
|
||||
<CommonList items={sliced}>
|
||||
{#snippet item(community)}
|
||||
<CommunityItem
|
||||
@@ -92,7 +90,7 @@
|
||||
{/if}
|
||||
</ul>
|
||||
{/if}
|
||||
{#if data.communities.value.length > 0}
|
||||
{#if data.communities.length > 0}
|
||||
<Fixate placement="bottom">
|
||||
<Pageination
|
||||
page={Number(page.url.searchParams.get('page')) || 1}
|
||||
|
||||
@@ -1,32 +1,38 @@
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import { ReactiveState } from '$lib/app/util.svelte'
|
||||
import { feed } from '$lib/feature/feeds/feed.svelte.js'
|
||||
|
||||
export async function load({ fetch, parent }) {
|
||||
const { page, query, sort, type, typeInstance } = await parent()
|
||||
|
||||
const communities =
|
||||
const feedData = await feed('/explore/communities', async (params) =>
|
||||
query != ''
|
||||
? await client({ func: fetch, instanceURL: typeInstance }).search({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
page: params.page,
|
||||
sort: params.sort,
|
||||
type_: 'Communities',
|
||||
listing_type: type,
|
||||
q: query,
|
||||
listing_type: params.type,
|
||||
q: params.query,
|
||||
})
|
||||
: await client({
|
||||
func: fetch,
|
||||
instanceURL: typeInstance,
|
||||
}).listCommunities({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: type,
|
||||
page: params.page,
|
||||
sort: params.sort,
|
||||
type_: params.type,
|
||||
show_nsfw: true,
|
||||
})
|
||||
}),
|
||||
).load({
|
||||
page,
|
||||
query,
|
||||
sort,
|
||||
type,
|
||||
})
|
||||
|
||||
return {
|
||||
communities: new ReactiveState(communities.communities),
|
||||
communities: feedData.communities,
|
||||
type: type,
|
||||
sort: sort,
|
||||
query: query,
|
||||
|
||||
Reference in new issue
Block a user