feat(message-input): prevent message when loading

This commit is contained in:
ItzCrazyKns 2024-04-24 10:06:56 +05:30
parent 571cdc1b4e
commit 3b66808e7d
No known key found for this signature in database
GPG Key ID: 8162927C7CCE3065
3 changed files with 9 additions and 6 deletions

View File

@ -77,7 +77,7 @@ const Chat = ({
className="bottom-24 lg:bottom-10 fixed z-40"
style={{ width: dividerWidth }}
>
<MessageInput sendMessage={sendMessage} />
<MessageInput loading={loading} sendMessage={sendMessage} />
</div>
)}
</div>

View File

@ -6,8 +6,10 @@ import { Attach, CopilotToggle } from './MessageInputActions';
const MessageInput = ({
sendMessage,
loading,
}: {
sendMessage: (message: string) => void;
loading: boolean;
}) => {
const [copilotEnabled, setCopilotEnabled] = useState(false);
const [message, setMessage] = useState('');
@ -25,12 +27,13 @@ const MessageInput = ({
return (
<form
onSubmit={(e) => {
if (loading) return;
e.preventDefault();
sendMessage(message);
setMessage('');
}}
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey) {
if (e.key === 'Enter' && !e.shiftKey && !loading) {
e.preventDefault();
sendMessage(message);
setMessage('');
@ -58,7 +61,7 @@ const MessageInput = ({
setCopilotEnabled={setCopilotEnabled}
/>
<button
disabled={message.trim().length === 0}
disabled={message.trim().length === 0 || loading}
className="bg-[#24A0ED] text-white disabled:text-white/50 hover:bg-opacity-85 transition duration-100 disabled:bg-[#ececec21] rounded-full p-2"
>
<ArrowUp className="bg-background" size={17} />
@ -74,7 +77,7 @@ const MessageInput = ({
setCopilotEnabled={setCopilotEnabled}
/>
<button
disabled={message.trim().length === 0}
disabled={message.trim().length === 0 || loading}
className="bg-[#24A0ED] text-white disabled:text-white/50 hover:bg-opacity-85 transition duration-100 disabled:bg-[#ececec21] rounded-full p-2"
>
<ArrowUp className="bg-background" size={17} />

View File

@ -168,7 +168,7 @@ const SettingsDialog = ({
<p className="text-white/70 text-sm">OpenAI API Key</p>
<input
type="text"
placeholder='OpenAI API Key'
placeholder="OpenAI API Key"
defaultValue={config.openeaiApiKey}
onChange={(e) =>
setConfig({
@ -183,7 +183,7 @@ const SettingsDialog = ({
<p className="text-white/70 text-sm">Ollama API URL</p>
<input
type="text"
placeholder='Ollama API URL'
placeholder="Ollama API URL"
defaultValue={config.ollamaApiUrl}
onChange={(e) =>
setConfig({