flotilla/src/app/components/PrimaryNav.svelte

97 lines
3.7 KiB
Svelte
Raw Normal View History

2024-08-05 21:45:16 +00:00
<script lang="ts">
2024-12-16 19:49:57 +00:00
import {page} from "$app/stores"
import {goto} from "$app/navigation"
2024-10-01 23:27:25 +00:00
import {userProfile} from "@welshman/app"
2024-08-15 21:30:55 +00:00
import Avatar from "@lib/components/Avatar.svelte"
2024-10-21 22:19:55 +00:00
import Divider from "@lib/components/Divider.svelte"
2024-08-06 20:10:10 +00:00
import PrimaryNavItem from "@lib/components/PrimaryNavItem.svelte"
2024-08-16 17:50:38 +00:00
import SpaceAdd from "@app/components/SpaceAdd.svelte"
import ChatEnable from "@app/components/ChatEnable.svelte"
2024-10-09 23:11:23 +00:00
import MenuSpaces from "@app/components/MenuSpaces.svelte"
import MenuSettings from "@app/components/MenuSettings.svelte"
2024-11-14 18:53:13 +00:00
import PrimaryNavItemSpace from "@app/components/PrimaryNavItemSpace.svelte"
2024-12-17 01:07:52 +00:00
import {userRoomsByUrl, canDecrypt, PLATFORM_RELAY, PLATFORM_LOGO} from "@app/state"
2024-08-08 21:02:46 +00:00
import {pushModal} from "@app/modal"
2024-12-16 19:24:10 +00:00
import {makeSpacePath} from "@app/routes"
2024-12-16 19:49:57 +00:00
import {notifications} from "@app/notifications"
2024-08-14 00:58:26 +00:00
const addSpace = () => pushModal(SpaceAdd)
2024-10-09 23:11:23 +00:00
2024-12-16 19:24:10 +00:00
const showSpacesMenu = () => (spacePaths.length > 0 ? pushModal(MenuSpaces) : pushModal(SpaceAdd))
2024-10-09 23:11:23 +00:00
const showSettingsMenu = () => pushModal(MenuSettings)
2024-12-05 23:32:27 +00:00
const openChat = () => ($canDecrypt ? goto("/chat") : pushModal(ChatEnable, {next: "/chat"}))
2024-12-16 19:24:10 +00:00
2024-12-17 01:07:52 +00:00
$: spaceUrls = Array.from($userRoomsByUrl.keys())
2024-12-16 19:24:10 +00:00
$: spacePaths = spaceUrls.map(url => makeSpacePath(url))
2024-12-16 19:49:57 +00:00
$: anySpaceNotifications = spacePaths.some(
path => !$page.url.pathname.startsWith(path) && $notifications.has(path),
)
2024-08-05 21:45:16 +00:00
</script>
2024-11-18 23:34:19 +00:00
<div class="relative z-nav hidden w-14 flex-shrink-0 bg-base-200 pt-4 md:block">
2024-10-21 17:51:37 +00:00
<div class="flex h-full flex-col justify-between">
<div>
2024-10-22 18:04:40 +00:00
{#if PLATFORM_RELAY}
2024-11-14 18:53:13 +00:00
<PrimaryNavItemSpace url={PLATFORM_RELAY} />
2024-10-21 17:51:37 +00:00
{:else}
2024-10-22 18:16:32 +00:00
<PrimaryNavItem title="Home" href="/home" class="tooltip-right">
<Avatar src={PLATFORM_LOGO} class="!h-10 !w-10" />
</PrimaryNavItem>
<Divider />
2024-12-16 19:24:10 +00:00
{#each spaceUrls as url (url)}
2024-11-14 18:53:13 +00:00
<PrimaryNavItemSpace {url} />
2024-10-18 22:58:44 +00:00
{/each}
<PrimaryNavItem title="Add Space" on:click={addSpace} class="tooltip-right">
2024-11-01 21:46:38 +00:00
<Avatar icon="settings-minimalistic" class="!h-10 !w-10" />
2024-10-18 22:58:44 +00:00
</PrimaryNavItem>
2024-10-21 17:51:37 +00:00
{/if}
</div>
<div>
2024-10-21 21:09:57 +00:00
<PrimaryNavItem
title="Settings"
href="/settings/profile"
prefix="/settings"
class="tooltip-right">
2024-10-21 17:51:37 +00:00
<Avatar src={$userProfile?.picture} class="!h-10 !w-10" />
</PrimaryNavItem>
2024-11-14 18:53:13 +00:00
<PrimaryNavItem
title="Messages"
on:click={openChat}
2024-11-14 18:53:13 +00:00
class="tooltip-right"
2024-12-16 19:24:10 +00:00
notification={$notifications.has("/chat")}>
<Avatar icon="letter" class="!h-10 !w-10" />
2024-10-21 17:51:37 +00:00
</PrimaryNavItem>
2024-10-21 20:46:32 +00:00
<PrimaryNavItem title="Search" href="/people" class="tooltip-right">
<Avatar icon="magnifer" class="!h-10 !w-10" />
</PrimaryNavItem>
2024-08-05 21:45:16 +00:00
</div>
</div>
2024-10-21 17:51:37 +00:00
</div>
2024-10-09 21:19:27 +00:00
<slot />
2024-10-18 23:09:17 +00:00
<div
class="border-top fixed bottom-0 left-0 right-0 z-nav h-14 border border-base-200 bg-base-100 md:hidden">
<div class="content-padding-x content-sizing flex justify-between px-2">
2024-10-23 16:45:06 +00:00
<div class="flex gap-2 sm:gap-8">
2025-01-15 18:56:56 +00:00
<PrimaryNavItem title="Home" href="/home">
<Avatar icon="home-smile" class="!h-10 !w-10" />
</PrimaryNavItem>
2024-12-16 19:24:10 +00:00
<PrimaryNavItem
title="Messages"
on:click={openChat}
notification={$notifications.has("/chat")}>
<Avatar icon="letter" class="!h-10 !w-10" />
</PrimaryNavItem>
2024-12-16 19:24:10 +00:00
<PrimaryNavItem title="Spaces" on:click={showSpacesMenu} notification={anySpaceNotifications}>
2024-10-25 23:59:12 +00:00
<Avatar icon="settings-minimalistic" class="!h-10 !w-10" />
2024-10-21 20:46:32 +00:00
</PrimaryNavItem>
</div>
2024-10-21 20:46:32 +00:00
<PrimaryNavItem title="Settings" on:click={showSettingsMenu}>
2025-01-15 18:56:56 +00:00
<Avatar icon="settings" src={$userProfile?.picture} class="!h-10 !w-10" />
2024-10-09 21:19:27 +00:00
</PrimaryNavItem>
</div>
</div>