Add mobile nav notification badges

This commit is contained in:
Jon Staab
2024-11-14 12:16:44 -08:00
parent 14ad4ec785
commit 2978d91977
11 changed files with 128 additions and 131 deletions
+22 -1
View File
@@ -4,7 +4,15 @@ import {repository, pubkey} from "@welshman/app"
import {prop, max, sortBy, assoc, lt, now} from "@welshman/lib"
import type {Filter} from "@welshman/util"
import {DIRECT_MESSAGE} from "@welshman/util"
import {MESSAGE, THREAD, COMMENT, deriveEventsForUrl} from "@app/state"
import {makeSpacePath} from "@app/routes"
import {
MESSAGE,
THREAD,
COMMENT,
deriveEventsForUrl,
getMembershipUrls,
userMembership,
} from "@app/state"
// Checked state
@@ -49,3 +57,16 @@ export const deriveNotification = (path: string, filters: Filter[], url?: string
},
)
}
export const spacesNotification = derived(
[pubkey, checked, userMembership, deriveEvents(repository, {filters: SPACE_FILTERS})],
([$pubkey, $checked, $userMembership, $events]) => {
return getMembershipUrls($userMembership).some(url => {
const path = makeSpacePath(url)
const lastChecked = max([$checked["*"], $checked[path]])
const [latestEvent] = sortBy($e => -$e.created_at, $events)
return latestEvent?.pubkey !== $pubkey && lt(lastChecked, latestEvent?.created_at)
})
},
)