feat: add feed filtering to inbox
This commit is contained in:
1 parent
9f3fef95be
commit
9711ffe4d9
3 files changed
+39
-12
No files matched your search
+24
-11
@@ -2,12 +2,15 @@ import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { getInboxItemPublished } from '$lib/lemmy/inbox.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||
|
||||
export async function load({ url }) {
|
||||
const auth = get(authData)
|
||||
if (!auth) return
|
||||
|
||||
const type: InboxFeedType =
|
||||
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
||||
const client = getClient()
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
|
||||
const params = {
|
||||
@@ -17,15 +20,25 @@ export async function load({ url }) {
|
||||
}
|
||||
|
||||
const [replies, mentions, privateMessages] = await Promise.all([
|
||||
client.getReplies({
|
||||
...params,
|
||||
sort: 'New',
|
||||
}),
|
||||
client.getPersonMentions({
|
||||
...params,
|
||||
sort: 'New',
|
||||
}),
|
||||
client.getPrivateMessages(params),
|
||||
type == 'all' || type == 'replies'
|
||||
? client.getReplies({
|
||||
...params,
|
||||
sort: 'New',
|
||||
})
|
||||
: { replies: [] },
|
||||
type == 'all' || type == 'mentions'
|
||||
? client.getPersonMentions({
|
||||
...params,
|
||||
sort: 'New',
|
||||
})
|
||||
: {
|
||||
mentions: [],
|
||||
},
|
||||
type == 'all' || type == 'messages'
|
||||
? client.getPrivateMessages({ ...params })
|
||||
: {
|
||||
private_messages: [],
|
||||
},
|
||||
])
|
||||
|
||||
const data = [
|
||||
@@ -38,5 +51,5 @@ export async function load({ url }) {
|
||||
Date.parse(getInboxItemPublished(a))
|
||||
)
|
||||
|
||||
return { page: page, data: data }
|
||||
return { type: type, page: page, data: data }
|
||||
}
|
||||
Reference in new issue
Block a user