misc: update cursor pagination
This commit is contained in:
1 parent
c3926efff0
commit
c843d8bb45
4 files changed
+28
-22
No files matched your search
@@ -10,9 +10,9 @@
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let page: number
|
||||
export let next_cursor: string | undefined = undefined
|
||||
export let cursor: { next?: string; back?: string } | undefined = undefined
|
||||
|
||||
const dispatcher = createEventDispatcher<{ change: number, cursor: string }>()
|
||||
const dispatcher = createEventDispatcher<{ change: number; cursor: string }>()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row w-full gap-4 items-center">
|
||||
@@ -22,25 +22,24 @@
|
||||
</span>
|
||||
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
||||
{/if}
|
||||
{#if !next_cursor}
|
||||
<Button
|
||||
on:click={() => {
|
||||
dispatcher('change', --page)
|
||||
}}
|
||||
disabled={page <= 1}
|
||||
class={$$slots.default ? '' : 'flex-1'}
|
||||
>
|
||||
<Icon src={ChevronLeft} size="18" mini slot="prefix" />
|
||||
Back
|
||||
</Button>
|
||||
{#if cursor?.back}
|
||||
<Button
|
||||
on:click={() => {
|
||||
if (cursor?.back) dispatcher('cursor', cursor.back)
|
||||
else dispatcher('change', --page)
|
||||
}}
|
||||
disabled={page <= 1}
|
||||
class={$$slots.default ? '' : 'flex-1'}
|
||||
>
|
||||
<Icon src={ChevronLeft} size="18" mini slot="prefix" />
|
||||
Back
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
<Button
|
||||
on:click={() => {
|
||||
if (next_cursor)
|
||||
dispatcher('cursor', next_cursor)
|
||||
else
|
||||
dispatcher('change', ++page)
|
||||
if (cursor?.next) dispatcher('cursor', cursor?.next)
|
||||
else dispatcher('change', ++page)
|
||||
}}
|
||||
class={$$slots.default ? '' : 'flex-1'}
|
||||
>
|
||||
|
||||
@@ -88,9 +88,11 @@
|
||||
<div class="mt-auto">
|
||||
<Pageination
|
||||
page={data.page}
|
||||
next_cursor={data.next_page}
|
||||
cursor={{ next: data.cursor.next, back: data.cursor.back }}
|
||||
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
||||
on:cursor={(c) => searchParam($page.url, 'cursor', c.detail)}
|
||||
on:cursor={(c) => {
|
||||
searchParam($page.url, 'cursor', c.detail)
|
||||
}}
|
||||
>
|
||||
<span class="max-sm:hidden">
|
||||
You've viewed <span
|
||||
|
||||
+7
-2
@@ -8,6 +8,7 @@ import { feature } from '$lib/version.js'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
const cursor = url.searchParams.get('cursor') as string | undefined
|
||||
const prevCursor = url.searchParams.get('prevCursor') as string | undefined
|
||||
const page = Number(url.searchParams.get('page')) || undefined
|
||||
|
||||
const sort: SortType =
|
||||
@@ -22,7 +23,7 @@ export async function load({ url, fetch }) {
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: listingType,
|
||||
page_cursor: cursor
|
||||
page_cursor: cursor,
|
||||
})
|
||||
|
||||
try {
|
||||
@@ -31,7 +32,11 @@ export async function load({ url, fetch }) {
|
||||
listingType: listingType,
|
||||
page: page || 1,
|
||||
posts: posts,
|
||||
next_page: posts.next_page
|
||||
cursor: {
|
||||
next: posts.next_page,
|
||||
back: prevCursor,
|
||||
current: cursor,
|
||||
},
|
||||
}
|
||||
} catch (err) {
|
||||
throw error(500, {
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
|
||||
<Pageination
|
||||
page={data.page}
|
||||
next_cursor={data.posts.next_page}
|
||||
cursor={{ next: data.posts.next_page }}
|
||||
on:cursor={(c) => searchParam($page.url, 'cursor', c.detail)}
|
||||
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user