Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(url Query): Added an optional URL query parameter #116

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
import { Send } from '@material-ui/icons'
import React, { useState, useRef, useCallback } from 'react'
import React, { useState, useRef, useCallback, useContext, useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { RootState } from '../../store'
import { setIsChatMode, setQuery } from '../../slices/assistantSlice'
import clsx from 'clsx'
import { ExtensionContext } from '@looker/extension-sdk-react'

const PromptInput = () => {
const dispatch = useDispatch()
const [inputText, setInputText] = useState('')
const [letsGo, setLetsGo] = useState(false)
const inputRef = useRef(null)

const { lookerHostData } = React.useContext(ExtensionContext)

const { isQuerying } = useSelector((state: RootState) => state.assistant)

useEffect(() => {
// check if lookerHostData is undefined
if (lookerHostData) {
const queryPrompt = new URLSearchParams(lookerHostData?.route?.split('?')[1]).get('queryPrompt') as string
console.log('Query Prompt:', queryPrompt, lookerHostData)
if (queryPrompt && queryPrompt.length > 5) {
setInputText(queryPrompt)
setLetsGo(true)
}
}
}, [lookerHostData])

useEffect(() => {
if (letsGo) {
handleSubmit()
}
}, [letsGo])

const handleInputChange = (e: any) => {
setInputText(e.target.value)
}
Expand Down