AppShell.svelte (5053B)
1 <script lang="ts"> 2 import type { Snippet } from 'svelte'; 3 import { internalHref } from '../navigation-url'; 4 import Button from './primitives/Button.svelte'; 5 import CapabilityGate from './CapabilityGate.svelte'; 6 import type { IdentityViewActionResult } from '../runtime/view-context.ts'; 7 import type { IdentitySnapshot } from '../runtime/identity-session.ts'; 8 import Disclosure from './primitives/Disclosure.svelte'; 9 import { deploymentRelayPolicy } from '../config/deployment-relays.ts'; 10 import { operationCapabilities } from '../runtime/capabilities.ts'; 11 const availability = operationCapabilities(deploymentRelayPolicy); 12 13 type ShellRoute = 14 '/search' | '/sell' | '/selling' | '/messages' | '/about' | '/privacy'; 15 type Identity = 16 | { 17 kind: 'guest'; 18 onconnect?: () => Promise<IdentityViewActionResult> | void; 19 } 20 | { kind: 'connected'; publicKey: string; ondisconnect?: () => void }; 21 let { 22 children, 23 currentPath = '/', 24 availableRoutes = [], 25 identity = { kind: 'guest' }, 26 capability, 27 ondisconnect 28 }: { 29 children: Snippet; 30 currentPath?: string; 31 availableRoutes?: readonly ShellRoute[]; 32 identity?: Identity; 33 capability?: IdentitySnapshot; 34 ondisconnect?: () => void; 35 } = $props(); 36 37 const observed = $derived( 38 capability ?? 39 (identity.kind === 'guest' 40 ? { state: 'guest' as const, reason: 'disconnected' as const } 41 : { 42 state: 'connected' as const, 43 publicKey: identity.publicKey, 44 messaging: 'not_probed' as const 45 }) 46 ); 47 const unavailable = $derived( 48 !availableRoutes.includes('/search') || 49 !availableRoutes.includes('/about') || 50 !availableRoutes.includes('/privacy') || 51 (identity.kind === 'guest' 52 ? !availableRoutes.includes('/sell') || !identity.onconnect 53 : !availableRoutes.includes('/selling') || 54 !availableRoutes.includes('/messages') || 55 !identity.ondisconnect) 56 ); 57 58 function available(href: string) { 59 return ( 60 href === '/' || 61 availableRoutes.some((route) => route === href.split('#')[0]) 62 ); 63 } 64 </script> 65 66 {#snippet navigation(label: string, href: string, brand = false)} 67 {#if available(href) && internalHref(href)} 68 <a 69 href={internalHref(href)} 70 class="shell-link" 71 class:brand 72 aria-current={currentPath === href ? 'page' : undefined}>{label}</a 73 > 74 {:else} 75 <span 76 class="shell-link text-muted" 77 aria-disabled="true" 78 aria-describedby="shell-availability" 79 aria-current={currentPath === href ? 'page' : undefined}>{label}</span 80 > 81 {/if} 82 {/snippet} 83 84 <a href={internalHref('#main-content')} class="skip-link visually-hidden" 85 >Skip to main content</a 86 > 87 <header class="navbar"> 88 <nav aria-label="Primary" class="page navbar__inner"> 89 <div class="cluster"> 90 {@render navigation('HarvestCircle', '/', true)} 91 {@render navigation('Search', '/search')} 92 {#if identity.kind === 'guest'} 93 {@render navigation('List food', '/sell')} 94 {@render navigation('Messages', '/messages')} 95 {:else} 96 {@render navigation('Messages', '/messages')} 97 {@render navigation('Selling', '/selling')} 98 <Disclosure summary="Identity"> 99 <p class="key">{identity.publicKey}</p> 100 <Button 101 label="Disconnect" 102 disabled={!identity.ondisconnect} 103 onclick={identity.ondisconnect} 104 /> 105 </Disclosure> 106 {/if} 107 <CapabilityGate 108 focusTarget="navbar" 109 {ondisconnect} 110 identity={observed} 111 compact 112 focusScope={currentPath} 113 onconnect={identity.kind === 'guest' ? identity.onconnect : undefined} 114 /> 115 </div> 116 {#if unavailable} 117 <p id="shell-availability" class="text-small text-muted"> 118 Unavailable during development: disabled navigation and actions. 119 </p> 120 {/if} 121 </nav> 122 </header> 123 <main id="main-content" tabindex="-1" class="page"> 124 {#if !availability.posting || !availability.messaging} 125 <div class="notice stack" role="note" aria-label="Build availability"> 126 {#if !availability.posting}<p>Posting is disabled in this build.</p>{/if} 127 {#if !availability.messaging}<p> 128 Messaging is disabled in this build. 129 </p>{/if} 130 <p> 131 Browsing, local editing and pending-work review remain available where 132 supported. Availability flags do not establish full qualification. 133 </p> 134 <details class="disclosure"> 135 <summary>Availability limits</summary> 136 <p> 137 Static build flags do not instantly stop already-open tabs. Urgent 138 stops require relay enforcement. 139 </p> 140 </details> 141 </div> 142 {/if} 143 {@render children()} 144 </main> 145 <footer class="footer"> 146 <nav aria-label="Footer" class="page cluster"> 147 {@render navigation('About', '/about')} 148 {@render navigation('Privacy', '/privacy')} 149 {@render navigation('Help / report', '/about#help')} 150 </nav> 151 </footer>