impr: isolate inbox handling code into separate service class

This commit is contained in:
Xylight authored and xylight committed 2025-11-04 17:56:37 -08:00
1 parent 72bb10b924
commit b8f69dda95
12 files changed
+201 -170

No files matched your search

+1 -6
View File
@@ -23,17 +23,12 @@
none: '',
}
const alignments = {
default: '',
center: '',
}
interface Props {
class?: ClassValue
size?: keyof typeof sizes
color?: keyof typeof colors
margin?: keyof typeof margins
alignment?: keyof typeof alignments
alignment?: 'default' | 'center'
border?: boolean
children?: import('svelte').Snippet
action?: import('svelte').Snippet
+2 -2
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import { site } from '$lib/api/client.svelte'
import { notifications, profile } from '$lib/app/auth.svelte'
import { profile } from '$lib/app/auth.svelte'
import { t } from '$lib/app/i18n'
import { LINKED_INSTANCE_URL } from '$lib/app/instance.svelte'
import { Menu, Spinner } from 'mono-svelte'
@@ -140,7 +140,7 @@
<Icon src={Bars3} micro size="18" />
</div>
{/if}
{#if Math.max(...Object.values($notifications)) > 0}
{#if Math.max(...Object.values(profile.inbox.notifications)) > 0}
<div
class="w-2 h-2 absolute top-0.5 right-0.5 bg-red-500 rounded-full"
></div>
+6 -5
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import { env } from '$env/dynamic/public'
import { site } from '$lib/api/client.svelte'
import { notifications, profile } from '$lib/app/auth.svelte'
import { profile } from '$lib/app/auth.svelte'
import { t } from '$lib/app/i18n'
import { settings } from '$lib/app/settings.svelte'
import { theme } from '$lib/app/theme/theme.svelte'
@@ -61,11 +61,12 @@
{/snippet}
{#if profile.current?.jwt}
{@const notifications = profile.inbox.notifications}
<MenuButton href="/inbox" icon={Inbox}>
{$t('profile.inbox')}
{#if $notifications.inbox > 0}
{#if notifications.inbox > 0}
<Badge color="red-subtle" class="text-xs ml-auto font-bold py-0.5!">
{$notifications.inbox > 99 ? '∞' : $notifications.inbox}
{notifications.inbox > 99 ? '∞' : notifications.inbox}
</Badge>
{/if}
</MenuButton>
@@ -73,7 +74,7 @@
<MenuButton href="/moderation" icon={ShieldCheck}>
{$t('routes.moderation.feed')}
{#snippet suffix()}
{@render notifBadge($notifications.reports)}
{@render notifBadge(notifications.reports)}
{/snippet}
</MenuButton>
{/if}
@@ -81,7 +82,7 @@
<MenuButton href="/admin/applications" icon={ServerStack}>
{$t('routes.admin.applications.title')}
{#snippet suffix()}
{@render notifBadge($notifications.applications)}
{@render notifBadge(notifications.applications)}
{/snippet}
</MenuButton>
{/if}
+4 -3
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import { env } from '$env/dynamic/public'
import { notifications, profile } from '$lib/app/auth.svelte'
import { profile } from '$lib/app/auth.svelte'
import { t } from '$lib/app/i18n'
import { LINKED_INSTANCE_URL } from '$lib/app/instance.svelte'
import { settings } from '$lib/app/settings.svelte'
@@ -52,18 +52,19 @@
/>
<EndPlaceholder margin="sm" size="xs">{$t('profile.profile')}</EndPlaceholder>
{#if profile.current?.jwt}
{@const notifications = profile.inbox.notifications}
<SidebarButton
icon={UserCircle}
href="/profile"
label={$t('profile.profile')}
/>
<SidebarButton icon={Inbox} href="/inbox" label={$t('profile.inbox')}>
{#if $notifications.inbox}
{#if notifications.inbox}
<Badge
class="min-w-5 h-5 p-0! px-0.5 grid place-items-center ml-auto"
color="red-subtle"
>
{$notifications.inbox > 99 ? '∞' : $notifications.inbox}
{notifications.inbox > 99 ? '∞' : notifications.inbox}
</Badge>
{/if}
</SidebarButton>