update admin layout
All checks were successful
delpoy / build-and-deploy (push) Successful in 49s

This commit is contained in:
bytedream 2024-12-03 03:12:17 +01:00
parent 332089228e
commit 672379c27b
2 changed files with 44 additions and 18 deletions

View File

@ -24,6 +24,8 @@
await onUpdate(); await onUpdate();
await tick(); await tick();
if (!bodyElem) return;
const intersectionObserver = new IntersectionObserver( const intersectionObserver = new IntersectionObserver(
async (entries, observer) => { async (entries, observer) => {
if (entries.filter((e) => e.isIntersecting).length === 0 || !entries) return; if (entries.filter((e) => e.isIntersecting).length === 0 || !entries) return;

View File

@ -1,9 +1,10 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores'; import { page } from '$app/stores';
import { fly } from 'svelte/transition';
import { env } from '$env/dynamic/public'; import { env } from '$env/dynamic/public';
import { import {
ArrowLeftOnRectangle, ArrowLeftOnRectangle,
Cog6Tooth, AdjustmentsHorizontal,
Flag, Flag,
UserGroup, UserGroup,
Users, Users,
@ -16,6 +17,8 @@
let { children, data } = $props(); let { children, data } = $props();
let transitionPrefix = $state(0);
async function logout() { async function logout() {
const response = await fetch(`${env.PUBLIC_BASE_PATH}/admin/logout`, { const response = await fetch(`${env.PUBLIC_BASE_PATH}/admin/logout`, {
method: 'POST' method: 'POST'
@ -62,18 +65,17 @@
}, },
{ {
path: `${env.PUBLIC_BASE_PATH}/admin/settings`, path: `${env.PUBLIC_BASE_PATH}/admin/settings`,
icon: Cog6Tooth, icon: AdjustmentsHorizontal,
name: 'Website Einstellungen', name: 'Website Einstellungen',
badge: null, badge: null,
enabled: data.settingsRead enabled: data.settingsRead
} }
]; ];
let pageTitleSuffix = let pageTitleSuffix = $derived(
(tabs.find((t) => $page.url.pathname === t.path)?.name ?? tabs.find((t) => $page.url.pathname === t.path)?.name ??
$page.url.pathname === `${env.PUBLIC_BASE_PATH}/admin/login`) ($page.url.pathname === `${env.PUBLIC_BASE_PATH}/admin/login` ? 'Login' : null)
? 'Login ' );
: null;
</script> </script>
<svelte:head> <svelte:head>
@ -81,23 +83,34 @@
</svelte:head> </svelte:head>
{#if $page.url.pathname !== `${env.PUBLIC_BASE_PATH}/admin/login`} {#if $page.url.pathname !== `${env.PUBLIC_BASE_PATH}/admin/login`}
<div class="h-12 relative bg-base-200 flex justify-center items-center"> <div class="relative bg-base-200 w-full flex justify-center">
<ul class="menu menu-horizontal h-10 p-0 flex items-center bg-base-300 rounded-lg"> <div role="tablist" class="tabs tabs-lifted">
{#each tabs as tab} {#each tabs as tab, i}
{#if tab.enabled} {#if tab.enabled}
{@const Icon = tab.icon} {@const Icon = tab.icon}
<li> <a
<a href={tab.path}> role="tab"
class="tab h-full"
class:tab-active={$page.url.pathname === tab.path}
href={tab.path}
onclick={() => {
let currIdx = tabs.findIndex((t) => $page.url.pathname === t.path);
if (currIdx !== -1) {
transitionPrefix = currIdx < i ? 1 : -1;
}
}}
>
<span class="my-2 flex items-center space-x-1">
<Icon /> <Icon />
<span class="mr-1" class:underline={$page.url.pathname === tab.path}>{tab.name}</span> <span>{tab.name}</span>
{#if tab.badge != null} {#if tab.badge != null}
<div class="badge">{tab.badge}</div> <div class="badge">{tab.badge}</div>
{/if} {/if}
</a> </span>
</li> </a>
{/if} {/if}
{/each} {/each}
</ul> </div>
<div class="absolute top-0 right-0 flex items-center h-full"> <div class="absolute top-0 right-0 flex items-center h-full">
<ul class="menu menu-vertical"> <ul class="menu menu-vertical">
<li> <li>
@ -109,8 +122,19 @@
</ul> </ul>
</div> </div>
</div> </div>
<div class="h-full w-full -mt-12 pt-12 overflow-y-scroll overflow-x-hidden"> <div class="grid">
{@render children()} {#key $page.url.pathname}
<div
class="col-[1] row-[1] h-full w-full overflow-y-scroll overflow-x-hidden"
in:fly={{ x: transitionPrefix * window.innerWidth, duration: !transitionPrefix ? 0 : 150 }}
out:fly={{
x: transitionPrefix * -window.innerWidth,
duration: !transitionPrefix ? 0 : 150
}}
>
{@render children()}
</div>
{/key}
</div> </div>
{:else} {:else}
<div class="h-full w-full"> <div class="h-full w-full">