mirror of https://github.com/buster-so/buster.git
on select items submit
This commit is contained in:
parent
ba9155a9af
commit
8a4a056603
|
@ -104,6 +104,10 @@ export const BusterChatInputBase: React.FC<BusterChatInputProps> = React.memo(
|
|||
onSubmit({ ...value, mode });
|
||||
};
|
||||
|
||||
const onSuggestionItemClick = useMemoizedFn(() => {
|
||||
onSubmitPreflight();
|
||||
});
|
||||
|
||||
const onCloseCreateShortcutModal = useMemoizedFn(() => {
|
||||
setOpenCreateShortcutModal(false);
|
||||
});
|
||||
|
@ -123,6 +127,7 @@ export const BusterChatInputBase: React.FC<BusterChatInputProps> = React.memo(
|
|||
<MentionInputSuggestions
|
||||
defaultValue={defaultValue}
|
||||
onPressEnter={onSubmitPreflight}
|
||||
onSuggestionItemClick={onSuggestionItemClick}
|
||||
mentions={mentions}
|
||||
suggestionItems={suggestionItems}
|
||||
disabled={disabled}
|
||||
|
|
|
@ -66,6 +66,12 @@ export const MentionInputSuggestions = forwardRef<
|
|||
? !hasClickedSelect && suggestionItems.length > 0
|
||||
: isInteracting && suggestionItems.length > 0;
|
||||
|
||||
// biome-ignore lint/style/noNonNullAssertion: we know the ref is not null
|
||||
const getValue = mentionsInputRef.current?.getValue!;
|
||||
// biome-ignore lint/style/noNonNullAssertion: we know the ref is not null
|
||||
const addMentionToInput = mentionsInputRef.current?.addMentionToInput!;
|
||||
const mounted = useMounted();
|
||||
|
||||
const onChangeInputValue: MentionInputProps['onChange'] = useCallback(
|
||||
(d) => {
|
||||
const { transformedValue } = d;
|
||||
|
@ -95,7 +101,6 @@ export const MentionInputSuggestions = forwardRef<
|
|||
const onSelectItem = useMemoizedFn(
|
||||
({ onClick, ...params }: MentionInputSuggestionsOnSelectParams) => {
|
||||
const { addValueToInput, loading, label, disabled, inputValue } = params;
|
||||
console.log('onSelectItem', params);
|
||||
if (disabled) {
|
||||
console.warn('Item is disabled', params);
|
||||
return;
|
||||
|
@ -114,17 +119,12 @@ export const MentionInputSuggestions = forwardRef<
|
|||
setValue(stringValue);
|
||||
}
|
||||
onClick?.();
|
||||
if (closeSuggestionOnSelect && params.closeOnSelect !== false) setHasClickedSelect(true);
|
||||
onSuggestionItemClick?.(params);
|
||||
|
||||
if (closeSuggestionOnSelect && params.closeOnSelect !== false) setHasClickedSelect(true);
|
||||
}
|
||||
);
|
||||
|
||||
// biome-ignore lint/style/noNonNullAssertion: we know the ref is not null
|
||||
const getValue = mentionsInputRef.current?.getValue!;
|
||||
// biome-ignore lint/style/noNonNullAssertion: we know the ref is not null
|
||||
const addMentionToInput = mentionsInputRef.current?.addMentionToInput!;
|
||||
const mounted = useMounted();
|
||||
|
||||
const onBlur = useMemoizedFn(() => {
|
||||
setIsInteracting(false);
|
||||
});
|
||||
|
|
|
@ -30,6 +30,19 @@ export const MentionInputSuggestionsItem = ({
|
|||
style,
|
||||
popoverContent,
|
||||
}: MentionInputSuggestionsItemProps) => {
|
||||
const onSelectItem = () => {
|
||||
onSelect({
|
||||
value,
|
||||
inputValue,
|
||||
label,
|
||||
onClick,
|
||||
addValueToInput,
|
||||
closeOnSelect,
|
||||
disabled,
|
||||
loading,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<PopoverContentWrapper popoverContent={popoverContent}>
|
||||
<Command.Item
|
||||
|
@ -42,17 +55,11 @@ export const MentionInputSuggestionsItem = ({
|
|||
value={value}
|
||||
data-testid={`type-${type}-value-${value}`}
|
||||
style={style}
|
||||
onMouseDown={() => {
|
||||
onSelectItem();
|
||||
}}
|
||||
onSelect={() => {
|
||||
onSelect({
|
||||
value,
|
||||
inputValue,
|
||||
label,
|
||||
onClick,
|
||||
addValueToInput,
|
||||
closeOnSelect,
|
||||
disabled,
|
||||
loading,
|
||||
});
|
||||
onSelectItem();
|
||||
}}
|
||||
>
|
||||
{icon && (
|
||||
|
|
|
@ -6,6 +6,7 @@ import { useGetChatMemoized, useGetChatMessageMemoized } from '@/api/buster_rest
|
|||
import { useStartNewChat, useStopChat } from '@/api/buster_rest/chats/queryRequestsV2';
|
||||
import { useChatUpdate } from '@/api/buster_rest/chats/useChatUpdate';
|
||||
import { useMemoizedFn } from '@/hooks/useMemoizedFn';
|
||||
import { timeout } from '@/lib/timeout';
|
||||
|
||||
type StartChatParams = {
|
||||
prompt: string | undefined;
|
||||
|
@ -46,11 +47,13 @@ export const useChat = () => {
|
|||
|
||||
const hasMultipleMessages = message_ids.length > 1;
|
||||
if (!hasMultipleMessages) {
|
||||
navigate({
|
||||
await navigate({
|
||||
to: '/app/chats/$chatId',
|
||||
params: { chatId: id },
|
||||
});
|
||||
}
|
||||
|
||||
await timeout(500);
|
||||
};
|
||||
|
||||
const onStartNewChat = useMemoizedFn(
|
||||
|
|
Loading…
Reference in New Issue