feat: Add pagination to inbox page

This commit is contained in:
Xyphyn committed 2023-07-27 12:30:09 -07:00
1 parent c0aaf08a9f
commit 81270b72d3
4 files changed
+31 -24

No files matched your search

+14 -3
View File
@@ -5,9 +5,9 @@ import type {
PostView, PostView,
} from 'lemmy-js-client' } from 'lemmy-js-client'
export function getItemPublished( type Result = PostView | CommentView | PersonView | CommunityView
item: PostView | CommentView | PersonView | CommunityView
) { export function getItemPublished(item: Result) {
if ('comment' in item) { if ('comment' in item) {
return item.comment.published return item.comment.published
} else if ('post' in item) { } else if ('post' in item) {
@@ -24,3 +24,14 @@ export function getItemPublished(
return '' return ''
} }
export const isPost = (item: Result): item is PostView =>
'post' in item && !('comment' in item)
export const isComment = (item: Result): item is CommentView =>
'comment' in item
export const isCommunity = (item: Result): item is CommunityView =>
'community' in item
export const isUser = (item: Result): item is PersonView => 'person' in item
+11 -8
View File
@@ -1,9 +1,4 @@
<script lang="ts"> <script lang="ts">
import type {
CommentReplyView,
PersonMentionView,
PrivateMessageView,
} from 'lemmy-js-client'
import InboxItem from './InboxItem.svelte' import InboxItem from './InboxItem.svelte'
import Button from '$lib/components/input/Button.svelte' import Button from '$lib/components/input/Button.svelte'
import { Check, Icon } from 'svelte-hero-icons' import { Check, Icon } from 'svelte-hero-icons'
@@ -11,10 +6,9 @@
import { goto } from '$app/navigation' import { goto } from '$app/navigation'
import { page } from '$app/stores' import { page } from '$app/stores'
import { isRead } from '$lib/lemmy/inbox.js' import { isRead } from '$lib/lemmy/inbox.js'
import Pageination from '$lib/components/ui/Pageination.svelte'
export let data: { export let data
data: PersonMentionView[] | CommentReplyView[] | PrivateMessageView[]
}
let markingAsRead = false let markingAsRead = false
@@ -67,5 +61,14 @@
{#each data.data as item} {#each data.data as item}
<InboxItem {item} read={isRead(item)} /> <InboxItem {item} read={isRead(item)} />
{/each} {/each}
<Pageination
page={data.page}
on:change={(p) => {
$page.url.searchParams.set('page', p.detail.toString())
goto($page.url.toString(), {
invalidateAll: true,
})
}}
/>
{/if} {/if}
</div> </div>
+5 -3
View File
@@ -2,15 +2,17 @@ import { authData, getClient } from '$lib/lemmy.js'
import { getInboxItemPublished } from '$lib/lemmy/inbox.js' import { getInboxItemPublished } from '$lib/lemmy/inbox.js'
import { get } from 'svelte/store' import { get } from 'svelte/store'
export async function load() { export async function load({ url }) {
const auth = get(authData) const auth = get(authData)
if (!auth) return if (!auth) return
const client = getClient() const client = getClient()
const page = Number(url.searchParams.get('page')) || 1
const params = { const params = {
limit: 50, limit: 50,
page: 1, page: page,
auth: auth.token, auth: auth.token,
} }
@@ -36,5 +38,5 @@ export async function load() {
Date.parse(getInboxItemPublished(a)) Date.parse(getInboxItemPublished(a))
) )
return { data: data } return { page: page, data: data }
} }
+1 -10
View File
@@ -10,6 +10,7 @@
import Post from '$lib/components/lemmy/post/Post.svelte' import Post from '$lib/components/lemmy/post/Post.svelte'
import UserItem from '$lib/components/lemmy/user/UserItem.svelte' import UserItem from '$lib/components/lemmy/user/UserItem.svelte'
import Pageination from '$lib/components/ui/Pageination.svelte' import Pageination from '$lib/components/ui/Pageination.svelte'
import { isComment, isCommunity, isPost, isUser } from '$lib/lemmy/item.js'
import type { import type {
CommentView, CommentView,
CommunityView, CommunityView,
@@ -24,16 +25,6 @@
let query = '' let query = ''
const isPost = (item: Result): item is PostView =>
'post' in item && !('comment' in item)
const isComment = (item: Result): item is CommentView => 'comment' in item
const isCommunity = (item: Result): item is CommunityView =>
'community' in item
const isUser = (item: Result): item is PersonView => 'person' in item
let pageNum = data.page let pageNum = data.page
</script> </script>