Skip to content

Commit

Permalink
enhancement: removing pill menu from ram pages
Browse files Browse the repository at this point in the history
enhancement: adding back button to return to overview page
  • Loading branch information
dafuga committed Oct 26, 2024
1 parent 1a7642c commit 5a581b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
26 changes: 22 additions & 4 deletions src/lib/components/pageheader.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
<script lang="ts">
import { ArrowLeft } from 'lucide-svelte';
import { goto } from '$app/navigation';
interface Props {
title: string;
subtitle?: string;
inverted?: boolean;
backPath?: string;
}
let props: Props = $props();
function goBack() {
if (props.backPath) {
goto(props.backPath);
} else {
history.back();
}
}
</script>

<header class="flex gap-2" class:flex-col={!props.inverted} class:flex-col-reverse={props.inverted}>
<h1 class="text-3xl font-bold leading-none text-white">{props.title}</h1>
{#if props.subtitle}
<h2 class="text-xl font-medium leading-none text-white/60">{props.subtitle}</h2>
<header class="flex items-center gap-4">
{#if props.backPath}
<button onclick={goBack} class="text-white hover:text-white/80 focus:outline-none">
<ArrowLeft size={24} />
</button>
{/if}
<div class="flex gap-2" class:flex-col={!props.inverted} class:flex-col-reverse={props.inverted}>
<h1 class="text-3xl font-bold leading-none text-white">{props.title}</h1>
{#if props.subtitle}
<h2 class="text-xl font-medium leading-none text-white/60">{props.subtitle}</h2>
{/if}
</div>
</header>
26 changes: 7 additions & 19 deletions src/routes/[network]/(account)/ram/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
<script lang="ts">
import { page } from '$app/stores';
import PillGroup from '$lib/components/navigation/pillgroup.svelte';
import Stack from '$lib/components/layout/stack.svelte';
import Pageheader from '$lib/components/pageheader.svelte';
import { i18n } from '$lib/i18n';
const { data, children } = $props();
const tabOptions = $derived.by(() => {
const network = String(data.network);
return [
{ href: `/${network}/ram`, text: 'Overview' },
{ href: `/${network}/ram/buy`, text: 'Buy RAM' },
{ href: `/${network}/ram/sell`, text: 'Sell RAM' }
];
});
const locale = i18n.getLanguageFromUrl($page.url);
let currentTab = $derived($page.url.pathname.split('/')[4] || 'overview');
let options = $derived(
tabOptions.map((option) => ({
...option,
active: $page.url.pathname.replace(/^\/[^/]+/, '') === option.href
}))
);
const subtitle = $derived.by(() => {
switch (currentTab) {
case 'buy':
Expand All @@ -34,12 +20,14 @@
return 'Overview';
}
});
let backPath = $derived(
currentTab === 'overview' ? undefined : `/${locale}/${data.network.shortname}/ram`
);
</script>

<Stack class="gap-6">
<Pageheader title="RAM" {subtitle} />

<PillGroup {options} class="mb-6" />
<Pageheader title="RAM" {subtitle} {backPath} />

{@render children()}
</Stack>

0 comments on commit 5a581b2

Please sign in to comment.