impr: isolate inbox handling code into separate service class
This commit is contained in:
1 parent
72bb10b924
commit
b8f69dda95
12 files changed
+201
-170
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { notifications } from '$lib/app/auth.svelte'
|
||||
import { profile } from '$lib/app/auth.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Tabs } from '$lib/ui/layout'
|
||||
import { Badge } from 'mono-svelte'
|
||||
@@ -7,13 +7,16 @@
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
{#if $notifications.applications > 0}
|
||||
<span class="flex flex-row text-red-500 gap-2">
|
||||
<Badge color="red-subtle" class="w-max">
|
||||
{$notifications.applications > 99 ? '∞' : $notifications.applications}
|
||||
</Badge> unread applications
|
||||
</span>
|
||||
{/if}
|
||||
<svelte:boundary>
|
||||
{@const notifications = profile.inbox.notifications}
|
||||
{#if notifications.applications > 0}
|
||||
<span class="flex flex-row text-red-500 gap-2">
|
||||
<Badge color="red-subtle" class="w-max">
|
||||
{notifications.applications > 99 ? '∞' : notifications.applications}
|
||||
</Badge> unread applications
|
||||
</span>
|
||||
{/if}
|
||||
</svelte:boundary>
|
||||
|
||||
<Tabs
|
||||
routes={[
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
ApproveRegistrationApplication,
|
||||
RegistrationApplicationView,
|
||||
} from '$lib/api/types'
|
||||
import { notifications, profile } from '$lib/app/auth.svelte'
|
||||
import { profile } from '$lib/app/auth.svelte'
|
||||
import { errorMessage } from '$lib/app/error'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import ApplicationDenyModal from '$lib/feature/moderation/ApplicationDenyModal.svelte'
|
||||
@@ -69,7 +69,7 @@
|
||||
application.admin = profile.current.user!.local_user_view.person
|
||||
application.registration_application.deny_reason = denyReason
|
||||
|
||||
$notifications.applications -= 1
|
||||
profile.inbox.notifications.applications -= 1
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: errorMessage(err as string),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { getClient } 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 { searchParam } from '$lib/app/util.svelte'
|
||||
import Fixate from '$lib/ui/generic/Fixate.svelte'
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
const response = await getClient().markAllAsRead()
|
||||
|
||||
$notifications.inbox = 0
|
||||
profile.inbox.notifications.inbox = 0
|
||||
|
||||
goto(page.url, {
|
||||
invalidateAll: true,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getClient } from '$lib/api/client.svelte'
|
||||
import { notifications, profile } from '$lib/app/auth.svelte'
|
||||
import { profile } from '$lib/app/auth.svelte'
|
||||
import { ReactiveState } from '$lib/app/util.svelte'
|
||||
import {
|
||||
generalizeCommentReply,
|
||||
@@ -64,11 +64,7 @@ export async function load({ url, fetch }) {
|
||||
? data.filter((i) => i.type != 'private_message' && !i.read).length
|
||||
: 0
|
||||
|
||||
notifications.update((i) => ({
|
||||
applications: i.applications,
|
||||
reports: i.reports,
|
||||
inbox: totalNotifs,
|
||||
}))
|
||||
profile.inbox.notifications.inbox = totalNotifs
|
||||
|
||||
return {
|
||||
unreadOnly: new ReactiveState(unreadOnly),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { getClient } 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 Markdown from '$lib/app/markdown/Markdown.svelte'
|
||||
import { escapeHtml } from '$lib/app/util.svelte'
|
||||
@@ -50,7 +50,8 @@
|
||||
}
|
||||
|
||||
item.read = isRead
|
||||
if (profile.current.user) $notifications.inbox += isRead ? -1 : 1
|
||||
if (profile.current.user)
|
||||
profile.inbox.notifications.inbox += isRead ? -1 : 1
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { getClient } from '$lib/api/client.svelte'
|
||||
import { notifications, profile } from '$lib/app/auth.svelte'
|
||||
import { profile } from '$lib/app/auth.svelte'
|
||||
import { errorMessage } from '$lib/app/error'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import CommentItem from '$lib/feature/comment/CommentItem.svelte'
|
||||
@@ -39,7 +39,7 @@
|
||||
.then((res) => {
|
||||
i.resolved = res.comment_report_view.comment_report.resolved
|
||||
i.resolver = res.comment_report_view.resolver
|
||||
$notifications.reports += i.resolved ? -1 : 1
|
||||
profile.inbox.notifications.reports += i.resolved ? -1 : 1
|
||||
}),
|
||||
),
|
||||
)
|
||||
@@ -59,7 +59,7 @@
|
||||
|
||||
i.resolver = res.post_report_view.resolver
|
||||
|
||||
$notifications.reports += i.resolved ? -1 : 1
|
||||
profile.inbox.notifications.reports += i.resolved ? -1 : 1
|
||||
}),
|
||||
),
|
||||
)
|
||||
@@ -80,7 +80,7 @@
|
||||
|
||||
i.resolver = res.private_message_report_view.resolver
|
||||
|
||||
$notifications.reports += i.resolved ? -1 : 1
|
||||
profile.inbox.notifications.reports += i.resolved ? -1 : 1
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user