nav: context-aware New button for database routes

- Show "New character/weapon/summon" pill button on database pages
- Keep existing circular + button for team creation elsewhere

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Justin Edmund 2025-12-01 02:27:47 -08:00
parent 43c291327c
commit 39b1ed9f64

View file

@ -64,6 +64,35 @@
// Database route detection
const isDatabaseRoute = $derived($page.url.pathname.startsWith(localizeHref('/database')))
// Detect current database entity type
const currentDatabaseEntity = $derived.by(() => {
const path = $page.url.pathname
if (path.startsWith(databaseCharactersHref)) return 'character'
if (path.startsWith(databaseWeaponsHref)) return 'weapon'
if (path.startsWith(databaseSummonsHref)) return 'summon'
return null
})
// Database "New" button config
const databaseNewButtonLabel = $derived(
currentDatabaseEntity === 'character'
? 'New character'
: currentDatabaseEntity === 'weapon'
? 'New weapon'
: currentDatabaseEntity === 'summon'
? 'New summon'
: 'New'
)
const databaseNewButtonHref = $derived(
currentDatabaseEntity === 'character'
? localizeHref('/database/characters/new')
: currentDatabaseEntity === 'weapon'
? localizeHref('/database/weapons/new')
: currentDatabaseEntity === 'summon'
? localizeHref('/database/summons/new')
: localizeHref('/database')
)
// Function to check if a nav item is selected
function isNavSelected(href: string): boolean {
const path = $page.url.pathname
@ -232,17 +261,32 @@
</li>
</ul>
{/if}
<Button
icon="plus"
iconOnly
shape="circle"
variant="primary"
{...(userElement ? { element: userElement } : {})}
elementStyle={Boolean(userElement)}
class="new-team-button"
aria-label="New team"
href={newTeamHref}
/>
{#if isDatabaseRoute}
<Button
icon="plus"
shape="pill"
variant="primary"
size="small"
{...(userElement ? { element: userElement } : {})}
elementStyle={Boolean(userElement)}
class="new-item-button"
href={databaseNewButtonHref}
>
{databaseNewButtonLabel}
</Button>
{:else}
<Button
icon="plus"
iconOnly
shape="circle"
variant="primary"
{...(userElement ? { element: userElement } : {})}
elementStyle={Boolean(userElement)}
class="new-team-button"
aria-label="New team"
href={newTeamHref}
/>
{/if}
</nav>
<!-- Settings Modal -->
@ -482,6 +526,12 @@
// The Button component already handles size, shape, colors, etc.
}
// Style the database "New item" button
:global(.new-item-button) {
padding-top: spacing.$unit-2x !important;
padding-bottom: spacing.$unit-2x !important;
}
// Element-specific SELECTED states for navigation links
// Hover states remain the default grey (defined in base styles above)
nav.element-wind {