Fix squirrely notification badges
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import RelayName from "@app/components/RelayName.svelte"
|
||||
import RelayDescription from "@app/components/RelayDescription.svelte"
|
||||
import {makeSpacePath} from "@app/routes"
|
||||
import {spacesNotifications} from "@app/notifications"
|
||||
import {inactiveSpacesNotifications} from "@app/notifications"
|
||||
|
||||
export let url
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<div slot="icon"><SpaceAvatar {url} /></div>
|
||||
<div slot="title" class="flex gap-1">
|
||||
<RelayName {url} />
|
||||
{#if $spacesNotifications.includes(url)}
|
||||
{#if $inactiveSpacesNotifications.includes(path)}
|
||||
<div class="relative top-1 h-2 w-2 rounded-full bg-primary" />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -3,18 +3,17 @@
|
||||
import PrimaryNavItem from "@lib/components/PrimaryNavItem.svelte"
|
||||
import SpaceAvatar from "@app/components/SpaceAvatar.svelte"
|
||||
import {makeSpacePath} from "@app/routes"
|
||||
import {deriveNotification, SPACE_FILTERS} from "@app/notifications"
|
||||
import {spacesNotifications} from "@app/notifications"
|
||||
|
||||
export let url
|
||||
|
||||
const path = makeSpacePath(url)
|
||||
const notification = deriveNotification(path, SPACE_FILTERS, url)
|
||||
</script>
|
||||
|
||||
<PrimaryNavItem
|
||||
title={displayRelayUrl(url)}
|
||||
href={path}
|
||||
class="tooltip-right"
|
||||
notification={$notification}>
|
||||
notification={$spacesNotifications.includes(path)}>
|
||||
<SpaceAvatar {url} />
|
||||
</PrimaryNavItem>
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
export let url
|
||||
export let pubkey
|
||||
export let events: TrustedEvent[] = []
|
||||
export let hideLoading = false
|
||||
|
||||
const ctrl = createFeedController({
|
||||
useWindowing: true,
|
||||
@@ -59,8 +60,10 @@
|
||||
<NoteItem {url} {event} />
|
||||
</div>
|
||||
{/each}
|
||||
<p class="center my-12 flex">
|
||||
<Spinner loading />
|
||||
</p>
|
||||
{#if !hideLoading}
|
||||
<p class="center my-12 flex">
|
||||
<Spinner loading />
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -17,7 +17,7 @@ checked.subscribe(v => console.log("====== checked", v))
|
||||
export const deriveChecked = (key: string) => derived(checked, prop(key))
|
||||
|
||||
export const setChecked = (key: string, ts = now()) =>
|
||||
Boolean(console.trace("====== setChecked", key))||
|
||||
Boolean(console.trace("====== setChecked", key)) ||
|
||||
checked.update(state => ({...state, [key]: ts}))
|
||||
|
||||
// Filters for various routes
|
||||
@@ -64,18 +64,20 @@ export const deriveNotification = (path: string, filters: Filter[], url?: string
|
||||
export const spacesNotifications = derived(
|
||||
[pubkey, checked, userMembership, deriveEvents(repository, {filters: SPACE_FILTERS})],
|
||||
([$pubkey, $checked, $userMembership, $events]) => {
|
||||
return getMembershipUrls($userMembership).filter(url => {
|
||||
const path = makeSpacePath(url)
|
||||
const lastChecked = max([$checked["*"], $checked[path]])
|
||||
const [latestEvent] = sortBy($e => -$e.created_at, $events)
|
||||
return getMembershipUrls($userMembership)
|
||||
.filter(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)
|
||||
})
|
||||
return latestEvent?.pubkey !== $pubkey && lt(lastChecked, latestEvent?.created_at)
|
||||
})
|
||||
.map(url => makeSpacePath(url))
|
||||
},
|
||||
)
|
||||
|
||||
export const inactiveSpacesNotifications = derived(
|
||||
[page, spacesNotifications],
|
||||
([$page, $spacesNotifications]) =>
|
||||
$spacesNotifications.filter(url => !$page.url.pathname.startsWith(makeSpacePath(url))),
|
||||
$spacesNotifications.filter(path => !$page.url.pathname.startsWith(path)),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user