flotilla/src/app/components/PrimaryNav.svelte

79 lines
2.5 KiB
Svelte
Raw Normal View History

2024-08-05 22:28:46 +00:00
<style>
.z-nav-active {
-webkit-mask-image: url("/nav-active.svg");
mask-image: url("/nav-active.svg");
}
</style>
2024-08-05 21:45:16 +00:00
<script lang="ts">
import {page} from "$app/stores"
2024-08-16 17:50:38 +00:00
import {tweened} from "svelte/motion"
import {quintOut} from "svelte/easing"
import {displayRelayUrl} from "@welshman/util"
2024-08-06 20:10:10 +00:00
import Icon from "@lib/components/Icon.svelte"
2024-08-15 21:30:55 +00:00
import Avatar from "@lib/components/Avatar.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 SpaceAvatar from "@app/components/SpaceAvatar.svelte"
import {userProfile, userMembership} from "@app/state"
2024-08-08 21:02:46 +00:00
import {pushModal} from "@app/modal"
import {makeSpacePath, getPrimaryNavItemIndex} from "@app/routes"
const activeOffset = tweened(-44, {
2024-08-16 17:50:38 +00:00
duration: 300,
easing: quintOut,
})
2024-08-08 21:02:46 +00:00
2024-08-14 00:58:26 +00:00
const addSpace = () => pushModal(SpaceAdd)
let element: HTMLElement
// Set the active highlight element to the offset of the nav item we're focused on
$: {
if (element) {
const index = getPrimaryNavItemIndex($page)
2024-08-16 17:50:38 +00:00
const navItems: any = Array.from(element.querySelectorAll(".z-nav-item") || [])
2024-08-14 00:58:26 +00:00
activeOffset.set(navItems[index].offsetTop - 44)
2024-08-14 00:58:26 +00:00
}
}
2024-08-05 21:45:16 +00:00
</script>
2024-08-26 21:43:43 +00:00
<div class="relative w-14 flex-shrink-0 bg-base-100 pt-4" bind:this={element}>
2024-08-16 17:50:38 +00:00
<div
class="absolute z-nav-active ml-2 h-[144px] w-12 bg-base-300"
style={`top: ${$activeOffset}px`} />
2024-08-05 22:28:46 +00:00
<div class="flex h-full flex-col justify-between">
2024-08-05 21:45:16 +00:00
<div>
2024-08-16 18:12:14 +00:00
<PrimaryNavItem href="/home">
2024-08-16 17:50:38 +00:00
<Avatar
src={$userProfile?.picture}
class="!h-10 !w-10 border border-solid border-base-300"
size={7} />
2024-08-05 21:45:16 +00:00
</PrimaryNavItem>
2024-09-23 17:28:33 +00:00
{#each $userMembership?.roomsByUrl.keys() || [] as url (url)}
<PrimaryNavItem title={displayRelayUrl(url)} href={makeSpacePath(url)}>
<SpaceAvatar {url} />
2024-08-14 00:58:26 +00:00
</PrimaryNavItem>
2024-08-05 21:45:16 +00:00
{/each}
2024-08-08 21:02:46 +00:00
<PrimaryNavItem title="Add Space" on:click={addSpace}>
2024-08-05 22:28:46 +00:00
<div class="!flex w-10 items-center justify-center">
2024-08-05 21:45:16 +00:00
<Icon size={7} icon="add-circle" />
</div>
</PrimaryNavItem>
2024-08-16 18:12:14 +00:00
<PrimaryNavItem title="Discover Spaces" href="/discover">
2024-08-05 22:28:46 +00:00
<div class="!flex w-10 items-center justify-center">
2024-08-05 21:45:16 +00:00
<Icon size={6} icon="compass-big" />
</div>
</PrimaryNavItem>
</div>
<div>
2024-08-16 18:12:14 +00:00
<PrimaryNavItem title="Settings" href="/settings">
2024-08-05 22:28:46 +00:00
<div class="!flex w-10 items-center justify-center">
2024-08-05 21:45:16 +00:00
<Icon size={7} icon="settings" />
</div>
</PrimaryNavItem>
</div>
</div>
</div>