impr: switch to refactored feed handler (#654)
* impr: use refactored feed handler for main & community * refactor: re-add post preloading to feed handler * fix: remove unused setting & improve consistency of postmedia compact
This commit is contained in:
1 parent
2d01124bbf
commit
9460eec7e1
26 files changed
+489
-467
No files matched your search
@@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user