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
@@ -7,6 +7,7 @@
|
||||
import { page } from '$app/stores'
|
||||
import { isRead } from '$lib/lemmy/inbox.js'
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -52,6 +53,19 @@
|
||||
Mark all as read
|
||||
</Button>
|
||||
</div>
|
||||
<div class="mt-4" />
|
||||
<MultiSelect
|
||||
selected={data.type}
|
||||
options={['all', 'mentions', 'replies', 'messages']}
|
||||
optionNames={['All', 'Mentions', 'Replies', 'Messages']}
|
||||
on:select={(e) => {
|
||||
$page.url.searchParams.delete('page')
|
||||
$page.url.searchParams.set('type', e.detail ?? 'all')
|
||||
goto($page.url.toString(), {
|
||||
invalidateAll: true,
|
||||
})
|
||||
}}
|
||||
/>
|
||||
<div class="flex flex-col gap-4 list-none my-4">
|
||||
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||
<p class="text-center opacity-60 text-lg mx-4">
|
||||
|
||||
+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 }
|
||||
}
|
||||
@@ -70,7 +70,7 @@
|
||||
<div class="flex flex-row items-center justify-between">
|
||||
<div
|
||||
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
|
||||
overflow-hidden {read ? 'opacity-50' : ''}"
|
||||
overflow-hidden {read ? 'text-slate-600 dark:text-zinc-400' : ''}"
|
||||
>
|
||||
<span class="font-bold">
|
||||
{item.creator.display_name ?? item.creator.name}
|
||||
|
||||
Reference in new issue
Block a user