feat: add unread filters to inbox and reports

This commit is contained in:
Xyphyn committed 2023-07-29 13:09:40 -07:00
1 parent d65c62d2d9
commit 1c9661546c
4 files changed
+81 -20

No files matched your search

+36 -16
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import InboxItem from './InboxItem.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 { goto } from '$app/navigation'
import { page } from '$app/stores'
@@ -54,23 +54,43 @@
</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-row gap-4 flex-wrap">
<MultiSelect
selected={data.unreadOnly}
options={[false, true]}
optionNames={['All', 'Unread']}
on:select={(e) => {
$page.url.searchParams.delete('page')
$page.url.searchParams.set('unreadOnly', (e.detail ?? false).toString())
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">
{#if !data.data || (data.data?.length ?? 0) == 0}
<p class="text-center opacity-60 text-lg mx-4">
Wow, it's quite empty in here.
</p>
<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">Inbox empty</h1>
<p class="mt-2 text-center">You're all caught up!</p>
</div>
</div>
{:else}
{#each data.data as item}
<InboxItem {item} read={isRead(item)} />
+4 -1
View File
@@ -12,11 +12,14 @@ export async function load({ url }) {
(url.searchParams.get('type') as InboxFeedType) || 'all'
const client = getClient()
const page = Number(url.searchParams.get('page')) || 1
const unreadOnly: boolean =
(url.searchParams.get('unreadOnly') || 'true') == 'true'
const params = {
limit: 50,
page: page,
auth: auth.token,
unread_only: unreadOnly,
}
const [replies, mentions, privateMessages] = await Promise.all([
@@ -51,5 +54,5 @@ export async function load({ url }) {
Date.parse(getInboxItemPublished(a))
)
return { type: type, page: page, data: data }
return { unreadOnly: unreadOnly, type: type, page: page, data: data }
}
+30 -1
View File
@@ -3,11 +3,30 @@
import Card from '$lib/components/ui/Card.svelte'
import { fly } from 'svelte/transition'
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
</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">
{#each data.items as item}
<div in:fly={{ y: -6, opacity: 0, duration: 500 }}>
@@ -28,4 +47,14 @@
</div>
{/each}
</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}
+11 -2
View File
@@ -2,11 +2,19 @@ import { authData, getClient } from '$lib/lemmy.js'
import { getItemPublished } from '$lib/lemmy/item.js'
import { get } from 'svelte/store'
type ReportListType = 'unread' | 'all'
type ReportFilter = 'all' | 'posts' | 'comments' | 'messages'
export async function load({ url }) {
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
if (!jwt) return { page: page }
if (!jwt) return { type: type, page: page }
// can they like
// 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
// meaning I have to make a separate function to get dates
// for EACH FREAKING ITEM KAJSHDAWLD auwdi awiody
const client = getClient()
const params = {
auth: jwt,
limit: 20,
page: page,
unresolved_only: type == 'unread',
}
const [posts, comments, messages] = await Promise.all([
@@ -45,6 +53,7 @@ export async function load({ url }) {
)
return {
type: type,
page: page,
items: everything,
}