feat: add FlowChatBox #918 (#1086)

### What problem does this PR solve?

feat: add FlowChatBox #918 

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-06-06 19:29:36 +08:00
committed by GitHub
parent 6399a4fde2
commit dbdae8e83c
10 changed files with 547 additions and 14 deletions

View File

@ -9,7 +9,14 @@ import { getAuthorization } from '@/utils/authorizationUtil';
import { PaginationProps } from 'antd';
import axios from 'axios';
import { EventSourceParserStream } from 'eventsource-parser/stream';
import { useCallback, useEffect, useMemo, useState } from 'react';
import {
ChangeEventHandler,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'umi';
import { useSetModalState, useTranslate } from './commonHooks';
@ -196,3 +203,39 @@ export const useSendMessageWithSse = (
return { send, answer, done };
};
//#region chat hooks
export const useScrollToBottom = (id?: string) => {
const ref = useRef<HTMLDivElement>(null);
const scrollToBottom = useCallback(() => {
if (id) {
ref.current?.scrollIntoView({ behavior: 'instant' });
}
}, [id]);
useEffect(() => {
scrollToBottom();
}, [scrollToBottom]);
return ref;
};
export const useHandleMessageInputChange = () => {
const [value, setValue] = useState('');
const handleInputChange: ChangeEventHandler<HTMLInputElement> = (e) => {
const value = e.target.value;
const nextValue = value.replaceAll('\\n', '\n').replaceAll('\\t', '\t');
setValue(nextValue);
};
return {
handleInputChange,
value,
setValue,
};
};
// #endregion