2025-03-26 00:16:36 +01:00
|
|
|
<script lang="ts" context="module">
|
|
|
|
|
export type Tab = {
|
|
|
|
|
path: string,
|
|
|
|
|
title: string,
|
|
|
|
|
icon: string,
|
|
|
|
|
component?: ComponentType,
|
|
|
|
|
hidden?: boolean,
|
|
|
|
|
hide_background?: boolean,
|
|
|
|
|
hide_frame?: boolean,
|
|
|
|
|
subpages?: Tab[],
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { onMount, type ComponentType } from "svelte";
|
2025-03-27 15:38:59 +01:00
|
|
|
import Footer from "layout/Footer.svelte";
|
2022-10-18 14:30:50 +02:00
|
|
|
|
|
|
|
|
export let title = ""
|
2025-03-26 00:16:36 +01:00
|
|
|
export let pages: Tab[] = []
|
2022-10-18 14:30:50 +02:00
|
|
|
|
2025-07-30 18:53:10 +02:00
|
|
|
const navigate = (page: Tab) => {
|
|
|
|
|
window.history.pushState({}, window.document.title, page.path)
|
2022-10-18 14:30:50 +02:00
|
|
|
get_page()
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 18:53:10 +02:00
|
|
|
const get_page = () => {
|
2022-10-18 14:30:50 +02:00
|
|
|
current_page = null
|
|
|
|
|
current_subpage = null
|
|
|
|
|
|
2025-07-30 18:53:10 +02:00
|
|
|
for (const page of pages) {
|
2022-10-18 14:30:50 +02:00
|
|
|
if (window.location.pathname.endsWith(page.path)) {
|
|
|
|
|
current_page = page
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (page.subpages) {
|
|
|
|
|
page.subpages.forEach(subpage => {
|
|
|
|
|
if (window.location.pathname.endsWith(subpage.path)) {
|
|
|
|
|
current_page = page
|
|
|
|
|
current_subpage = subpage
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-07-30 18:53:10 +02:00
|
|
|
}
|
2022-10-18 14:30:50 +02:00
|
|
|
|
|
|
|
|
// If no page is active, default to home
|
|
|
|
|
if (!current_page) {
|
|
|
|
|
current_page = pages[0]
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 18:53:10 +02:00
|
|
|
// If no subpage is active, default to the first subpage, if there are any
|
2022-10-18 14:30:50 +02:00
|
|
|
if (!current_subpage && current_page.subpages) {
|
|
|
|
|
current_subpage = current_page.subpages[0]
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 18:53:10 +02:00
|
|
|
title = current_subpage === null ? current_page.title : current_subpage.title
|
|
|
|
|
window.document.title = title+" ~ pixeldrain"
|
|
|
|
|
|
|
|
|
|
console.debug("Page", current_page)
|
|
|
|
|
console.debug("Subpage", current_subpage)
|
2022-10-18 14:30:50 +02:00
|
|
|
|
|
|
|
|
pages = pages
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-26 00:16:36 +01:00
|
|
|
let current_page: Tab = null
|
|
|
|
|
let current_subpage: Tab = null
|
2022-10-18 14:30:50 +02:00
|
|
|
|
|
|
|
|
onMount(() => get_page())
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:window on:popstate={get_page} />
|
|
|
|
|
|
2025-03-26 00:16:36 +01:00
|
|
|
{#if current_page !== null && current_page.hide_frame !== true}
|
|
|
|
|
<header>
|
|
|
|
|
<h1>{title}</h1>
|
|
|
|
|
|
|
|
|
|
<div class="tab_bar">
|
|
|
|
|
{#each pages as page}
|
|
|
|
|
{#if !page.hidden}
|
|
|
|
|
<a class="button"
|
|
|
|
|
href="{page.path}"
|
|
|
|
|
class:button_highlight={current_page && page.path === current_page.path}
|
2025-07-30 18:53:10 +02:00
|
|
|
on:click|preventDefault={() => {navigate(page)}}>
|
2025-03-26 00:16:36 +01:00
|
|
|
<i class="icon">{page.icon}</i>
|
|
|
|
|
<span>{page.title}</span>
|
|
|
|
|
</a>
|
|
|
|
|
{/if}
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
{/if}
|
2022-10-18 14:30:50 +02:00
|
|
|
|
2025-03-26 00:16:36 +01:00
|
|
|
{#if current_page !== null}
|
2024-07-09 18:18:26 +02:00
|
|
|
<div id="page_content" class:page_content={current_page.hide_background !== true}>
|
2022-10-18 14:30:50 +02:00
|
|
|
{#if current_page.subpages}
|
|
|
|
|
<div class="tab_bar submenu">
|
|
|
|
|
{#each current_page.subpages as page}
|
|
|
|
|
{#if !page.hidden}
|
|
|
|
|
<a class="button"
|
|
|
|
|
href="{page.path}"
|
|
|
|
|
class:button_highlight={current_subpage && page.path === current_subpage.path}
|
2025-07-30 18:53:10 +02:00
|
|
|
on:click|preventDefault={() => {navigate(page)}}>
|
2023-11-16 12:17:36 +01:00
|
|
|
<i class="icon">{page.icon}</i>
|
|
|
|
|
<span>{page.title}</span>
|
2022-10-18 14:30:50 +02:00
|
|
|
</a>
|
|
|
|
|
{/if}
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if current_subpage}
|
|
|
|
|
<svelte:component this={current_subpage.component} />
|
|
|
|
|
{/if}
|
|
|
|
|
{:else}
|
|
|
|
|
<svelte:component this={current_page.component} />
|
|
|
|
|
{/if}
|
2024-07-09 18:18:26 +02:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
2022-10-18 14:30:50 +02:00
|
|
|
|
2025-03-26 00:16:36 +01:00
|
|
|
{#if current_page !== null && current_page.hide_frame !== true}
|
|
|
|
|
<Footer/>
|
|
|
|
|
{/if}
|
2022-10-18 14:30:50 +02:00
|
|
|
|
|
|
|
|
<style>
|
2023-11-16 12:17:36 +01:00
|
|
|
.submenu {
|
2022-10-18 14:30:50 +02:00
|
|
|
border-bottom: 2px solid var(--separator);
|
|
|
|
|
}
|
2023-11-16 12:17:36 +01:00
|
|
|
.tab_bar > .button {
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: 0;
|
|
|
|
|
}
|
2022-10-18 14:30:50 +02:00
|
|
|
</style>
|