feat: add setting for infinite scroll
This commit is contained in:
1 parent
82e3c8efd6
commit
ef74a4e6d2
5 files changed
+34
-16
No files matched your search
@@ -594,6 +594,10 @@
|
|||||||
"title": "Default sort",
|
"title": "Default sort",
|
||||||
"description": "The default sorting to use in feeds."
|
"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": {
|
"postsInNewTab": {
|
||||||
"title": "Open posts in new tab",
|
"title": "Open posts in new tab",
|
||||||
"description": "Open posts in a separate tab instead of the current."
|
"description": "Open posts in a separate tab instead of the current."
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ interface Settings {
|
|||||||
compactFeatured: boolean
|
compactFeatured: boolean
|
||||||
showHidden: boolean
|
showHidden: boolean
|
||||||
}
|
}
|
||||||
|
infiniteScroll: boolean
|
||||||
language: string | null
|
language: string | null
|
||||||
translator: string | undefined
|
translator: string | undefined
|
||||||
}
|
}
|
||||||
@@ -155,6 +156,7 @@ export const defaultSettings: Settings = {
|
|||||||
compactFeatured: toBool(env.PUBLIC_COMPACT_FEATURED) ?? true,
|
compactFeatured: toBool(env.PUBLIC_COMPACT_FEATURED) ?? true,
|
||||||
showHidden: false,
|
showHidden: false,
|
||||||
},
|
},
|
||||||
|
infiniteScroll: true,
|
||||||
language: env.PUBLIC_LANGUAGE ?? null,
|
language: env.PUBLIC_LANGUAGE ?? null,
|
||||||
translator: env.PUBLIC_TRANSLATOR ?? undefined,
|
translator: env.PUBLIC_TRANSLATOR ?? undefined,
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-16
@@ -21,11 +21,12 @@
|
|||||||
import { Spinner } from 'mono-svelte'
|
import { Spinner } from 'mono-svelte'
|
||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
import type { GetPostsResponse } from 'lemmy-js-client'
|
import type { GetPostsResponse } from 'lemmy-js-client'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
const limit = 20
|
const limit = 20
|
||||||
let hasMore = data.posts.posts.length == limit
|
let hasMore = data.posts.posts.length != 0
|
||||||
|
|
||||||
async function loadMore() {
|
async function loadMore() {
|
||||||
if (!hasMore) return
|
if (!hasMore) return
|
||||||
@@ -38,14 +39,12 @@
|
|||||||
page_cursor: data.cursor.next,
|
page_cursor: data.cursor.next,
|
||||||
})
|
})
|
||||||
|
|
||||||
hasMore = newPosts.posts.length == limit
|
hasMore = newPosts.posts.length != 0
|
||||||
|
|
||||||
console.log(hasMore)
|
|
||||||
|
|
||||||
data.cursor.next = newPosts.next_page
|
data.cursor.next = newPosts.next_page
|
||||||
data.posts.posts = [...data.posts.posts, ...newPosts.posts]
|
data.posts.posts = [...data.posts.posts, ...newPosts.posts]
|
||||||
|
|
||||||
_posts.set({ data: data.posts, params: $page.url.searchParams })
|
_posts.update((ps) => ({ data: data.posts, params: ps.params }))
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -62,19 +61,24 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<PostFeed posts={data.posts.posts}>
|
<PostFeed posts={data.posts.posts}>
|
||||||
{#if hasMore}
|
{#if $userSettings.infiniteScroll}
|
||||||
<div class="w-full flex flex-col skeleton gap-2 animate-pulse pt-6">
|
{#if hasMore}
|
||||||
<div class="w-96 h-8"></div>
|
<div class="w-full flex flex-col skeleton gap-2 animate-pulse pt-6">
|
||||||
<div class="w-full h-48"></div>
|
<div class="w-96 h-8"></div>
|
||||||
<div class="!bg-transparent h-8 flex justify-between">
|
<div class="w-full h-48"></div>
|
||||||
<div class="w-48 h-8"></div>
|
<div class="!bg-transparent h-8 flex justify-between">
|
||||||
<div class="w-24 h-8"></div>
|
<div class="w-48 h-8"></div>
|
||||||
|
<div class="w-24 h-8"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
|
<InfiniteScroll window threshold={1000} on:loadMore={loadMore} />
|
||||||
{/if}
|
{/if}
|
||||||
<InfiniteScroll window threshold={750} on:loadMore={loadMore} />
|
|
||||||
</PostFeed>
|
</PostFeed>
|
||||||
<div class="mt-auto">
|
<svelte:element
|
||||||
|
this={$userSettings.infiniteScroll ? 'noscript' : 'div'}
|
||||||
|
class="mt-auto"
|
||||||
|
>
|
||||||
<Pageination
|
<Pageination
|
||||||
page={data.page}
|
page={data.page}
|
||||||
cursor={{ next: data.cursor.next, back: data.cursor.back }}
|
cursor={{ next: data.cursor.next, back: data.cursor.back }}
|
||||||
@@ -91,7 +95,7 @@
|
|||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
</Pageination>
|
</Pageination>
|
||||||
</div>
|
</svelte:element>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ export async function load({ url, fetch }) {
|
|||||||
|
|
||||||
const cached = get(_posts)
|
const cached = get(_posts)
|
||||||
|
|
||||||
|
console.log(url.searchParams.toString())
|
||||||
|
console.log(cached?.params?.toString())
|
||||||
|
|
||||||
const posts =
|
const posts =
|
||||||
cached && url.searchParams.toString() == cached.params.toString()
|
cached && url.searchParams.toString() == cached.params.toString()
|
||||||
? cached.data
|
? cached.data
|
||||||
|
|||||||
@@ -214,6 +214,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<ToggleSetting
|
||||||
|
bind:checked={$userSettings.infiniteScroll}
|
||||||
|
title={$t('settings.app.infiniteScroll.title')}
|
||||||
|
description={$t('settings.app.infiniteScroll.description')}
|
||||||
|
/>
|
||||||
<ToggleSetting
|
<ToggleSetting
|
||||||
bind:checked={$userSettings.openLinksInNewTab}
|
bind:checked={$userSettings.openLinksInNewTab}
|
||||||
title={$t('settings.app.postsInNewTab.title')}
|
title={$t('settings.app.postsInNewTab.title')}
|
||||||
|
|||||||
Reference in new issue
Block a user