@@ -2,6 +2,7 @@ import { useCallback, useRef, useState } from 'react'
2
2
import Modal from './modal'
3
3
import { SuggestSearchListItem } from './suggest-search-list-item'
4
4
import { classNames } from '../lib/class-names'
5
+ import { EZQL , Prompt } from 'ezql'
5
6
6
7
import styles from './ezql-prompt.module.css'
7
8
@@ -23,14 +24,19 @@ export default function EzqlPrompt({
23
24
className,
24
25
} : EzqlPromptOpts ) {
25
26
const [ query , setQuery ] = useState ( '' )
27
+
26
28
const listRef = useRef < HTMLUListElement > ( null )
27
29
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 )
30
33
31
34
// TODO make request to Outerbase
35
+ const ezql = new EZQL ( { token } )
36
+ const result = await ezql . prompt ( phrase , Prompt . sql )
37
+ console . dir ( result )
32
38
// and pass the result to onResults()
33
- } , [ ] )
39
+ } , [ token ] )
34
40
35
41
return (
36
42
< Modal didDismiss = { ( ) => setShouldDisplayEzql ( false ) } className = { classNames ( 'ezql-prompt-modal' , className ) } >
@@ -61,7 +67,7 @@ export default function EzqlPrompt({
61
67
</ span >
62
68
< ul className = { classNames ( styles . suggestions_list , 'suggestions-list' ) } ref = { listRef } >
63
69
{ suggestions ?. map ( ( text ) => (
64
- < SuggestSearchListItem key = { text } text = { text } didSubmitWithValue = { didSubmitWithValue } />
70
+ < SuggestSearchListItem key = { text } text = { text } didSubmitWithValue = { onSubmission } />
65
71
) ) }
66
72
</ ul >
67
73
</ div >
0 commit comments