import { ChatbotUIContext } from "@/context/context" import useHotkey from "@/lib/hooks/use-hotkey" import { IconLoader2, IconSend } from "@tabler/icons-react" import { FC, useContext, useState } from "react" import { Dialog, DialogContent } from "../ui/dialog" import { TextareaAutosize } from "../ui/textarea-autosize" interface CommandKProps {} export const CommandK: FC = ({}) => { useHotkey("k", () => setIsOpen(prevState => !prevState)) const { profile } = useContext(ChatbotUIContext) const [isOpen, setIsOpen] = useState(false) const [value, setValue] = useState("") const [loading, setLoading] = useState(false) const [content, setContent] = useState("") const handleCommandK = async () => { setLoading(true) const response = await fetch("/api/command", { method: "POST", body: JSON.stringify({ input: value }) }) const data = await response.json() setContent(data.content) setLoading(false) setValue("") } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault() handleCommandK() } } if (!profile) return null return ( isOpen && ( {profile.openai_api_key ? (
{content}
turn dark mode on.
find my sql chat
i need a new assistant
start a chat with my 2024 resolutions file
{loading ? ( ) : ( )}
) : (
Add your OpenAI API key in the settings to unlock CMD+K.
)}
) ) }