Files
photon-tbw/src/routes/inbox/+page.svelte
T
2025-08-20 21:16:32 -07:00

132 lines
3.5 KiB
Svelte

<script lang="ts">
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { notifications, profile } from '$lib/auth.svelte.js'
import CommonList from '$lib/components/ui/layout/CommonList.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
import Pageination from '$lib/components/ui/Pageination.svelte'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import { Button, Option, Select } from 'mono-svelte'
import { ArrowPath, Check, Funnel, Icon, Inbox } from 'svelte-hero-icons'
import InboxItem from './InboxItem.svelte'
import { searchParam } from '$lib/util.svelte'
let { data } = $props()
let markingAsRead = $state(false)
async function markAllAsRead() {
if (!profile.current?.user) {
goto('/login')
return
}
markingAsRead = true
const response = await getClient().markAllAsRead()
$notifications.inbox = 0
goto(page.url, {
invalidateAll: true,
}).then(() => {
markingAsRead = false
})
return response.replies
}
</script>
<svelte:head>
<title>{$t('routes.inbox.title')}</title>
</svelte:head>
<Header pageHeader class="lg:flex-row justify-between flex-col">
{$t('routes.inbox.title')}
<div class="flex items-center gap-2 tracking-normal">
<Button
onclick={() => goto(page.url, { invalidateAll: true })}
size="custom"
class="rounded-2xl h-9 aspect-square"
rounding="none"
aria-label={$t('common.refresh')}
>
{#snippet prefix()}
<Icon src={ArrowPath} size="16" mini />
{/snippet}
</Button>
<Button
onclick={markAllAsRead}
loading={markingAsRead}
disabled={markingAsRead || data.inbox.value.length == 0}
rounding="pill"
color="primary"
>
{#snippet prefix()}
<Icon src={Check} size="16" mini />
{/snippet}
{$t('routes.inbox.markAsRead')}
</Button>
</div>
</Header>
<div class="h-3 sm:h-6"></div>
<div class="mb-3 sm:mb-6">
<Select
class=" w-max items-center"
bind:value={
() => data.unreadOnly.value.toString(),
v => (data.unreadOnly.value = v == 'true')
}
onchange={() =>
searchParam(
page.url,
'unreadOnly',
data.unreadOnly.value ? 'true' : 'false',
'page',
)}
>
{#snippet customLabel()}
<span class="flex items-center gap-1">
<Icon src={Funnel} size="15" mini />
{$t('filter.filter')}
</span>
{/snippet}
<Option value="false">{$t('filter.location.all')}</Option>
<Option value="true">{$t('filter.unread')}</Option>
</Select>
</div>
{#if !data.inbox?.value || (data.inbox.value?.length ?? 0) == 0}
<Placeholder
icon={Inbox}
title={$t('routes.inbox.empty.title')}
description={$t('routes.inbox.empty.description')}
class="self-center justify-self-center my-auto"
/>
{:else}
<CommonList items={data.inbox.value} size="md">
{#snippet item(item)}
<InboxItem {item} />
{/snippet}
</CommonList>
{/if}
{#if !(data.page == 1 && (data?.inbox?.value.length ?? 0) == 0)}
<div
class="sticky z-30 mx-auto max-w-full self-end mt-auto bottom-22 lg:bottom-6"
>
<Pageination
hasMore={!(
!data.inbox || (data.inbox.value?.length ?? 0) < (data?.limit ?? 0)
)}
page={data.page}
href={page => `?page=${page}`}
/>
</div>
{/if}