mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
* First * Fix the parsing of SQL. * Get thread data action * Remove old page * Wait for data to complete * SSR everywhere * Remove unused * Add monaco settings * update loaders * Add sorting * supress hydration warnings * Fix profile layout * more server action action * fixes * Update page.tsx * Update actions.ts * Update AssistantChatForm.tsx * init * add polling * Update actions.ts * redirect to message id * Update page.tsx * Update page.tsx * handle run loading states with use client state with valtio * reduce first load JS * test action v1 * test action v2 * server action test 3 * test action 4 * test action 5 * test 6 * test 7 * test 7 * test 8 * test 9 * test 10 * test 11 * TEST 12 * TEST 13 * try and make it work * Update page.tsx * Update actions.ts * redirect added in * Update page.tsx * Update SchemaFlow.tsx * Update SchemaFlowHandler.tsx * 14 * Update SchemaFlow.tsx * move parse tables to client * a11y fixes --------- Co-authored-by: Terry Sutton <saltcod@gmail.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
107 lines
3.0 KiB
TypeScript
107 lines
3.0 KiB
TypeScript
'use client'
|
|
|
|
import { CHAT_EXAMPLES } from '@/data/chat-examples'
|
|
import { useAppStateSnapshot } from '@/lib/state'
|
|
import { createClient } from '@/lib/supabase/client'
|
|
import { ExternalLink } from 'lucide-react'
|
|
import { useEffect, useState } from 'react'
|
|
import { useFormState } from 'react-dom'
|
|
import { AssistantChatForm, cn } from 'ui'
|
|
import { createThread } from './actions'
|
|
import { useRouter } from 'next/navigation'
|
|
|
|
const suggestions = CHAT_EXAMPLES
|
|
|
|
const NewThreadInput = () => {
|
|
const router = useRouter()
|
|
const [value, setValue] = useState(() => {
|
|
if (typeof window !== 'undefined') {
|
|
const localPrompt = localStorage.getItem('prompt')
|
|
if (localPrompt) {
|
|
localStorage.removeItem('prompt')
|
|
return localPrompt
|
|
}
|
|
}
|
|
return ''
|
|
})
|
|
|
|
const initialState = {
|
|
message: undefined,
|
|
success: undefined,
|
|
data: {
|
|
value,
|
|
runId: undefined,
|
|
threadId: undefined,
|
|
messageId: undefined,
|
|
},
|
|
}
|
|
|
|
const [state, formAction] = useFormState(createThread, initialState)
|
|
|
|
// useEffect(() => {
|
|
// if (state.success && state.data.threadId && state.data.runId && state.data.messageId) {
|
|
// console.log(state.data)
|
|
// const { threadId, runId, messageId } = state.data
|
|
// console.log('threadId', threadId)
|
|
// console.log('runId', runId)
|
|
// console.log('messageId', messageId)
|
|
// // router.push(`/${state.data.threadId}/${state.data.runId}/${state.data.messageId}`)
|
|
// }
|
|
// }, [state.success])
|
|
|
|
const supabase = createClient()
|
|
const snap = useAppStateSnapshot()
|
|
|
|
return (
|
|
<>
|
|
<div className="relative w-10/12 xl:w-11/12 max-w-xl">
|
|
<AssistantChatForm
|
|
action={formAction}
|
|
key={'new-thread-form'}
|
|
id={'new-thread-form'}
|
|
onSubmit={async (event) => {
|
|
const {
|
|
data: { user },
|
|
} = await supabase.auth.getUser()
|
|
if (!user) {
|
|
event.preventDefault()
|
|
localStorage.setItem('prompt', value)
|
|
snap.setLoginDialogOpen(true)
|
|
return
|
|
}
|
|
}}
|
|
value={value}
|
|
placeholder="e.g Create a Telegram-like chat application"
|
|
onValueChange={(e) => setValue(e.target.value)}
|
|
message={state?.message}
|
|
/>
|
|
{state?.message && <p>{state?.message}</p>}
|
|
</div>
|
|
<div className="flex gap-3">
|
|
{suggestions.map((suggestion, idx) => (
|
|
<button
|
|
key={idx}
|
|
type="button"
|
|
className={cn(
|
|
'text-xs',
|
|
'flex items-center gap-3 !pr-3',
|
|
'transition border rounded-full px-3 py-1.5',
|
|
'text-light',
|
|
'hover:border-stronger hover:text'
|
|
)}
|
|
onClick={(event) => {
|
|
setValue(suggestion.prompt)
|
|
event.preventDefault()
|
|
}}
|
|
>
|
|
{suggestion.label}
|
|
<ExternalLink size={12} />
|
|
</button>
|
|
))}
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default NewThreadInput
|