Merge pull request #349 from Xyphyn/infinite-scroll

feat: add infinite scroll
This commit is contained in:
Xylight authored and GitHub committed 2024-07-09 16:22:28 -07:00
commit 49a0e983df
19 files changed
+561 -110

No files matched your search

@@ -42,6 +42,7 @@
import Expandable from '$lib/components/ui/Expandable.svelte'
import { Popover } from 'mono-svelte'
import { t } from '$lib/translations.js'
import { createWindowVirtualizer } from '@tanstack/svelte-virtual'
export let data
@@ -112,7 +113,24 @@
$: remoteView =
$page.params.instance?.toLowerCase() != $instance.toLowerCase()
const test = 'wow'
const virtualizer = createWindowVirtualizer({
count: 0,
estimateSize: () => 50,
})
onMount(async () => {
const comments = await data.comments
$virtualizer.setOptions({ count: comments.comments.length })
})
let virtualItemEls: HTMLElement[] = []
$: items = $virtualizer.getVirtualItems()
$: {
if (virtualItemEls.length)
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
}
</script>
<svelte:head>
@@ -1,56 +1,57 @@
import { browser } from '$app/environment'
import { env } from '$env/dynamic/public'
import { profile } from '$lib/auth.js'
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
import { getClient } from '$lib/lemmy.js'
import { awaitIfServer } from '$lib/promise.js'
import { SSR_ENABLED, userSettings } from '$lib/settings.js'
import { error } from '@sveltejs/kit'
import { get } from 'svelte/store'
import { browser } from "$app/environment";
import { env } from "$env/dynamic/public";
import { profile } from "$lib/auth.js";
import CommunityCard from "$lib/components/lemmy/community/CommunityCard.svelte";
import { getClient } from "$lib/lemmy.js";
import { awaitIfServer } from "$lib/promise.js";
import { SSR_ENABLED, userSettings } from "$lib/settings.js";
import { error } from "@sveltejs/kit";
import type { GetComments } from "lemmy-js-client";
import { get } from "svelte/store";
export async function load({ params, url, fetch }) {
const thread = url.searchParams.get('thread')
let parentId: number | undefined
let showContext: string | undefined = undefined
const thread = url.searchParams.get("thread");
let parentId: number | undefined;
let showContext: string | undefined = undefined;
let max_depth = 3
let max_depth = 3;
if (thread) {
const split = thread.split('.')
const split = thread.split(".");
if (split.length >= 9) {
const sliced = split.slice(0, split.length - 4)
showContext = sliced[sliced.length - 1]
parentId = Number(split[split.length - 5])
const sliced = split.slice(0, split.length - 4);
showContext = sliced[sliced.length - 1];
parentId = Number(split[split.length - 5]);
} else {
parentId = Number(split[1])
parentId = Number(split[1]);
}
if (!Number.isInteger(parentId)) {
parentId = undefined
parentId = undefined;
}
}
if (parentId) {
max_depth = 10
max_depth = 10;
}
const sort = get(userSettings)?.defaultSort?.comments ?? 'Hot'
const sort = get(userSettings)?.defaultSort?.comments ?? "Hot";
const commentParams: any = {
const commentParams: GetComments = {
post_id: Number(params.id),
type_: 'All',
type_: "All",
limit: 50,
page: 1,
max_depth: max_depth,
saved_only: false,
sort: sort,
parent_id: parentId,
}
};
const comments = getClient(params.instance, fetch).getComments(commentParams);
const post = await getClient(params.instance.toLowerCase(), fetch).getPost({
id: Number(params.id),
})
const comments = getClient(params.instance, fetch).getComments(commentParams)
});
return {
thread: {
@@ -60,13 +61,13 @@ export async function load({ params, url, fetch }) {
post: post,
commentSort: sort,
comments: (await awaitIfServer(comments)).data,
// slots: {
// sidebar: {
// component: CommunityCard,
// props: {
// community_view: post.community_view,
// },
// },
// },
}
slots: {
sidebar: {
component: CommunityCard,
props: {
community_view: post.community_view,
},
},
},
};
}