fix: re-add community view

This commit is contained in:
Xylight committed 2024-07-03 15:55:57 -07:00
1 parent cd7622bc26
commit e4b340e41b
1 file changed
+35 -35
@@ -1,57 +1,57 @@
import { browser } from '$app/environment' import { browser } from "$app/environment";
import { env } from '$env/dynamic/public' import { env } from "$env/dynamic/public";
import { profile } from '$lib/auth.js' import { profile } from "$lib/auth.js";
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte' import CommunityCard from "$lib/components/lemmy/community/CommunityCard.svelte";
import { getClient } from '$lib/lemmy.js' import { getClient } from "$lib/lemmy.js";
import { awaitIfServer } from '$lib/promise.js' import { awaitIfServer } from "$lib/promise.js";
import { SSR_ENABLED, userSettings } from '$lib/settings.js' import { SSR_ENABLED, userSettings } from "$lib/settings.js";
import { error } from '@sveltejs/kit' import { error } from "@sveltejs/kit";
import type { GetComments } from 'lemmy-js-client' import type { GetComments } from "lemmy-js-client";
import { get } from 'svelte/store' import { get } from "svelte/store";
export async function load({ params, url, fetch }) { export async function load({ params, url, fetch }) {
const thread = url.searchParams.get('thread') const thread = url.searchParams.get("thread");
let parentId: number | undefined let parentId: number | undefined;
let showContext: string | undefined = undefined let showContext: string | undefined = undefined;
let max_depth = 3 let max_depth = 3;
if (thread) { if (thread) {
const split = thread.split('.') const split = thread.split(".");
if (split.length >= 9) { if (split.length >= 9) {
const sliced = split.slice(0, split.length - 4) const sliced = split.slice(0, split.length - 4);
showContext = sliced[sliced.length - 1] showContext = sliced[sliced.length - 1];
parentId = Number(split[split.length - 5]) parentId = Number(split[split.length - 5]);
} else { } else {
parentId = Number(split[1]) parentId = Number(split[1]);
} }
if (!Number.isInteger(parentId)) { if (!Number.isInteger(parentId)) {
parentId = undefined parentId = undefined;
} }
} }
if (parentId) { if (parentId) {
max_depth = 10 max_depth = 10;
} }
const sort = get(userSettings)?.defaultSort?.comments ?? 'Hot' const sort = get(userSettings)?.defaultSort?.comments ?? "Hot";
const commentParams: GetComments = { const commentParams: GetComments = {
post_id: Number(params.id), post_id: Number(params.id),
type_: 'All', type_: "All",
limit: 50, limit: 50,
page: 1, page: 1,
max_depth: max_depth, max_depth: max_depth,
saved_only: false, saved_only: false,
sort: sort, sort: sort,
parent_id: parentId, parent_id: parentId,
} };
const comments = getClient(params.instance, fetch).getComments(commentParams) const comments = getClient(params.instance, fetch).getComments(commentParams);
const post = await getClient(params.instance.toLowerCase(), fetch).getPost({ const post = await getClient(params.instance.toLowerCase(), fetch).getPost({
id: Number(params.id), id: Number(params.id),
}) });
return { return {
thread: { thread: {
@@ -61,13 +61,13 @@ export async function load({ params, url, fetch }) {
post: post, post: post,
commentSort: sort, commentSort: sort,
comments: (await awaitIfServer(comments)).data, comments: (await awaitIfServer(comments)).data,
// slots: { slots: {
// sidebar: { sidebar: {
// component: CommunityCard, component: CommunityCard,
// props: { props: {
// community_view: post.community_view, community_view: post.community_view,
// }, },
// }, },
// }, },
} };
} }