navigation.ts (990B)
1 import type { AdminRealm } from './api'; 2 3 export interface RealmNavigation { 4 visible: boolean; 5 label: string; 6 href: string; 7 isPlural: boolean; 8 } 9 10 export function realmNavigation( 11 realms: AdminRealm[] | null, 12 canCreateRealm: boolean 13 ): RealmNavigation { 14 const realmCount = realms?.length || 0; 15 const singleRealmOnly = realmCount === 1 && !canCreateRealm; 16 const firstSlug = realms?.[0]?.slug || ''; 17 18 return { 19 visible: realmCount > 0 || canCreateRealm, 20 label: singleRealmOnly ? 'Realm' : 'Realms', 21 href: singleRealmOnly 22 ? `/settings/${encodeURIComponent(firstSlug)}` 23 : '/realms', 24 isPlural: !singleRealmOnly, 25 }; 26 } 27 28 export function realmBreadcrumbItems( 29 realms: AdminRealm[] | null, 30 canCreateRealm: boolean, 31 realmSlug: string 32 ) { 33 const navigation = realmNavigation(realms, canCreateRealm); 34 return [ 35 { 36 label: navigation.label, 37 ...(navigation.isPlural ? { path: '/realms' } : {}), 38 }, 39 { label: realmSlug }, 40 ]; 41 }