blob: 7a6b361df03d6f4e7093ad1395ffd9ffd6825974 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import React, { useEffect, useRef, useState } from 'react'
import { askAI, defineWord, DivideTaskIntoSubTasks } from '../ollama';
export const PromptAI = ({ type }) => {
const placeholder = type === 'prompt' ? "Prompt..." : "Define..."
const [inputValue, setInputValue] = useState('');
const [hitEnter, setHitEnter] = useState(false)
useEffect(() => {
if (hitEnter) {
if (type === 'prompt') {
askAI(inputValue)
} else {
defineWord(inputValue)
}
}
}, [hitEnter])
const handleInputChange = (e) => {
const query = e.target.value;
setInputValue(query);
};
const handleKeyDown = (e) => {
if (e.key === 'Enter') {
setHitEnter(true)
}
}
return (
!hitEnter ? (
<div className='w-screen text-center'>
<input
autoFocus
type="text"
placeholder={placeholder}
value={inputValue}
onChange={handleInputChange}
onKeyDown={handleKeyDown}
className="bg-gray-700 text-white px-2 py-1 rounded-md dark:bg-gray-800 inline-block w-3/4"
/>
</div>
) : null
)
}
|