@@ -4,7 +4,8 @@ It appears when the user clicks on the `Search` component or presses the corresp
44-->
55<script lang =" ts" >
66 import { afterNavigate } from ' $app/navigation' ;
7- import { overlay_open , search_query , search_recent , searching } from ' ../stores' ;
7+ import { overlay_open } from ' ../stores' ;
8+ import { search } from ' ../state/search.svelte' ;
89 import { onMount , type Snippet } from ' svelte' ;
910 import { focusable_children , forcefocus , trap } from ' ../actions/focus.js' ;
1011 import Icon from ' ../components/Icon.svelte' ;
@@ -24,7 +25,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
2425 let modal = $state () as HTMLElement ;
2526
2627 // TODO proper types
27- let search : any = $state (null );
28+ let searched : any = $state (null );
2829 let recent_searches: any [] = $state ([]);
2930
3031 let last_scroll_position: number | null = null ;
@@ -46,7 +47,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
4647 }
4748
4849 if (type === ' results' ) {
49- search = payload ;
50+ searched = payload ;
5051 }
5152
5253 if (type === ' recents' ) {
@@ -69,8 +70,8 @@ It appears when the user clicks on the `Search` component or presses the corresp
6970 });
7071
7172 async function close() {
72- if ($searching ) {
73- $searching = false ;
73+ if (search . active ) {
74+ search . active = false ;
7475 const scroll = last_scroll_position || 0 ;
7576 last_scroll_position = null ;
7677 document .body .style .position = ' ' ;
@@ -79,14 +80,14 @@ It appears when the user clicks on the `Search` component or presses the corresp
7980 document .body .removeAttribute (' tabindex' );
8081 window .scrollTo (0 , scroll );
8182
82- $search_query = ' ' ;
83+ search . query = ' ' ;
8384 }
8485
85- search = null ;
86+ searched = null ;
8687 }
8788
8889 function navigate(href : string ) {
89- $search_recent = [href , ... $search_recent .filter ((x ) => x !== href )];
90+ search . recent = [href , ... search . recent .filter ((x ) => x !== href )];
9091 close ();
9192 }
9293
@@ -99,7 +100,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
99100 type: ' query' ,
100101 id ,
101102 payload: {
102- query: $search_query ,
103+ query: search . query ,
103104 path: $page .url .pathname
104105 }
105106 });
@@ -108,16 +109,16 @@ It appears when the user clicks on the `Search` component or presses the corresp
108109
109110 $effect (() => {
110111 if (ready ) {
111- worker .postMessage ({ type: ' recents' , payload: $state . snapshot ( $search_recent ) });
112+ worker .postMessage ({ type: ' recents' , payload: search . recent });
112113 }
113114 });
114115
115116 $effect (() => {
116- $overlay_open = $searching ;
117+ $overlay_open = search . active ;
117118 });
118119
119120 $effect (() => {
120- if ($searching ) {
121+ if (search . active ) {
121122 last_scroll_position = window .scrollY ;
122123 }
123124 });
@@ -127,12 +128,12 @@ It appears when the user clicks on the `Search` component or presses the corresp
127128 onkeydown ={(e ) => {
128129 if (e .key === ' k' && (navigator .platform === ' MacIntel' ? e .metaKey : e .ctrlKey )) {
129130 e .preventDefault ();
130- $search_query = ' ' ;
131+ search . query = ' ' ;
131132
132- if ($searching ) {
133+ if (search . active ) {
133134 close ();
134135 } else {
135- $searching = true ;
136+ search . active = true ;
136137 }
137138 }
138139
@@ -142,7 +143,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
142143 }}
143144/>
144145
145- {#if $searching && ready }
146+ {#if search . active && ready }
146147 <div class ="pseudo-overlay" aria-hidden ="true" onclick ={close }></div >
147148
148149 <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -178,16 +179,16 @@ It appears when the user clicks on the `Search` component or presses the corresp
178179 }
179180 }}
180181 oninput ={(e ) => {
181- $search_query = e .currentTarget .value ;
182+ search . query = e .currentTarget .value ;
182183 }}
183- value ={$search_query }
184+ value ={search . query }
184185 {placeholder }
185186 aria-describedby =" search-description"
186187 aria-label ={placeholder }
187188 spellcheck =" false"
188189 />
189190
190- <button aria-label ="Clear" onclick ={() => ($search_query = ' ' )}>
191+ <button aria-label ="Clear" onclick ={() => (search . query = ' ' )}>
191192 <Icon name =" close" />
192193 </button >
193194 </div >
@@ -207,11 +208,11 @@ It appears when the user clicks on the `Search` component or presses the corresp
207208 </span >
208209
209210 <div class =" results" >
210- {#if search ?.query }
211+ {#if searched ?.query }
211212 <div class =" results-container" >
212213 <SearchResults
213- results ={search .results }
214- query ={search .query }
214+ results ={searched .results }
215+ query ={searched .query }
215216 onselect ={(href ) => {
216217 navigate (href );
217218 }}
@@ -229,17 +230,17 @@ It appears when the user clicks on the `Search` component or presses the corresp
229230 {#if recent_searches .length }
230231 <div class =" results-container" >
231232 <ul class =" recent" >
232- {#each recent_searches as search }
233+ {#each recent_searches as result }
233234 <li >
234- <a onclick ={() => navigate (search .href )} href ={search .href }>
235- {search .breadcrumbs .at (- 1 )}
235+ <a onclick ={() => navigate (result .href )} href ={result .href }>
236+ {result .breadcrumbs .at (- 1 )}
236237 </a >
237238
238239 <button
239240 class =" raised icon"
240241 aria-label =" Delete"
241242 onclick ={(e ) => {
242- $search_recent = $search_recent . filter ((href ) => href !== search .href );
243+ search . recent = search . recent . filter ((href ) => href !== result .href );
243244 e .stopPropagation ();
244245 e .preventDefault ();
245246 }}
@@ -258,7 +259,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
258259{/if }
259260
260261<div aria-live =" assertive" class =" visually-hidden" >
261- {#if $searching && search ?.results .length === 0 }
262+ {#if search . active && searched ?.results .length === 0 }
262263 <p >
263264 {#if no_results }
264265 {@render no_results ()}
0 commit comments