@@ -2,6 +2,7 @@ import { useCallback, useRef, useState } from 'react'
22import Modal from './modal'
33import { SuggestSearchListItem } from './suggest-search-list-item'
44import { classNames } from '../lib/class-names'
5+ import { EZQL , Prompt } from 'ezql'
56
67import styles from './ezql-prompt.module.css'
78
@@ -23,14 +24,19 @@ export default function EzqlPrompt({
2324 className,
2425} : EzqlPromptOpts ) {
2526 const [ query , setQuery ] = useState ( '' )
27+
2628 const listRef = useRef < HTMLUListElement > ( null )
2729
28- const onSubmission = useCallback ( ( value : string ) => {
29- if ( didSubmitWithValue ) didSubmitWithValue ( value )
30+ const onSubmission = useCallback ( async ( phrase : string ) => {
31+ if ( ! token ) throw new Error ( "Missing token" )
32+ if ( didSubmitWithValue ) didSubmitWithValue ( phrase )
3033
3134 // TODO make request to Outerbase
35+ const ezql = new EZQL ( { token } )
36+ const result = await ezql . prompt ( phrase , Prompt . sql )
37+ console . dir ( result )
3238 // and pass the result to onResults()
33- } , [ ] )
39+ } , [ token ] )
3440
3541 return (
3642 < Modal didDismiss = { ( ) => setShouldDisplayEzql ( false ) } className = { classNames ( 'ezql-prompt-modal' , className ) } >
@@ -61,7 +67,7 @@ export default function EzqlPrompt({
6167 </ span >
6268 < ul className = { classNames ( styles . suggestions_list , 'suggestions-list' ) } ref = { listRef } >
6369 { suggestions ?. map ( ( text ) => (
64- < SuggestSearchListItem key = { text } text = { text } didSubmitWithValue = { didSubmitWithValue } />
70+ < SuggestSearchListItem key = { text } text = { text } didSubmitWithValue = { onSubmission } />
6571 ) ) }
6672 </ ul >
6773 </ div >
0 commit comments