'use client' import { usePathname, useRouter, useSearchParams } from 'next/navigation' import { useEffect, useRef, useState } from 'react' import Textarea from 'react-textarea-autosize' import { useEnterSubmit } from '@/lib/hooks/use-enter-submit' import { cn } from '@/lib/utils' import { Button, buttonVariants } from '@/components/ui/button' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' import { IconArrowElbow, IconHome } from '@/components/ui/icons' // import { UseChatHelpers } from '@aigxion/isdk/react' import { useTranslation } from 'react-i18next' import { PrefetchKind } from 'next/dist/client/components/router-reducer/router-reducer-types' export interface PromptIndexProps { onSubmit?: (value: string) => void isLoading?: boolean id: string } export function PromptFormIndex({ onSubmit, // input, // setInput, isLoading, id }: PromptIndexProps) { const router = useRouter() const { t } = useTranslation(); const { formRef, onKeyDown } = useEnterSubmit() const [input, setInput] = useState('') // const inputRef = useRef(null) // useEffect(() => { // if (inputRef.current) { // inputRef.current.focus() // } // }, []) const searchParams = useSearchParams() const pathname = usePathname() const q = searchParams.get('q') console.log("----PromptFormIndex----", pathname, q, ["/", "/zh-CN/"].includes(pathname)) return (
{ e.preventDefault() // if (!inputRef.current) { // return // } if (!input?.trim() || isLoading) { return } setInput('') // await onSubmit(input) const url = `/chat/${id}?q=${input}` if (["/", "/zh-CN/"].includes(pathname)) { // router.push(`/`, { shallow: false }) console.log("--onSubmit--", e, input, url) router.push(url, { scroll: false }) } else { router.prefetch(url, { kind: PrefetchKind.FULL }) history.pushState({}, '', url) history.go(1) if (!!onSubmit) { onSubmit(input) } } // inputRef.current.value = "" // router.prefetch(url, { // kind: PrefetchKind.FULL // }) // history.pushState({}, '', url) // history.go(1) }} ref={formRef} >
{/* */} New Chat