2025-03-04 05:25:51 +08:00
|
|
|
'use client';
|
|
|
|
|
2025-03-04 05:30:56 +08:00
|
|
|
import React from 'react';
|
2025-03-04 05:25:51 +08:00
|
|
|
import { InputTextAreaButton } from '@/components/ui/inputs/InputTextAreaButton';
|
|
|
|
import { useBusterNewChatContextSelector } from '@/context/Chats';
|
|
|
|
import { inputHasText } from '@/lib/text';
|
|
|
|
import { useMemoizedFn } from 'ahooks';
|
|
|
|
import { ChangeEvent, useMemo, useState } from 'react';
|
|
|
|
|
|
|
|
const autoResizeConfig = {
|
|
|
|
minRows: 3,
|
|
|
|
maxRows: 18
|
|
|
|
};
|
|
|
|
|
|
|
|
export const NewChatInput: React.FC<{}> = () => {
|
|
|
|
const onStartNewChat = useBusterNewChatContextSelector((state) => state.onStartNewChat);
|
|
|
|
const [inputValue, setInputValue] = useState('');
|
2025-03-04 05:30:56 +08:00
|
|
|
const [loading, setLoading] = useState(false);
|
2025-03-04 05:25:51 +08:00
|
|
|
|
|
|
|
const disabledSubmit = useMemo(() => {
|
|
|
|
return !inputHasText(inputValue);
|
|
|
|
}, [inputValue]);
|
|
|
|
|
2025-03-04 05:30:56 +08:00
|
|
|
const onSubmit = useMemoizedFn(async (value: string) => {
|
|
|
|
await onStartNewChat({ prompt: value });
|
2025-03-04 05:25:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const onChange = useMemoizedFn((e: ChangeEvent<HTMLTextAreaElement>) => {
|
|
|
|
setInputValue(e.target.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<InputTextAreaButton
|
|
|
|
placeholder="Ask Buster a question..."
|
|
|
|
autoResize={autoResizeConfig}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
onChange={onChange}
|
|
|
|
autoFocus
|
|
|
|
disabledSubmit={disabledSubmit}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|