@@ -4,7 +4,8 @@ It appears when the user clicks on the `Search` component or presses the corresp
4
4
-->
5
5
<script lang =" ts" >
6
6
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' ;
8
9
import { onMount , type Snippet } from ' svelte' ;
9
10
import { focusable_children , forcefocus , trap } from ' ../actions/focus.js' ;
10
11
import Icon from ' ../components/Icon.svelte' ;
@@ -24,7 +25,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
24
25
let modal = $state () as HTMLElement ;
25
26
26
27
// TODO proper types
27
- let search : any = $state (null );
28
+ let searched : any = $state (null );
28
29
let recent_searches: any [] = $state ([]);
29
30
30
31
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
46
47
}
47
48
48
49
if (type === ' results' ) {
49
- search = payload ;
50
+ searched = payload ;
50
51
}
51
52
52
53
if (type === ' recents' ) {
@@ -69,8 +70,8 @@ It appears when the user clicks on the `Search` component or presses the corresp
69
70
});
70
71
71
72
async function close() {
72
- if ($searching ) {
73
- $searching = false ;
73
+ if (search . active ) {
74
+ search . active = false ;
74
75
const scroll = last_scroll_position || 0 ;
75
76
last_scroll_position = null ;
76
77
document .body .style .position = ' ' ;
@@ -79,14 +80,14 @@ It appears when the user clicks on the `Search` component or presses the corresp
79
80
document .body .removeAttribute (' tabindex' );
80
81
window .scrollTo (0 , scroll );
81
82
82
- $search_query = ' ' ;
83
+ search . query = ' ' ;
83
84
}
84
85
85
- search = null ;
86
+ searched = null ;
86
87
}
87
88
88
89
function navigate(href : string ) {
89
- $search_recent = [href , ... $search_recent .filter ((x ) => x !== href )];
90
+ search . recent = [href , ... search . recent .filter ((x ) => x !== href )];
90
91
close ();
91
92
}
92
93
@@ -99,7 +100,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
99
100
type: ' query' ,
100
101
id ,
101
102
payload: {
102
- query: $search_query ,
103
+ query: search . query ,
103
104
path: $page .url .pathname
104
105
}
105
106
});
@@ -108,16 +109,16 @@ It appears when the user clicks on the `Search` component or presses the corresp
108
109
109
110
$effect (() => {
110
111
if (ready ) {
111
- worker .postMessage ({ type: ' recents' , payload: $state . snapshot ( $search_recent ) });
112
+ worker .postMessage ({ type: ' recents' , payload: search . recent });
112
113
}
113
114
});
114
115
115
116
$effect (() => {
116
- $overlay_open = $searching ;
117
+ $overlay_open = search . active ;
117
118
});
118
119
119
120
$effect (() => {
120
- if ($searching ) {
121
+ if (search . active ) {
121
122
last_scroll_position = window .scrollY ;
122
123
}
123
124
});
@@ -127,12 +128,12 @@ It appears when the user clicks on the `Search` component or presses the corresp
127
128
onkeydown ={(e ) => {
128
129
if (e .key === ' k' && (navigator .platform === ' MacIntel' ? e .metaKey : e .ctrlKey )) {
129
130
e .preventDefault ();
130
- $search_query = ' ' ;
131
+ search . query = ' ' ;
131
132
132
- if ($searching ) {
133
+ if (search . active ) {
133
134
close ();
134
135
} else {
135
- $searching = true ;
136
+ search . active = true ;
136
137
}
137
138
}
138
139
@@ -142,7 +143,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
142
143
}}
143
144
/>
144
145
145
- {#if $searching && ready }
146
+ {#if search . active && ready }
146
147
<div class ="pseudo-overlay" aria-hidden ="true" onclick ={close }></div >
147
148
148
149
<!-- 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
178
179
}
179
180
}}
180
181
oninput ={(e ) => {
181
- $search_query = e .currentTarget .value ;
182
+ search . query = e .currentTarget .value ;
182
183
}}
183
- value ={$search_query }
184
+ value ={search . query }
184
185
{placeholder }
185
186
aria-describedby =" search-description"
186
187
aria-label ={placeholder }
187
188
spellcheck =" false"
188
189
/>
189
190
190
- <button aria-label ="Clear" onclick ={() => ($search_query = ' ' )}>
191
+ <button aria-label ="Clear" onclick ={() => (search . query = ' ' )}>
191
192
<Icon name =" close" />
192
193
</button >
193
194
</div >
@@ -207,11 +208,11 @@ It appears when the user clicks on the `Search` component or presses the corresp
207
208
</span >
208
209
209
210
<div class =" results" >
210
- {#if search ?.query }
211
+ {#if searched ?.query }
211
212
<div class =" results-container" >
212
213
<SearchResults
213
- results ={search .results }
214
- query ={search .query }
214
+ results ={searched .results }
215
+ query ={searched .query }
215
216
onselect ={(href ) => {
216
217
navigate (href );
217
218
}}
@@ -229,17 +230,17 @@ It appears when the user clicks on the `Search` component or presses the corresp
229
230
{#if recent_searches .length }
230
231
<div class =" results-container" >
231
232
<ul class =" recent" >
232
- {#each recent_searches as search }
233
+ {#each recent_searches as result }
233
234
<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 )}
236
237
</a >
237
238
238
239
<button
239
240
class =" raised icon"
240
241
aria-label =" Delete"
241
242
onclick ={(e ) => {
242
- $search_recent = $search_recent . filter ((href ) => href !== search .href );
243
+ search . recent = search . recent . filter ((href ) => href !== result .href );
243
244
e .stopPropagation ();
244
245
e .preventDefault ();
245
246
}}
@@ -258,7 +259,7 @@ It appears when the user clicks on the `Search` component or presses the corresp
258
259
{/if }
259
260
260
261
<div aria-live =" assertive" class =" visually-hidden" >
261
- {#if $searching && search ?.results .length === 0 }
262
+ {#if search . active && searched ?.results .length === 0 }
262
263
<p >
263
264
{#if no_results }
264
265
{@render no_results ()}
0 commit comments