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
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user