fix nav highlight for profile sub-routes

This commit is contained in:
Justin Edmund 2025-12-13 20:02:14 -08:00
parent 82c3f3c471
commit 492307530a

View file

@ -45,9 +45,6 @@
// Localized links // Localized links
const galleryHref = $derived(localizeHref('/teams/explore')) const galleryHref = $derived(localizeHref('/teams/explore'))
const guidesHref = $derived(localizeHref('/guides')) const guidesHref = $derived(localizeHref('/guides'))
const collectionHref = $derived(
username ? localizeHref(`/${username}/collection/characters`) : localizeHref('/collection')
)
const meHref = $derived(localizeHref('/me')) const meHref = $derived(localizeHref('/me'))
const loginHref = $derived(localizeHref('/auth/login')) const loginHref = $derived(localizeHref('/auth/login'))
const registerHref = $derived(localizeHref('/auth/register')) const registerHref = $derived(localizeHref('/auth/register'))
@ -110,11 +107,6 @@
return path === href return path === href
} }
// For collection, check if we're on any collection page
if (href === collectionHref) {
return path.includes('/collection')
}
// Exact match or starts with href + / // Exact match or starts with href + /
return path === href || path.startsWith(href + '/') return path === href || path.startsWith(href + '/')
} }
@ -124,9 +116,13 @@
return $page.url.pathname === href || $page.url.pathname.startsWith(href + '/') return $page.url.pathname === href || $page.url.pathname.startsWith(href + '/')
} }
// Check if the user profile link is selected // Check if the user profile link is selected (includes sub-routes like /favorites, /collection)
const userProfilePath = $derived(localizeHref(`/${username}`))
const isProfileSelected = $derived( const isProfileSelected = $derived(
isAuth && ($page.url.pathname === meHref || $page.url.pathname === localizeHref(`/${username}`)) isAuth &&
($page.url.pathname === meHref ||
$page.url.pathname === userProfilePath ||
$page.url.pathname.startsWith(userProfilePath + '/'))
) )
// Settings modal state // Settings modal state
@ -225,12 +221,10 @@
<a href={galleryHref} class:selected={isNavSelected(galleryHref)}>{m.nav_gallery()}</a> <a href={galleryHref} class:selected={isNavSelected(galleryHref)}>{m.nav_gallery()}</a>
</li> </li>
{#if isAuth} {#if isAuth}
<!-- Authenticated: show Guides and Collection in nav --> <!-- Authenticated: show Guides and Crew in nav -->
<li><a href={guidesHref} class:selected={isNavSelected(guidesHref)}>Guides</a></li> <li><a href={guidesHref} class:selected={isNavSelected(guidesHref)}>Guides</a></li>
<li> <li>
<a href={collectionHref} class:selected={isNavSelected(collectionHref)} <a href={crewHref} class:selected={isNavSelected(crewHref)}>Crew</a>
>{m.nav_collection()}</a
>
</li> </li>
<li> <li>
<a <a
@ -280,19 +274,19 @@
<DropdownMenu.Portal> <DropdownMenu.Portal>
<DropdownMenu.Content class="dropdown-content" sideOffset={5}> <DropdownMenu.Content class="dropdown-content" sideOffset={5}>
{#if !isAuth} {#if !isAuth}
<!-- Not authenticated: show Guides and Collection in dropdown --> <!-- Not authenticated: show Guides in dropdown -->
<DropdownItem> <DropdownItem>
<a href={guidesHref}>Guides</a> <a href={guidesHref}>Guides</a>
</DropdownItem> </DropdownItem>
<DropdownMenu.Separator class="dropdown-separator" />
{/if}
{#if role !== null && role >= 7}
<DropdownItem> <DropdownItem>
<a href={collectionHref}>{m.nav_collection()}</a> <a href={databaseHref}>Database</a>
</DropdownItem> </DropdownItem>
<DropdownMenu.Separator class="dropdown-separator" /> <DropdownMenu.Separator class="dropdown-separator" />
{/if} {/if}
{#if isAuth} {#if isAuth}
<DropdownItem>
<a href={crewHref}>Crew</a>
</DropdownItem>
<DropdownItem> <DropdownItem>
<button class="dropdown-button-with-badge" onclick={() => (invitationsModalOpen = true)}> <button class="dropdown-button-with-badge" onclick={() => (invitationsModalOpen = true)}>
<span>Invitations</span> <span>Invitations</span>
@ -307,11 +301,6 @@
{m.nav_settings()} {m.nav_settings()}
</button> </button>
</DropdownItem> </DropdownItem>
{#if role !== null && role >= 7}
<DropdownItem>
<a href={databaseHref}>Database</a>
</DropdownItem>
{/if}
{#if isAuth} {#if isAuth}
<DropdownMenu.Separator class="dropdown-separator" /> <DropdownMenu.Separator class="dropdown-separator" />
<DropdownItem> <DropdownItem>