flotilla/src/app/components/MenuSpaceButton.svelte

49 lines
1.7 KiB
Svelte
Raw Normal View History

2024-11-15 22:03:54 +00:00
<script lang="ts">
import {page} from "$app/stores"
import {derived} from "svelte/store"
import {max} from "@welshman/lib"
2024-12-10 21:07:17 +00:00
import {matchFilter, MESSAGE} from "@welshman/util"
2024-11-15 22:03:54 +00:00
import {pubkey} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import MenuSpace from "@app/components/MenuSpace.svelte"
import {checked, getNotification, deriveNotification, THREAD_FILTERS} from "@app/notifications"
2024-12-10 21:07:17 +00:00
import {userMembership, getMembershipRoomsByUrl, deriveEventsForUrl, GENERAL} from "@app/state"
2024-11-15 22:03:54 +00:00
import {makeRoomPath, makeSpacePath} from "@app/routes"
import {pushDrawer} from "@app/modal"
export let url
const openMenu = () => pushDrawer(MenuSpace, {url})
const events = deriveEventsForUrl(url, [{kinds: [MESSAGE]}])
const threadsPath = makeSpacePath(url, "threads")
const threadsNotification = deriveNotification(threadsPath, THREAD_FILTERS, url)
const notification = derived(
[page, events, checked, userMembership],
2024-11-15 23:16:06 +00:00
([$page, $events, $checked, $userMembership]) =>
getMembershipRoomsByUrl(url, $userMembership)
2024-11-15 22:03:54 +00:00
.concat(GENERAL)
.some(room => {
const path = makeRoomPath(url, room)
if ($page.url.pathname === path) return false
const lastChecked = max([$checked["*"], $checked[path]])
2024-12-05 21:37:15 +00:00
const roomEvents = $events.filter(e => matchFilter({"#h": [room]}, e))
2024-11-15 22:03:54 +00:00
return getNotification($pubkey, lastChecked, roomEvents)
2024-11-15 23:16:06 +00:00
}),
2024-11-15 22:03:54 +00:00
)
</script>
<Button on:click={openMenu} class="btn btn-neutral btn-sm relative md:hidden">
<Icon icon="menu-dots" />
{#if $threadsNotification || $notification}
<div class="absolute right-0 top-0 -mr-1 -mt-1 h-2 w-2 rounded-full bg-primary" />
{/if}
</Button>