feat: add unread filters to inbox and reports
This commit is contained in:
1 parent
d65c62d2d9
commit
1c9661546c
4 files changed
+81
-20
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
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, EnvelopeOpen, Icon } from 'svelte-hero-icons'
|
||||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
@@ -54,23 +54,43 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4" />
|
<div class="mt-4" />
|
||||||
<MultiSelect
|
<div class="flex flex-row gap-4 flex-wrap">
|
||||||
selected={data.type}
|
<MultiSelect
|
||||||
options={['all', 'mentions', 'replies', 'messages']}
|
selected={data.unreadOnly}
|
||||||
optionNames={['All', 'Mentions', 'Replies', 'Messages']}
|
options={[false, true]}
|
||||||
on:select={(e) => {
|
optionNames={['All', 'Unread']}
|
||||||
$page.url.searchParams.delete('page')
|
on:select={(e) => {
|
||||||
$page.url.searchParams.set('type', e.detail ?? 'all')
|
$page.url.searchParams.delete('page')
|
||||||
goto($page.url.toString(), {
|
$page.url.searchParams.set('unreadOnly', (e.detail ?? false).toString())
|
||||||
invalidateAll: true,
|
goto($page.url.toString(), {
|
||||||
})
|
invalidateAll: true,
|
||||||
}}
|
})
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
<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>
|
||||||
<div class="flex flex-col gap-4 list-none my-4">
|
<div class="flex flex-col gap-4 list-none my-4">
|
||||||
{#if !data.data || (data.data?.length ?? 0) == 0}
|
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||||
<p class="text-center opacity-60 text-lg mx-4">
|
<div
|
||||||
Wow, it's quite empty in here.
|
class="text-slate-600 dark:text-zinc-400 flex flex-col justify-center items-center py-8 gap-2"
|
||||||
</p>
|
>
|
||||||
|
<Icon src={EnvelopeOpen} size="48" />
|
||||||
|
<div>
|
||||||
|
<h1 class="font-bold text-3xl">Inbox empty</h1>
|
||||||
|
<p class="mt-2 text-center">You're all caught up!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
{#each data.data as item}
|
{#each data.data as item}
|
||||||
<InboxItem {item} read={isRead(item)} />
|
<InboxItem {item} read={isRead(item)} />
|
||||||
|
|||||||
@@ -12,11 +12,14 @@ export async function load({ url }) {
|
|||||||
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
const page = Number(url.searchParams.get('page')) || 1
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
|
const unreadOnly: boolean =
|
||||||
|
(url.searchParams.get('unreadOnly') || 'true') == 'true'
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
limit: 50,
|
limit: 50,
|
||||||
page: page,
|
page: page,
|
||||||
auth: auth.token,
|
auth: auth.token,
|
||||||
|
unread_only: unreadOnly,
|
||||||
}
|
}
|
||||||
|
|
||||||
const [replies, mentions, privateMessages] = await Promise.all([
|
const [replies, mentions, privateMessages] = await Promise.all([
|
||||||
@@ -51,5 +54,5 @@ export async function load({ url }) {
|
|||||||
Date.parse(getInboxItemPublished(a))
|
Date.parse(getInboxItemPublished(a))
|
||||||
)
|
)
|
||||||
|
|
||||||
return { type: type, page: page, data: data }
|
return { unreadOnly: unreadOnly, type: type, page: page, data: data }
|
||||||
}
|
}
|
||||||
@@ -3,11 +3,30 @@
|
|||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import Report from './Report.svelte'
|
import Report from './Report.svelte'
|
||||||
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import { EnvelopeOpen, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if data.items}
|
<div class="mb-4 flex flex-col gap-4">
|
||||||
|
<h1 class="font-black text-3xl">Reports</h1>
|
||||||
|
<MultiSelect
|
||||||
|
selected={data.type}
|
||||||
|
options={['all', 'unread']}
|
||||||
|
optionNames={['All', 'Unread']}
|
||||||
|
on:select={(e) => {
|
||||||
|
$page.url.searchParams.delete('page')
|
||||||
|
$page.url.searchParams.set('type', e.detail)
|
||||||
|
goto($page.url.toString(), {
|
||||||
|
invalidateAll: true,
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{#if data.items && data.items.length > 0}
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
{#each data.items as item}
|
{#each data.items as item}
|
||||||
<div in:fly={{ y: -6, opacity: 0, duration: 500 }}>
|
<div in:fly={{ y: -6, opacity: 0, duration: 500 }}>
|
||||||
@@ -28,4 +47,14 @@
|
|||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div
|
||||||
|
class="text-slate-600 dark:text-zinc-400 flex flex-col justify-center items-center py-8 gap-2"
|
||||||
|
>
|
||||||
|
<Icon src={EnvelopeOpen} size="48" />
|
||||||
|
<div>
|
||||||
|
<h1 class="font-bold text-3xl">No reports</h1>
|
||||||
|
<p class="mt-2 text-center">You're all caught up!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -2,11 +2,19 @@ import { authData, getClient } from '$lib/lemmy.js'
|
|||||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
|
type ReportListType = 'unread' | 'all'
|
||||||
|
type ReportFilter = 'all' | 'posts' | 'comments' | 'messages'
|
||||||
|
|
||||||
export async function load({ url }) {
|
export async function load({ url }) {
|
||||||
const page = Number(url.searchParams.get('page')) || 1
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
|
const type: ReportListType =
|
||||||
|
(url.searchParams.get('type') as ReportListType) || 'unread'
|
||||||
|
const filter: ReportFilter =
|
||||||
|
(url.searchParams.get('filter') as ReportFilter) || 'all'
|
||||||
|
|
||||||
const jwt = get(authData)?.token
|
const jwt = get(authData)?.token
|
||||||
|
|
||||||
if (!jwt) return { page: page }
|
if (!jwt) return { type: type, page: page }
|
||||||
|
|
||||||
// can they like
|
// can they like
|
||||||
// make a sane, consistent, and simple API for once
|
// make a sane, consistent, and simple API for once
|
||||||
@@ -15,13 +23,13 @@ export async function load({ url }) {
|
|||||||
// the interfaces don't even extend each other
|
// the interfaces don't even extend each other
|
||||||
// meaning I have to make a separate function to get dates
|
// meaning I have to make a separate function to get dates
|
||||||
// for EACH FREAKING ITEM KAJSHDAWLD auwdi awiody
|
// for EACH FREAKING ITEM KAJSHDAWLD auwdi awiody
|
||||||
|
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
auth: jwt,
|
auth: jwt,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
|
unresolved_only: type == 'unread',
|
||||||
}
|
}
|
||||||
|
|
||||||
const [posts, comments, messages] = await Promise.all([
|
const [posts, comments, messages] = await Promise.all([
|
||||||
@@ -45,6 +53,7 @@ export async function load({ url }) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
type: type,
|
||||||
page: page,
|
page: page,
|
||||||
items: everything,
|
items: everything,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user