misc: switch to pagination component

This commit is contained in:
Xyphyn committed 2023-07-27 11:57:56 -07:00
1 parent 8e75e05585
commit 378580dd9f
5 files changed
+28 -39

No files matched your search

+13 -20
View File
@@ -12,6 +12,7 @@
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons' import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
import Markdown from '$lib/components/markdown/Markdown.svelte' import Markdown from '$lib/components/markdown/Markdown.svelte'
import Pageination from '$lib/components/ui/Pageination.svelte'
export let data export let data
</script> </script>
@@ -32,13 +33,11 @@
<MultiSelect <MultiSelect
options={['Subscribed', 'Local', 'All']} options={['Subscribed', 'Local', 'All']}
disabled={[$authData?.token == undefined]} disabled={[$authData?.token == undefined]}
selected={$page.url.searchParams.get('type') ?? selected={data.listingType}
$userSettings.defaultSort.feed}
on:select={(e) => { on:select={(e) => {
const url = $page.url $page.url.searchParams.set('type', e.detail)
url.searchParams.set('type', e.detail) $page.url.searchParams.delete('page')
url.searchParams.delete('page') goto($page.url.toString(), {
goto(url, {
invalidateAll: true, invalidateAll: true,
}) })
}} }}
@@ -46,8 +45,7 @@
<MultiSelect <MultiSelect
options={['Active', 'Hot', 'TopAll', 'New']} options={['Active', 'Hot', 'TopAll', 'New']}
optionNames={['Active', 'Hot', 'Top', 'New']} optionNames={['Active', 'Hot', 'Top', 'New']}
selected={$page.url.searchParams.get('sort') ?? selected={data.sort}
$userSettings.defaultSort.sort}
on:select={(e) => { on:select={(e) => {
const url = $page.url const url = $page.url
url.searchParams.set('sort', e.detail) url.searchParams.set('sort', e.detail)
@@ -60,18 +58,18 @@
</div> </div>
<section class="flex flex-col gap-4"> <section class="flex flex-col gap-4">
{#if data.posts.posts.length == 0} {#if data.posts.posts.length == 0}
{#if data.listingType == 'Subscribed'}
<div <div
class="text-slate-600 dark:text-zinc-400 flex flex-col justify-center items-center" class="text-slate-600 dark:text-zinc-400 flex flex-col justify-center items-center"
> >
<Icon src={ArchiveBox} size="32" solid /> <Icon src={ArchiveBox} size="32" solid />
<h1 class="font-bold text-2xl">No posts</h1> <h1 class="font-bold text-2xl">No posts</h1>
{#if data.listingType == 'Subscribed'}
<Button href="/communities" class="mt-4"> <Button href="/communities" class="mt-4">
<Icon src={Plus} size="16" mini slot="icon" /> <Icon src={Plus} size="16" mini slot="icon" />
<span>Follow some communities</span> <span>Follow some communities</span>
</Button> </Button>
</div>
{/if} {/if}
</div>
{/if} {/if}
{#each data.posts.posts as post, index (post.post.id)} {#each data.posts.posts as post, index (post.post.id)}
<div in:fly={{ y: -8, opacity: 0, delay: index < 4 ? index * 100 : 0 }}> <div in:fly={{ y: -8, opacity: 0, delay: index < 4 ? index * 100 : 0 }}>
@@ -79,20 +77,15 @@
</div> </div>
{/each} {/each}
</section> </section>
<Button <Pageination
on:click={() => { page={data.page}
$page.url.searchParams.set( on:change={(p) => {
'page', $page.url.searchParams.set('page', p.detail.toString())
((Number($page.url.searchParams.get('page')) || 1) + 1).toString()
)
goto($page.url.toString(), { goto($page.url.toString(), {
invalidateAll: true, invalidateAll: true,
}) })
}} }}
> />
Next
</Button>
</div> </div>
<aside class="hidden md:block"> <aside class="hidden md:block">
{#await data.streamed.site} {#await data.streamed.site}
+1
View File
@@ -18,6 +18,7 @@ export async function load({ url }) {
return { return {
sort: sort, sort: sort,
listingType: listingType, listingType: listingType,
page: page,
posts: await getClient().getPosts({ posts: await getClient().getPosts({
limit: 20, limit: 20,
page: page, page: page,
+6 -10
View File
@@ -11,6 +11,7 @@
import { fly } from 'svelte/transition' import { fly } from 'svelte/transition'
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import Modal from '$lib/components/ui/modal/Modal.svelte' import Modal from '$lib/components/ui/modal/Modal.svelte'
import Pageination from '$lib/components/ui/Pageination.svelte'
export let data export let data
@@ -70,20 +71,15 @@
<Post {post} /> <Post {post} />
</div> </div>
{/each} {/each}
<Button <Pageination
on:click={() => { page={data.page}
$page.url.searchParams.set( on:change={(p) => {
'page', $page.url.searchParams.set('page', p.detail.toString())
((Number($page.url.searchParams.get('page')) || 1) + 1).toString()
)
goto($page.url.toString(), { goto($page.url.toString(), {
invalidateAll: true, invalidateAll: true,
}) })
}} }}
> />
Next
</Button>
</div> </div>
<div class="hidden md:block"> <div class="hidden md:block">
<CommunityCard community_view={data.community.community_view} /> <CommunityCard community_view={data.community.community_view} />
+2
View File
@@ -11,6 +11,8 @@ export async function load(req: any) {
get(userSettings).defaultSort.sort get(userSettings).defaultSort.sort
return { return {
sort: sort,
page: page,
posts: await getClient().getPosts({ posts: await getClient().getPosts({
limit: 40, limit: 40,
community_name: req.params.name, community_name: req.params.name,
+6 -9
View File
@@ -13,6 +13,7 @@
import TextInput from '$lib/components/input/TextInput.svelte' import TextInput from '$lib/components/input/TextInput.svelte'
import Subscribe from './Subscribe.svelte' import Subscribe from './Subscribe.svelte'
import Button from '$lib/components/input/Button.svelte' import Button from '$lib/components/input/Button.svelte'
import Pageination from '$lib/components/ui/Pageination.svelte'
export let data export let data
@@ -145,19 +146,15 @@
</ul> </ul>
{#if data.communities.length > 0} {#if data.communities.length > 0}
<div class="mt-2 w-full"> <div class="mt-2 w-full">
<Button <Pageination
on:click={() => { page={Number($page.url.searchParams.get('page')) || 1}
$page.url.searchParams.set( on:change={(p) => {
'page', $page.url.searchParams.set('page', p.detail.toString())
((Number($page.url.searchParams.get('page')) || 1) + 1).toString()
)
goto($page.url.toString(), { goto($page.url.toString(), {
invalidateAll: true, invalidateAll: true,
}) })
}} }}
> />
Next
</Button>
</div> </div>
{/if} {/if}