|
52 | 52 | ); |
53 | 53 | let isVersionedPage = $derived(isApiPage || $page.url.pathname.includes('/examples')); |
54 | 54 |
|
| 55 | + // Check if we're on an overview page (no /api or /examples in path) |
| 56 | + let isOverviewPage = $derived(!isApiPage && !$page.url.pathname.includes('/examples')); |
| 57 | +
|
55 | 58 | function isActive(path: string): boolean { |
56 | 59 | return $page.url.pathname === `${base}/${path}`; |
57 | 60 | } |
|
100 | 103 | versionDropdownOpen = !versionDropdownOpen; |
101 | 104 | } |
102 | 105 |
|
103 | | - function selectVersion(tag: string) { |
| 106 | + async function selectVersion(tag: string) { |
104 | 107 | versionDropdownOpen = false; |
105 | 108 |
|
106 | | - if (!currentTag) return; |
| 109 | + // Update stored version preference |
| 110 | + const { versionStore } = await import('$lib/stores/versionStore'); |
| 111 | + versionStore.setVersion(packageId, tag); |
107 | 112 |
|
108 | 113 | // Preserve current hash if it exists |
109 | 114 | const hash = typeof window !== 'undefined' ? window.location.hash : ''; |
110 | 115 |
|
111 | | - // Get current page type (api or examples) |
| 116 | + // Get current page type (api or examples or overview) |
112 | 117 | const pathname = $page.url.pathname; |
113 | | - let pageType = 'api'; |
114 | | - let subPath = ''; |
115 | 118 |
|
116 | 119 | if (pathname.includes('/examples/')) { |
117 | 120 | // We're on a specific example page |
118 | | - pageType = 'examples'; |
119 | 121 | const match = pathname.match(/\/examples\/(.+)$/); |
120 | | - subPath = match ? `/${match[1]}` : ''; |
| 122 | + const subPath = match ? `/${match[1]}` : ''; |
| 123 | + goto(`${base}/${packageId}/${tag}/examples${subPath}${hash}`); |
121 | 124 | } else if (pathname.includes('/examples')) { |
122 | | - pageType = 'examples'; |
| 125 | + goto(`${base}/${packageId}/${tag}/examples${hash}`); |
| 126 | + } else if (pathname.includes('/api')) { |
| 127 | + goto(`${base}/${packageId}/${tag}/api${hash}`); |
| 128 | + } else { |
| 129 | + // On overview page - reload to pick up new version |
| 130 | + const { invalidateAll } = await import('$app/navigation'); |
| 131 | + await invalidateAll(); |
123 | 132 | } |
124 | | -
|
125 | | - // Navigate to the same page with new version |
126 | | - goto(`${base}/${packageId}/${tag}/${pageType}${subPath}${hash}`); |
127 | 133 | } |
128 | 134 |
|
129 | 135 | function handleVersionClickOutside(event: MouseEvent) { |
|
188 | 194 | {/if} |
189 | 195 | </nav> |
190 | 196 | {:else} |
191 | | - <!-- Version selector - only show on versioned pages --> |
192 | | - {#if isVersionedPage && manifest && currentTag} |
| 197 | + <!-- Version selector - show whenever manifest is available --> |
| 198 | + {#if manifest && currentTag} |
193 | 199 | <div class="version-selector-container" bind:this={versionDropdownRef}> |
194 | 200 | <button |
195 | 201 | class="version-selector-trigger" |
|
0 commit comments