22import { onMount } from ' svelte'
33import Icon from ' @iconify/svelte'
44
5- let keywordDesktop = ' '
6- let keywordMobile = ' '
5+ let keywordDesktop = $state ( ' ' )
6+ let keywordMobile = $state ( ' ' )
77
88interface PagefindResult {
99 url: string
@@ -13,25 +13,7 @@ interface PagefindResult {
1313 excerpt: string
1414}
1515
16- let result: PagefindResult [] = []
17-
18- // const fakeResult: PagefindResult[] = [
19- // {
20- // url: url('/'),
21- // meta: {
22- // title: 'This Is a Fake Search Result',
23- // },
24- // excerpt:
25- // 'Because the search cannot work in the <mark>dev</mark> environment.',
26- // },
27- // {
28- // url: url('/'),
29- // meta: {
30- // title: 'If You Want to Test the Search',
31- // },
32- // excerpt: 'Try running <mark>npm build && npm preview</mark> instead.',
33- // },
34- // ]
16+ let result: PagefindResult [] = $state ([])
3517
3618let search = (keyword : string , isDesktop : boolean ) => {}
3719
@@ -74,8 +56,8 @@ const togglePanel = () => {
7456 panel ?.classList .toggle (' float-panel-closed' )
7557}
7658
77- $ : search (keywordDesktop , true )
78- $ : search (keywordMobile , false )
59+ $effect (() => { search (keywordDesktop , true ) } )
60+ $effect (() => { search (keywordMobile , false ) } )
7961 </script >
8062
8163<!-- search bar for desktop view -->
@@ -84,14 +66,14 @@ $: search(keywordMobile, false)
8466 dark:bg-white/5 dark:hover:bg-white/10 dark:focus-within:bg-white/10
8567" >
8668 <Icon icon =" material-symbols:search" class =" absolute text-[1.25rem] pointer-events-none ml-3 transition my-auto text-black/30 dark:text-white/30" ></Icon >
87- <input placeholder ="搜索" bind:value ={keywordDesktop } on:focus ={() => search (keywordDesktop , true )}
69+ <input placeholder ="搜索" bind:value ={keywordDesktop } onfocus ={() => search (keywordDesktop , true )}
8870 class =" transition-all pl-10 text-sm bg-transparent outline-0
8971 h-full w-40 active:w-60 focus:w-60 text-black/50 dark:text-white/50"
9072 >
9173</div >
9274
9375<!-- toggle btn for phone/tablet view -->
94- <button on:click ={togglePanel } aria-label =" Search Panel" id =" search-switch"
76+ <button onclick ={togglePanel } aria-label =" Search Panel" id =" search-switch"
9577 class =" btn-plain scale-animation lg:!hidden rounded-lg w-11 h-11 active:scale-90" >
9678 <Icon icon =" material-symbols:search" class =" text-[1.25rem]" ></Icon >
9779</button >
0 commit comments