Merge pull request #349 from Xyphyn/infinite-scroll
feat: add infinite scroll
This commit is contained in:
19 files changed
+561
-110
No files matched your search
@@ -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}
|
||||
<Avatar
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<Material
|
||||
color={view != 'card' ? 'none' : 'distinct'}
|
||||
class="relative max-w-full min-w-0 w-full group cursor-pointer
|
||||
class="post relative max-w-full min-w-0 w-full group cursor-pointer
|
||||
{view != 'card' ? 'bg-transparent !border-0' : 'p-5'} {view == 'compact'
|
||||
? 'py-4 list-type'
|
||||
: view == 'list'
|
||||
@@ -95,6 +95,7 @@
|
||||
on:click={(e) => {
|
||||
onClick(e)
|
||||
}}
|
||||
style={$$props.style ?? ''}
|
||||
>
|
||||
<PostMeta
|
||||
community={post.community}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
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}
|
||||
</Material>
|
||||
{:else}
|
||||
<Link
|
||||
<Button
|
||||
href={url}
|
||||
target="_blank"
|
||||
class="text-slate-700 dark:text-zinc-300 inline-flex items-center gap-1 text-sm"
|
||||
class="text-slate-700 dark:text-zinc-300 inline-flex items-center gap-1 text-xs overflow-hidden w-max max-w-full"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon src={LinkIcon} size="14" mini slot="icon" class="flex-shrink-0" />
|
||||
<Icon src={LinkIcon} size="14" mini slot="prefix" class="flex-shrink-0" />
|
||||
{#if richURL}
|
||||
<div class="flex max-w-full overflow-hidden">
|
||||
{richURL.hostname}
|
||||
@@ -80,7 +83,7 @@
|
||||
{:else}
|
||||
{url}
|
||||
{/if}
|
||||
</Link>
|
||||
</Button>
|
||||
{#if thumbnail_url && !compact}
|
||||
<a href={url} target="_blank">
|
||||
<img
|
||||
|
||||
@@ -253,6 +253,7 @@
|
||||
class:text-slate-600={$userSettings.markReadPosts && read}
|
||||
class:dark:text-zinc-400={$userSettings.markReadPosts && read}
|
||||
style="grid-area: title;"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
<Markdown source={title} inline noStyle class="leading-[1.3]"></Markdown>
|
||||
</a>
|
||||
|
||||
+12
-9
@@ -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 @@
|
||||
</Placeholder>
|
||||
</div>
|
||||
{: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)}
|
||||
<li
|
||||
in:fly|global={{
|
||||
y: -8,
|
||||
duration: index < 4 ? 500 : 0,
|
||||
duration: 500,
|
||||
opacity: 0,
|
||||
delay: index < 4 ? index * 100 : 0,
|
||||
delay: 100 + index * 20,
|
||||
}}
|
||||
class="relative"
|
||||
class="relative post-container"
|
||||
>
|
||||
<Post
|
||||
hideCommunity={community}
|
||||
@@ -116,12 +121,9 @@
|
||||
? 'compact'
|
||||
: $userSettings.view}
|
||||
{post}
|
||||
class="transition-all duration-250 {post.withCrossposts &&
|
||||
viewPost != post.post.id
|
||||
? ''
|
||||
: ''}"
|
||||
class="transition-all duration-250"
|
||||
on:hide={() => {
|
||||
combinedPosts = combinedPosts.toSpliced(index, 1)
|
||||
posts = posts.toSpliced(index, 1)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
@@ -175,4 +177,5 @@
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
<slot />
|
||||
</ul>
|
||||
@@ -0,0 +1,222 @@
|
||||
<script lang="ts">
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { Badge, Button } from 'mono-svelte'
|
||||
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
|
||||
crossposts: PostView[]
|
||||
}
|
||||
type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
|
||||
|
||||
export let posts: PostView[]
|
||||
export let community: boolean = false
|
||||
|
||||
const addCrosspostProperty = (
|
||||
post: PostView,
|
||||
crossposts: PostView[]
|
||||
): PostViewWithCrossposts => ({
|
||||
...post,
|
||||
crossposts: crossposts,
|
||||
withCrossposts: true,
|
||||
})
|
||||
|
||||
const combineCrossposts = (
|
||||
posts: PostView[]
|
||||
): (PostViewWithCrossposts | PostViewWithoutCrossposts)[] => {
|
||||
const urlMap = new Map<
|
||||
string,
|
||||
PostViewWithCrossposts | PostViewWithoutCrossposts
|
||||
>()
|
||||
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
|
||||
const seenUrls = new Set<string>()
|
||||
|
||||
posts?.forEach((post) => {
|
||||
if (
|
||||
!post ||
|
||||
($userSettings.hidePosts.deleted && post.post.deleted) ||
|
||||
($userSettings.hidePosts.removed && post.post.removed)
|
||||
)
|
||||
return
|
||||
if (!post?.post?.url) {
|
||||
results.push(post)
|
||||
return
|
||||
}
|
||||
|
||||
let existing = urlMap.get(post.post.url)
|
||||
if (existing) {
|
||||
existing.withCrossposts = true
|
||||
if (existing.withCrossposts) {
|
||||
existing.crossposts = [...(existing.crossposts || []), post]
|
||||
}
|
||||
|
||||
urlMap.set(post.post.url, existing)
|
||||
} else {
|
||||
urlMap.set(post.post.url, post)
|
||||
results.push(post)
|
||||
}
|
||||
seenUrls.add(post.post.url)
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
// $: combinedPosts = combineCrossposts(posts)
|
||||
|
||||
let viewPost: number = -1
|
||||
|
||||
const virtualizer = createWindowVirtualizer({
|
||||
count: posts.length,
|
||||
estimateSize: () => 150,
|
||||
})
|
||||
|
||||
$: if (posts.length)
|
||||
$virtualizer.setOptions({
|
||||
count: posts.length,
|
||||
})
|
||||
|
||||
let virtualItemEls: HTMLElement[] = []
|
||||
|
||||
$: items = $virtualizer.getVirtualItems()
|
||||
$: {
|
||||
if (virtualItemEls.length)
|
||||
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
|
||||
}
|
||||
|
||||
afterNavigate(() => {
|
||||
$virtualizer.scrollToIndex($_posts?.lastSeen)
|
||||
})
|
||||
</script>
|
||||
|
||||
<ul
|
||||
class="flex flex-col list-none {$userSettings.view == 'card'
|
||||
? 'gap-3 md:gap-4'
|
||||
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
|
||||
style={$userSettings.leftAlign
|
||||
? `--template-areas:
|
||||
'media meta'
|
||||
'media title'
|
||||
'media body'
|
||||
'embed embed'
|
||||
'actions actions'; --template-columns: auto 1fr;`
|
||||
: ``}
|
||||
>
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
<Placeholder
|
||||
icon={ArchiveBox}
|
||||
title="No posts"
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- {#each combinedPosts as post, index} -->
|
||||
<!-- {#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)} -->
|
||||
<div
|
||||
style="position:relative; height: {browser
|
||||
? `${$virtualizer.getTotalSize()}px`
|
||||
: '100%'}; width: 100%;"
|
||||
>
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items[0]
|
||||
? items[0].start
|
||||
: 0}px);"
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
id="feed"
|
||||
>
|
||||
{#each items as row, index (row.index)}
|
||||
<li
|
||||
in:fly|global={{
|
||||
y: -8,
|
||||
duration: 500,
|
||||
opacity: 0,
|
||||
delay: 100 + index * 20,
|
||||
}}
|
||||
bind:this={virtualItemEls[index]}
|
||||
data-index={row.index}
|
||||
class="relative post-container"
|
||||
>
|
||||
<Post
|
||||
hideCommunity={community}
|
||||
view={(posts[row.index].post.featured_community ||
|
||||
posts[row.index].post.featured_local) &&
|
||||
$userSettings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: $userSettings.view}
|
||||
post={posts[row.index]}
|
||||
class="transition-all duration-250"
|
||||
on:hide={() => {
|
||||
posts = posts.toSpliced(row.index, 1)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
<!-- {#if posts[index].withCrossposts}
|
||||
<button
|
||||
on:click={() => {
|
||||
if (viewPost == posts[index].post.id) viewPost = -1
|
||||
else viewPost = posts[index].post.id
|
||||
}}
|
||||
>
|
||||
<Badge
|
||||
class="z-10 backdrop-blur-xl hover:brightness-110 cursor-pointer transition-all"
|
||||
color="gray-subtle"
|
||||
>
|
||||
{#if viewPost == posts[index].post.id}
|
||||
<Icon mini src={Minus} size="14" />
|
||||
{:else}
|
||||
<Icon mini src={Plus} size="14" />
|
||||
{/if}
|
||||
{posts[index].crossposts.length} crosspost{posts[index]
|
||||
.crossposts.length == 1
|
||||
? ''
|
||||
: 's'}
|
||||
</Badge>
|
||||
</button>{/if} -->
|
||||
</svelte:fragment>
|
||||
</Post>
|
||||
<!-- {#if posts[index].withCrossposts && viewPost == posts[index].post.id}
|
||||
<div
|
||||
transition:slide|global={{
|
||||
axis: 'y',
|
||||
duration: 500,
|
||||
easing: expoOut,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
class="text-sm flex flex-row gap-2 items-center"
|
||||
class:my-4={$userSettings.view == 'card'}
|
||||
>
|
||||
Crossposts <hr class="w-full dark:border-zinc-800" />
|
||||
{posts[index].crossposts.length}
|
||||
</span>
|
||||
{#each posts[index].crossposts as crosspost, index}
|
||||
<div class="w-full transition-all mb-4">
|
||||
<Post post={crosspost} view={$userSettings.view} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if} -->
|
||||
</li>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
<!-- {/if} -->
|
||||
<!-- {/each} -->
|
||||
{/if}
|
||||
<slot />
|
||||
</ul>
|
||||
@@ -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}
|
||||
<Avatar
|
||||
|
||||
@@ -473,7 +473,8 @@
|
||||
},
|
||||
"message": {
|
||||
"success": "Success",
|
||||
"error": "Error"
|
||||
"error": "Error",
|
||||
"retry": "Retry"
|
||||
},
|
||||
"toast": {
|
||||
"noComments": "The API returned no comments.",
|
||||
@@ -598,6 +599,10 @@
|
||||
"title": "Default sort",
|
||||
"description": "The default sorting to use in feeds."
|
||||
},
|
||||
"infiniteScroll": {
|
||||
"title": "Infinite scroll",
|
||||
"description": "New posts are added as you scroll down, without having to click 'next'."
|
||||
},
|
||||
"postsInNewTab": {
|
||||
"title": "Open posts in new tab",
|
||||
"description": "Open posts in a separate tab instead of the current."
|
||||
|
||||
@@ -88,6 +88,7 @@ interface Settings {
|
||||
compactFeatured: boolean
|
||||
showHidden: boolean
|
||||
}
|
||||
infiniteScroll: boolean
|
||||
language: string | null
|
||||
useRtl: boolean
|
||||
translator: string | undefined
|
||||
@@ -160,6 +161,7 @@ export const defaultSettings: Settings = {
|
||||
compactFeatured: toBool(env.PUBLIC_COMPACT_FEATURED) ?? true,
|
||||
showHidden: false,
|
||||
},
|
||||
infiniteScroll: true,
|
||||
language: env.PUBLIC_LANGUAGE ?? null,
|
||||
useRtl: false,
|
||||
translator: env.PUBLIC_TRANSLATOR ?? undefined,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
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'
|
||||
</script>
|
||||
@@ -18,6 +19,6 @@
|
||||
{$page.error?.message}
|
||||
</code>
|
||||
<Button size="sm" class="w-max" on:click={() => goto($page.url)}>
|
||||
Retry
|
||||
{$t('message.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
+178
-15
@@ -1,26 +1,143 @@
|
||||
<script lang="ts" context="module">
|
||||
export interface CachedPosts {
|
||||
data: GetPostsResponse
|
||||
params: URLSearchParams
|
||||
lastSeen: number
|
||||
instance: string
|
||||
}
|
||||
|
||||
export const _posts = writable<CachedPosts>(undefined)
|
||||
|
||||
export const shouldReload = (
|
||||
cache: CachedPosts | undefined,
|
||||
params: string,
|
||||
instance: string
|
||||
): boolean =>
|
||||
cache?.instance != instance || cache?.params.toString() != params
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores'
|
||||
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||
import { searchParam } from '$lib/util.js'
|
||||
import PostFeed from '$lib/components/lemmy/post/PostFeed.svelte'
|
||||
import { Button, Modal, Select, Spinner } from 'mono-svelte'
|
||||
import { ChartBar, GlobeAmericas, Icon, ServerStack } from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { site } from '$lib/lemmy.js'
|
||||
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { feature } from '$lib/version.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import {
|
||||
ChartBar,
|
||||
ExclamationCircle,
|
||||
ExclamationTriangle,
|
||||
GlobeAmericas,
|
||||
Icon,
|
||||
ServerStack,
|
||||
} from 'svelte-hero-icons'
|
||||
import { getClient, site } from '$lib/lemmy.js'
|
||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { t } from '$lib/translations.js'
|
||||
import { enhance } from '$app/forms'
|
||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||
import { Button, Material, Spinner } from 'mono-svelte'
|
||||
import { get, writable } from 'svelte/store'
|
||||
import type { GetPostsResponse } from 'lemmy-js-client'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { afterNavigate } from '$app/navigation'
|
||||
import { browser } from '$app/environment'
|
||||
import { onMount } from 'svelte'
|
||||
import { instance } from '$lib/instance.js'
|
||||
import VirtualFeed from '$lib/components/lemmy/post/feed/VirtualFeed.svelte'
|
||||
import PostFeed from '$lib/components/lemmy/post/feed/PostFeed.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
const limit = 20
|
||||
let hasMore = data.posts.posts.length != 0
|
||||
let error: any = undefined
|
||||
let loading = false
|
||||
|
||||
async function loadMore() {
|
||||
if (!hasMore || loading) return
|
||||
|
||||
try {
|
||||
loading = true
|
||||
const newPosts = await getClient()
|
||||
.getPosts({
|
||||
limit: limit,
|
||||
page: data.page,
|
||||
sort: data.sort,
|
||||
type_: data.listingType,
|
||||
page_cursor: data.cursor.next,
|
||||
})
|
||||
.catch((e) => {
|
||||
throw new Error(e)
|
||||
})
|
||||
|
||||
error = null
|
||||
|
||||
hasMore = newPosts.posts.length != 0
|
||||
|
||||
data.cursor.next = newPosts.next_page
|
||||
data.posts.posts = [...data.posts.posts, ...newPosts.posts]
|
||||
|
||||
_posts.update((ps) => ({
|
||||
data: data.posts,
|
||||
params: ps.params,
|
||||
lastSeen: ps.lastSeen,
|
||||
instance: ps.instance,
|
||||
}))
|
||||
|
||||
loading = false
|
||||
} catch (e) {
|
||||
error = e
|
||||
loading = false
|
||||
}
|
||||
}
|
||||
|
||||
const callback: IntersectionObserverCallback = (entries, observer) => {
|
||||
entries.forEach((entry) => {
|
||||
if (!entry.isIntersecting) return
|
||||
|
||||
const element = entry.target as HTMLElement
|
||||
const id = element.getAttribute('data-index')
|
||||
|
||||
if (!id) return
|
||||
|
||||
$_posts.lastSeen = Number(id)
|
||||
observer.unobserve(element)
|
||||
})
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const observer = new IntersectionObserver(callback, {
|
||||
root: null,
|
||||
rootMargin: '0px',
|
||||
threshold: 0.25,
|
||||
})
|
||||
|
||||
const elements = document.querySelectorAll('.post-container')
|
||||
elements.forEach((el) => observer.observe(el))
|
||||
|
||||
const postContainer = document.querySelector('#feed')
|
||||
if (postContainer) {
|
||||
const mutationObserver = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (mutation.type === 'childList') {
|
||||
mutation.addedNodes.forEach((node) => {
|
||||
if (
|
||||
node instanceof HTMLElement &&
|
||||
node.classList.contains('post-container')
|
||||
) {
|
||||
observer.observe(node)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
mutationObserver.observe(postContainer, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
||||
@@ -34,8 +151,48 @@
|
||||
<ViewSelect />
|
||||
</div>
|
||||
</div>
|
||||
<PostFeed posts={data.posts.posts} />
|
||||
<div class="mt-auto">
|
||||
|
||||
<svelte:component
|
||||
this={browser ? VirtualFeed : PostFeed}
|
||||
posts={data.posts.posts}
|
||||
>
|
||||
{#if $userSettings.infiniteScroll && browser}
|
||||
{#if error}
|
||||
<div
|
||||
class="flex flex-col justify-center items-center
|
||||
rounded-xl gap-2 py-8 mt-6
|
||||
border !border-b !border-red-500 bg-red-500/5 px-4"
|
||||
>
|
||||
<div class="bg-red-500/30 rounded-full p-3 text-red-500">
|
||||
<Icon src={ExclamationTriangle} size="24" solid></Icon>
|
||||
</div>
|
||||
<pre class="py-0.5">{error}</pre>
|
||||
<Button
|
||||
color="primary"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
on:click={loadMore}
|
||||
>
|
||||
{$t('message.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
{:else if hasMore}
|
||||
<div class="w-full flex flex-col skeleton gap-2 animate-pulse pt-6">
|
||||
<div class="w-96 h-8"></div>
|
||||
<div class="w-full h-48"></div>
|
||||
<div class="!bg-transparent h-8 flex justify-between">
|
||||
<div class="w-48 h-8"></div>
|
||||
<div class="w-24 h-8"></div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<InfiniteScroll window threshold={1000} on:loadMore={loadMore} />
|
||||
{/if}
|
||||
</svelte:component>
|
||||
<svelte:element
|
||||
this={$userSettings.infiniteScroll ? 'noscript' : 'div'}
|
||||
class="mt-auto"
|
||||
>
|
||||
<Pageination
|
||||
page={data.page}
|
||||
cursor={{ next: data.cursor.next, back: data.cursor.back }}
|
||||
@@ -52,5 +209,11 @@
|
||||
})}
|
||||
</span>
|
||||
</Pageination>
|
||||
</div>
|
||||
</svelte:element>
|
||||
</div>
|
||||
|
||||
<style lang="postcss">
|
||||
.skeleton * {
|
||||
@apply bg-slate-100 dark:bg-zinc-800 rounded-md;
|
||||
}
|
||||
</style>
|
||||
+28
-12
@@ -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 {
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -222,6 +222,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</Setting>
|
||||
<ToggleSetting
|
||||
beta
|
||||
bind:checked={$userSettings.infiniteScroll}
|
||||
title={$t('settings.app.infiniteScroll.title')}
|
||||
description={$t('settings.app.infiniteScroll.description')}
|
||||
/>
|
||||
<ToggleSetting
|
||||
bind:checked={$userSettings.openLinksInNewTab}
|
||||
title={$t('settings.app.postsInNewTab.title')}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
export let title: string
|
||||
export let description: string | undefined = undefined
|
||||
export let checked: boolean = false
|
||||
export let beta = false
|
||||
|
||||
export let supportedPlatforms = {
|
||||
desktop: true,
|
||||
@@ -20,25 +21,30 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col w-full justify-between gap-2 max-w-full">
|
||||
{#if Object.values(supportedPlatforms).some((v) => v == false)}
|
||||
{#if Object.values(supportedPlatforms).some((v) => v == false) || beta}
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
{#if supportedPlatforms.desktop}
|
||||
<Badge>
|
||||
<Icon src={ComputerDesktop} micro size="14" slot="icon" />
|
||||
{$t('settings.desktop')}
|
||||
</Badge>
|
||||
{#if beta}
|
||||
<Badge>Beta</Badge>
|
||||
{/if}
|
||||
{#if supportedPlatforms.tablet}
|
||||
<Badge>
|
||||
<Icon src={DeviceTablet} micro size="14" slot="icon" />
|
||||
{$t('settings.tablet')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if supportedPlatforms.mobile}
|
||||
<Badge>
|
||||
<Icon src={DevicePhoneMobile} micro size="14" slot="icon" />
|
||||
{$t('settings.mobile')}
|
||||
</Badge>
|
||||
{#if Object.values(supportedPlatforms).some((v) => v == false)}
|
||||
{#if supportedPlatforms.desktop}
|
||||
<Badge>
|
||||
<Icon src={ComputerDesktop} micro size="14" slot="icon" />
|
||||
{$t('settings.desktop')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if supportedPlatforms.tablet}
|
||||
<Badge>
|
||||
<Icon src={DeviceTablet} micro size="14" slot="icon" />
|
||||
{$t('settings.tablet')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if supportedPlatforms.mobile}
|
||||
<Badge>
|
||||
<Icon src={DevicePhoneMobile} micro size="14" slot="icon" />
|
||||
{$t('settings.mobile')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in new issue
Block a user