feat: add community cards with a hacky slot parameter

This commit is contained in:
Xyphyn committed 2023-10-09 16:21:50 -07:00
1 parent b65d78b973
commit d2b27803b4
9 files changed
+78 -39

No files matched your search

+14 -18
View File
@@ -1,29 +1,25 @@
import { profile } from '$lib/auth.js'
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
import { getClient } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js'
import type { ListingType, SortType } from 'lemmy-js-client'
import { get } from 'svelte/store'
export async function load(req: any) {
const cursor: string | undefined = req.url.searchParams.get('cursor')
const page = Number(req.url.searchParams.get('page')) || undefined
const sort: SortType =
(req.url.searchParams.get('sort') as SortType) ||
get(userSettings).defaultSort.sort
const community = await getClient(undefined, req.fetch).getCommunity({
name: req.params.name,
})
return {
sort: sort,
page: page || 1,
posts: getClient(undefined, req.fetch).getPosts({
limit: 40,
community_name: req.params.name,
page: page,
sort: sort,
page_cursor: cursor
}),
community: getClient(undefined, req.fetch).getCommunity({
name: req.params.name,
}),
community: community,
slots: {
sidebar: {
component: CommunityCard,
props: {
community_view: community.community_view,
moderators: community.moderators,
},
},
},
}
}
+27
View File
@@ -0,0 +1,27 @@
import { client } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js'
import type { SortType } from 'lemmy-js-client'
import { get } from 'svelte/store'
export async function load({ params, fetch, url }) {
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) ||
get(userSettings).defaultSort.sort
return {
sort: sort,
page: page || 1,
posts: client({ func: fetch }).getPosts({
limit: 40,
community_name: params.name,
page: page,
sort: sort,
page_cursor: cursor,
}),
}
}