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