crossfade

This commit is contained in:
Vincent van der Wal
2026-08-01 15:58:19 +02:00
parent 0d5dbbc61f
commit 17cf8df109
16 changed files with 258 additions and 51 deletions
@@ -1,6 +1,10 @@
<script lang="ts">
import { page } from '$app/stores';
import { storedLocation } from '$lib/stores/settings';
import { buildLocationRoute } from '$lib/utils/location';
import { href, routePath } from '$lib/i18n';
import * as m from '$lib/paraglide/messages';
@@ -18,6 +22,7 @@
{
title: m.nav_week,
url: '/weather/week' as const,
route: '/weather/week/[location]' as const,
iconPaths: [
'M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z'
]
@@ -25,11 +30,13 @@
{
title: m.nav_compare,
url: '/weather/compare' as const,
route: '/weather/compare/[location]' as const,
iconPaths: ['M13 7h8m0 0v8m0-8l-8 8-4-4-6 6']
},
{
title: m.nav_14day,
url: '/weather/14-day' as const,
route: '/weather/14-day/[location]' as const,
iconPaths: [
'M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z'
]
@@ -37,12 +44,14 @@
{
title: m.nav_seasonal,
url: '/weather/seasonal' as const,
route: '/weather/seasonal/[location]' as const,
// rising trend line (long-range outlook)
iconPaths: ['M3 17l6-6 4 4 7-7', 'M16 8h5v5']
},
{
title: m.nav_historical,
url: '/weather/historical' as const,
route: '/weather/historical/[location]' as const,
// clock with a counter-clockwise arrow (history)
iconPaths: ['M12 8v4l3 2', 'M3.5 9a9 9 0 1 0 2.2-3.6L3 8m0-4.5V8h4.5']
},
@@ -59,6 +68,11 @@
// the URL carries a locale prefix; compare the neutral path behind it
let currentPath = $derived(routePath($page.url.pathname));
// Link straight to the location page instead of the bare redirect route: it
// saves a navigation, and the page cross-fade can then wait for the real
// page's data instead of flashing through an empty redirect stub.
let locationRoute = $derived(buildLocationRoute($storedLocation));
const isActive = (url: string) => {
return currentPath === url || currentPath.startsWith(url + '/');
};
@@ -73,7 +87,7 @@
home link fills the entire row, padding included -->
<div class="flex h-14 shrink-0 items-stretch border-b border-sidebar-border">
<a
href={href('/weather/week')}
href={href('/weather/week/[location]', { location: locationRoute })}
class="flex flex-1 items-center gap-2.5 transition-colors hover:bg-sidebar-accent {collapsed
? 'justify-center'
: 'px-4'}"
@@ -98,7 +112,7 @@
{#each links as link (link.url)}
{@const active = isActive(link.url)}
<a
href={href(link.url)}
href={link.route ? href(link.route, { location: locationRoute }) : href(link.url)}
class="relative flex items-center rounded-md px-2.5 py-2 text-sm font-medium text-sidebar-foreground opacity-70 transition-colors duration-150 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:opacity-100 {active
? 'bg-sidebar-accent text-sidebar-primary! opacity-100! font-semibold! nav-active'
: ''}"