Files
Lazuli/src/routes/(app)/+layout.svelte
T

116 lines
5.0 KiB
Svelte
Raw Normal View History

2024-01-25 19:50:26 -05:00
<script lang="ts">
2024-01-27 01:38:04 -05:00
import { fly } from 'svelte/transition'
2024-01-28 02:41:13 -05:00
import { goto, beforeNavigate } from '$app/navigation'
2024-01-26 01:30:18 -05:00
import { pageWidth } from '$lib/stores'
2024-01-28 02:41:13 -05:00
import type { LayoutData } from './$types'
import { onMount } from 'svelte'
2024-01-29 12:29:32 -05:00
import NavTabComponent, { type NavTab } from '$lib/components/navbar/navTab.svelte'
import PlaylistTabComponent, { type PlaylistTab } from '$lib/components/navbar/playlistTab.svelte'
2024-01-28 02:41:13 -05:00
export let data: LayoutData
2024-01-25 19:50:26 -05:00
const pageTransitionTime: number = 200
2024-01-28 02:41:13 -05:00
let currentTabIndex = -1
2024-01-25 19:50:26 -05:00
type PageTransitionDirection = 1 | -1
2024-01-27 01:38:04 -05:00
let directionMultiplier: PageTransitionDirection = 1
2024-01-28 02:41:13 -05:00
let indicatorBar: HTMLDivElement, tabList: HTMLDivElement
const inPathnameHeirarchy = (pathname: string, rootPathname: string): boolean => {
return (pathname.startsWith(rootPathname) && rootPathname !== '/') || (pathname === '/' && rootPathname === '/')
}
2024-01-29 12:29:32 -05:00
// const calculateDirection = (newTab: Tab): void => {
// const newTabIndex = data.tabs.findIndex((tab) => tab === newTab)
// directionMultiplier = newTabIndex > currentTabIndex ? -1 : 1
// currentTabIndex = newTabIndex
// }
2024-01-28 02:41:13 -05:00
2024-01-29 12:29:32 -05:00
// const navigate = (newPathname: string): void => {
// const newTabIndex = data.tabs.findIndex((tab) => inPathnameHeirarchy(newPathname, tab.pathname))
2024-01-28 02:41:13 -05:00
2024-01-29 12:29:32 -05:00
// if (newTabIndex < 0) indicatorBar.style.opacity = '0'
2024-01-28 02:41:13 -05:00
2024-01-29 12:29:32 -05:00
// const newTab = data.tabs[newTabIndex]
// if (!newTab?.button) return
2024-01-28 02:41:13 -05:00
2024-01-29 12:29:32 -05:00
// const tabRec = newTab.button.getBoundingClientRect(),
// listRect = tabList.getBoundingClientRect()
2024-01-28 02:41:13 -05:00
2024-01-29 12:29:32 -05:00
// const shiftTop = () => (indicatorBar.style.top = `${tabRec.top - listRect.top}px`),
// shiftBottom = () => (indicatorBar.style.bottom = `${listRect.bottom - tabRec.bottom}px`)
2024-01-28 02:41:13 -05:00
2024-01-29 12:29:32 -05:00
// if (directionMultiplier > 0) {
// shiftTop()
// setTimeout(shiftBottom, pageTransitionTime)
// } else {
// shiftBottom()
// setTimeout(shiftTop, pageTransitionTime)
// }
2024-01-28 02:41:13 -05:00
2024-01-29 12:29:32 -05:00
// setTimeout(() => (indicatorBar.style.opacity = '100%'), pageTransitionTime + 300)
// }
2024-01-28 02:41:13 -05:00
2024-01-29 12:29:32 -05:00
// onMount(() => setTimeout(() => navigate(data.url.pathname))) // More stupid fucking non-blocking event loop shit
// beforeNavigate(({ to }) => {
// if (to) navigate(to.url.pathname)
// })
2024-01-26 01:30:18 -05:00
</script>
2024-01-27 01:38:04 -05:00
{#if $pageWidth >= 768}
<div class="grid h-full grid-rows-1 gap-8 overflow-hidden">
2024-01-29 12:29:32 -05:00
<div class="no-scrollbar fixed left-0 top-0 z-10 grid h-full grid-cols-1 grid-rows-[min-content_auto] gap-6 p-3 pt-12 w-20" bind:this={tabList}>
<div class="flex flex-col gap-6">
2024-01-29 12:29:32 -05:00
{#each data.navTabs as nav}
<NavTabComponent {nav} disabled={inPathnameHeirarchy(data.url.pathname, nav.pathname)}/>
2024-01-28 02:41:13 -05:00
{/each}
2024-01-29 12:29:32 -05:00
<!-- <div bind:this={indicatorBar} class="absolute left-0 w-[0.2rem] rounded-full bg-white transition-all duration-300 ease-in-out" /> -->
</div>
2024-01-29 15:55:22 -05:00
<div class="flex flex-col gap-6 px-1">
2024-01-29 12:29:32 -05:00
{#each data.playlistTabs as playlist}
<PlaylistTabComponent {playlist} disabled={new URLSearchParams(data.url.search).get('playlist') === playlist.id} />
{/each}
</div>
2024-01-28 02:41:13 -05:00
</div>
2024-01-27 01:38:04 -05:00
<section class="no-scrollbar relative overflow-y-scroll">
2024-01-28 02:41:13 -05:00
{#key data.url}
2024-01-27 01:38:04 -05:00
<div
in:fly={{ y: -50 * directionMultiplier, duration: pageTransitionTime, delay: pageTransitionTime }}
out:fly={{ y: 50 * directionMultiplier, duration: pageTransitionTime }}
class="absolute w-full px-[clamp(7rem,_5vw,_24rem)] pt-16"
2024-01-27 01:38:04 -05:00
>
<slot />
</div>
{/key}
</section>
<footer class="fixed bottom-0 flex w-full flex-col items-center justify-center">
<!-- <MiniPlayer displayMode={'horizontal'} /> -->
</footer>
</div>
{:else}
2024-01-26 01:30:18 -05:00
<div class="h-full overflow-hidden">
2024-01-28 02:41:13 -05:00
{#key data.url.pathname}
2024-01-26 01:30:18 -05:00
<section
2024-01-27 01:38:04 -05:00
in:fly={{ x: 200 * directionMultiplier, duration: pageTransitionTime, delay: pageTransitionTime }}
out:fly={{ x: -200 * directionMultiplier, duration: pageTransitionTime }}
2024-01-26 01:30:18 -05:00
class="no-scrollbar h-full overflow-y-scroll px-[5vw] pt-16"
>
<slot />
</section>
{/key}
<footer class="fixed bottom-0 flex w-full flex-col items-center justify-center">
2024-01-27 01:38:04 -05:00
<!-- <MiniPlayer displayMode={'vertical'} /> -->
2024-01-28 02:41:13 -05:00
<!-- <NavbarFoot
2024-01-27 01:38:04 -05:00
{currentPathname}
transitionTime={pageTransitionTime}
on:navigate={(event) => {
event.detail.direction === 'right' ? (directionMultiplier = 1) : (directionMultiplier = -1)
currentPathname = event.detail.pathname
goto(currentPathname)
}}
2024-01-28 02:41:13 -05:00
/> -->
2024-01-26 01:30:18 -05:00
</footer>
</div>
2024-01-29 12:29:32 -05:00
{/if}