diff --git a/bun.lockb b/bun.lockb index 6592e57e..30c540f1 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 5072bf19..e860b196 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,6 @@ { "name": "photon-lemmy", "version": "1.30.4", - "private": true, - "scripts": { - "dev": "vite dev", - "build": "vite build", - "test": "vitest", - "preview": "vite preview", - "start": "node build/index.js", - "bunstart": "bun build/index.js", - "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", - "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" - }, "devDependencies": { "@catdadcode/svelte-adapter-bun": "^0.5.7", "@dicebear/core": "^8.0.1", @@ -22,6 +11,7 @@ "@sveltejs/kit": "latest", "@sveltejs/vite-plugin-svelte": "^3.0.0", "@tailwindcss/container-queries": "^0.1.1", + "@tanstack/svelte-virtual": "^3.8.1", "@types/markdown-it": "^12.2.3", "@types/markdown-it-container": "^2.0.6", "@types/nprogress": "^0.2.0", @@ -40,7 +30,7 @@ "svelte": "latest", "svelte-check": "^3.0.1", "svelte-hero-icons": "^5.0.0", - "svelte-tiny-virtual-list": "^2.0.5", + "svelte-infinite-scroll": "^2.0.1", "sveltekit-i18n": "^2.4.2", "tailwindcss": "^3.3.3", "tslib": "^2.4.1", @@ -50,5 +40,16 @@ "vitest": "^1.0.0", "workbox-window": "^7.0.0" }, + "private": true, + "scripts": { + "dev": "vite dev", + "build": "vite build", + "test": "vitest", + "preview": "vite preview", + "start": "node build/index.js", + "bunstart": "bun build/index.js", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" + }, "type": "module" } diff --git a/src/lib/components/lemmy/community/CommunityLink.svelte b/src/lib/components/lemmy/community/CommunityLink.svelte index e3a4cc1a..6bffc308 100644 --- a/src/lib/components/lemmy/community/CommunityLink.svelte +++ b/src/lib/components/lemmy/community/CommunityLink.svelte @@ -16,6 +16,7 @@ class="items-center flex flex-row gap-2 hover:underline max-w-full min-w-0 {$$props.class || ''}" href="/c/{community.name}@{new URL(community.actor_id).hostname}" + data-sveltekit-preload-data="tap" > {#if avatar} { onClick(e) }} + style={$$props.style ?? ''} > import Link, { parseURL } from '$lib/components/input/Link.svelte' - import { Material } from 'mono-svelte' + import { Button, Material } from 'mono-svelte' import { Icon, Link as LinkIcon } from 'svelte-hero-icons' import { optimizeImageURL } from './helpers' @@ -64,12 +64,15 @@ {/if} {:else} - - + {#if richURL}
{richURL.hostname} @@ -80,7 +83,7 @@ {:else} {url} {/if} - + {#if thumbnail_url && !compact} diff --git a/src/lib/components/lemmy/post/PostFeed.svelte b/src/lib/components/lemmy/post/feed/PostFeed.svelte similarity index 90% rename from src/lib/components/lemmy/post/PostFeed.svelte rename to src/lib/components/lemmy/post/feed/PostFeed.svelte index 9bda3040..25fcf538 100644 --- a/src/lib/components/lemmy/post/PostFeed.svelte +++ b/src/lib/components/lemmy/post/feed/PostFeed.svelte @@ -7,6 +7,11 @@ import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons' import { expoOut } from 'svelte/easing' import { fly, slide } from 'svelte/transition' + import { browser } from '$app/environment' + import { afterUpdate, onMount, tick, type SvelteComponent } from 'svelte' + import { createWindowVirtualizer } from '@tanstack/svelte-virtual' + import { afterNavigate, beforeNavigate } from '$app/navigation' + import { _posts } from '../../../../../routes/+page.svelte' type PostViewWithCrossposts = PostView & { withCrossposts: true @@ -98,16 +103,16 @@
{:else} - {#each combinedPosts as post, index (post.post.id)} + {#each combinedPosts as post, index} {#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
  • { - combinedPosts = combinedPosts.toSpliced(index, 1) + posts = posts.toSpliced(index, 1) }} > @@ -175,4 +177,5 @@ {/if} {/each} {/if} + diff --git a/src/lib/components/lemmy/post/feed/VirtualFeed.svelte b/src/lib/components/lemmy/post/feed/VirtualFeed.svelte new file mode 100644 index 00000000..d51c5355 --- /dev/null +++ b/src/lib/components/lemmy/post/feed/VirtualFeed.svelte @@ -0,0 +1,222 @@ + + +
      + {#if posts?.length == 0} +
      + + + +
      + {:else} + + +
      +
      + {#each items as row, index (row.index)} +
    • + { + posts = posts.toSpliced(row.index, 1) + }} + > + + + + + +
    • + {/each} +
      +
      + + + {/if} + +
    diff --git a/src/lib/components/lemmy/user/UserLink.svelte b/src/lib/components/lemmy/user/UserLink.svelte index 34d33989..614b4e78 100644 --- a/src/lib/components/lemmy/user/UserLink.svelte +++ b/src/lib/components/lemmy/user/UserLink.svelte @@ -19,6 +19,7 @@ class="items-center flex flex-row gap-1 hover:underline max-w-full min-w-0 {$$props.class ?? ''}" href="/u/{user.name}@{new URL(user.actor_id).hostname}" + data-sveltekit-preload-data="tap" > {#if avatar} import { goto } from '$app/navigation' import { page } from '$app/stores' + import { t } from '$lib/translations' import { Button } from 'mono-svelte' import { Icon, XMark } from 'svelte-hero-icons' @@ -18,6 +19,6 @@ {$page.error?.message} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index cbc17fb2..0f32cd93 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,26 +1,143 @@ + +
    @@ -34,8 +151,48 @@
    - -
    + + + {#if $userSettings.infiniteScroll && browser} + {#if error} +
    +
    + +
    +
    {error}
    + +
    + {:else if hasMore} +
    +
    +
    +
    +
    +
    +
    +
    + {/if} + + {/if} +
    + -
    + + + diff --git a/src/routes/+page.ts b/src/routes/+page.ts index 66708e5b..448796da 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -1,10 +1,11 @@ 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' +import type { GetPostsResponse, ListingType, SortType } from 'lemmy-js-client' +import { get, writable } from 'svelte/store' import { error } from '@sveltejs/kit' -import { profile } from '$lib/auth.js' -import { feature } from '$lib/version.js' +import { _posts, shouldReload, type CachedPosts } from './+page.svelte' +import { browser } from '$app/environment' +import { instance } from '$lib/instance' export async function load({ url, fetch }) { const cursor = url.searchParams.get('cursor') as string | undefined @@ -18,14 +19,29 @@ export async function load({ url, fetch }) { const listingType: ListingType = (url.searchParams.get('type') as ListingType) || settings.defaultSort.feed - const posts = await getClient(undefined, fetch).getPosts({ - limit: 20, - page: page, - sort: sort, - type_: listingType, - page_cursor: cursor, - show_hidden: settings.posts.showHidden, - }) + const cached: CachedPosts | undefined = get(_posts) + + const posts = shouldReload(cached, url.searchParams.toString(), get(instance)) + ? await getClient(undefined, fetch).getPosts({ + limit: 20, + page: page, + sort: sort, + type_: listingType, + page_cursor: cursor, + show_hidden: settings.posts.showHidden, + }) + : cached.data + + if ( + shouldReload(cached, url.searchParams.toString(), get(instance)) && + browser + ) + _posts.set({ + data: posts, + params: url.searchParams, + lastSeen: 0, + instance: get(instance), + }) try { return { diff --git a/src/routes/c/[name]/+page.svelte b/src/routes/c/[name]/+page.svelte index 1ba66006..5f5b0dd8 100644 --- a/src/routes/c/[name]/+page.svelte +++ b/src/routes/c/[name]/+page.svelte @@ -7,7 +7,7 @@ import { fullCommunityName, searchParam } from '$lib/util.js' import { onDestroy, onMount } from 'svelte' import { setSessionStorage } from '$lib/session.js' - import PostFeed from '$lib/components/lemmy/post/PostFeed.svelte' + import PostFeed from '$lib/components/lemmy/post/feed/PostFeed.svelte' import { Button, Modal, toast } from 'mono-svelte' import { afterNavigate } from '$app/navigation' import { browser } from '$app/environment' diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte index 08bbe20e..f6477369 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/+page.svelte @@ -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)) + } diff --git a/src/routes/post/[instance]/[id=integer]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts index dc884fac..134e126a 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -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, + }, + }, + }, + }; } diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte index cb0b9113..662960c7 100644 --- a/src/routes/settings/+page.svelte +++ b/src/routes/settings/+page.svelte @@ -222,6 +222,12 @@ +
    - {#if Object.values(supportedPlatforms).some((v) => v == false)} + {#if Object.values(supportedPlatforms).some((v) => v == false) || beta}
    - {#if supportedPlatforms.desktop} - - - {$t('settings.desktop')} - + {#if beta} + Beta {/if} - {#if supportedPlatforms.tablet} - - - {$t('settings.tablet')} - - {/if} - {#if supportedPlatforms.mobile} - - - {$t('settings.mobile')} - + {#if Object.values(supportedPlatforms).some((v) => v == false)} + {#if supportedPlatforms.desktop} + + + {$t('settings.desktop')} + + {/if} + {#if supportedPlatforms.tablet} + + + {$t('settings.tablet')} + + {/if} + {#if supportedPlatforms.mobile} + + + {$t('settings.mobile')} + + {/if} {/if}
    {/if}