@@ -10,6 +10,7 @@ import iconShield from "@ktibow/iconset-material-symbols/shield";
1010import iconStar from "@ktibow/iconset-material-symbols/star" ;
1111import iconSearch from "@ktibow/iconset-material-symbols/search" ;
1212import { createMenu } from "./Menu" ;
13+ import { client } from "./main" ;
1314
1415export const Spacer : Component = function ( cx ) {
1516 return < div > </ div > ;
@@ -23,13 +24,41 @@ Spacer.css = `
2324export const UrlInput : Component <
2425 { } ,
2526 {
27+ value : string ;
2628 active : boolean ;
2729 input : HTMLInputElement ;
2830
2931 overflowItems : string [ ] ;
3032 }
3133> = function ( cx ) {
34+ this . value = "" ;
3235 this . overflowItems = [ "test" , "test2" , "test3" , "test4" , "test5" ] ;
36+ const fetchSuggestions = async ( ) => {
37+ console . log ( "fetched" ) ;
38+ let resp = await client . fetch (
39+ `http://suggestqueries.google.com/complete/search?client=firefox&q=${ encodeURIComponent ( this . input . value ) } `
40+ ) ;
41+ let json = await resp . json ( ) ;
42+ console . log ( json ) ;
43+ this . overflowItems = json [ 1 ] . slice ( 0 , 5 ) ;
44+ } ;
45+ let currentTimeout : number | null = null ;
46+ let ratelimiting = false ;
47+ let interval = 100 ;
48+ use ( this . value ) . listen ( ( ) => {
49+ if ( ratelimiting ) {
50+ if ( currentTimeout ) return ;
51+ // TODO: why is it using the node types here
52+ currentTimeout = setTimeout ( ( ) => {
53+ ratelimiting = false ;
54+ fetchSuggestions ( ) ;
55+ currentTimeout = null ;
56+ } , interval ) ;
57+ } else {
58+ ratelimiting = true ;
59+ fetchSuggestions ( ) ;
60+ }
61+ } ) ;
3362 return (
3463 < div
3564 on :click = { ( e : MouseEvent ) => {
@@ -61,7 +90,13 @@ export const UrlInput: Component<
6190 </ div >
6291 < div class = "realbar" >
6392 < IconButton icon = { iconShield } > </ IconButton >
64- < input this = { use ( this . input ) . bind ( ) } > </ input >
93+ < input
94+ this = { use ( this . input ) . bind ( ) }
95+ value = { use ( this . value ) . bind ( ) }
96+ on :input = { ( e : InputEvent ) => {
97+ this . value = ( e . target as HTMLInputElement ) . value ;
98+ } }
99+ > </ input >
65100
66101 < IconButton icon = { iconStar } > </ IconButton >
67102 </ div >
0 commit comments