import React, { KeyboardEventHandler, useEffect, useState } from 'react' import { askAI, askWithContext, defineWord } from '../ollama'; import { Input } from '@/components/ui/input'; export const PromptAI = ({ type, theme }: { type: string, theme: string }) => { const placeholder = type === 'ask ai' ? "Prompt..." : "Define..." const [inputValue, setInputValue] = useState(''); const [hitEnter, setHitEnter] = useState(false) useEffect(() => { if (hitEnter) { logseq.hideMainUI() if (type === 'ask ai') { askAI(inputValue, "") } else if (type === 'define') { defineWord(inputValue) } else if (type === 'ask with context') { askWithContext(inputValue) } } }, [hitEnter]) const handleInputChange = (e: any) => { const query = e.target.value; setInputValue(query); }; const handleKeyDown: KeyboardEventHandler = (e) => { if (e.key === 'Enter') { setHitEnter(true) } } return ( !hitEnter ? (
) : null ) }