Skip to content

Commit d285887

Browse files
RonnyChan96wuayee
andauthored
[frontend] solve the problem of abnormal display when clicking to stop the conversation. (#497)
Co-authored-by: wuayee <lixin_33@noreply.gitcode.com>
1 parent 0ed7bbf commit d285887

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

frontend/src/pages/chatPreview/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ import CheckGroup from './components/check-group';
6161
import Inspiration from './components/inspiration';
6262
import PreviewPicture from './components/receive-box/preview-picture';
6363
import './styles/chat-preview.scss';
64+
import store from '@/store/store';
65+
import {setIsCurrentAnswer} from "@/store/chatStore/chatStore";
6466

6567
/**
6668
* 应用聊天对话页面
@@ -92,6 +94,7 @@ const ChatPreview = (props) => {
9294
const isDebug = useAppSelector((state) => state.commonStore.isDebug);
9395
const isGuest = useAppSelector((state) => state.appStore.isGuest);
9496
const currentAnswer = useAppSelector((state) => state.chatCommonStore.currentAnswer);
97+
const isCurrentAnswer = useAppSelector((state) => state.chatCommonStore.isCurrentAnswer);
9598
const { showElsa } = useContext(AippContext);
9699
const [checkedList, setCheckedList] = useState([]);
97100
const [loading, setLoading] = useState(false);
@@ -586,6 +589,7 @@ const ChatPreview = (props) => {
586589
let { content } = currentChatItem;
587590
str = content + msg;
588591
item.content = str;
592+
store.dispatch(setIsCurrentAnswer(true));
589593
if (status === 'ARCHIVED') {
590594
item.finished = true;
591595
}
@@ -646,8 +650,8 @@ const ChatPreview = (props) => {
646650
// 终止进行中的对话
647651
async function chatRunningStop(params) {
648652
let terminateParams: any = {};
649-
terminateParams.content = params.content ? params.content : currentAnswer ? currentAnswer :
650-
t('conversationTerminated');
653+
terminateParams.content = params.content ? params.content : currentAnswer ?
654+
parseCurrentAnswer(currentAnswer) : t('conversationTerminated');
651655
if (params.logId) {
652656
terminateParams.logId = params.logId;
653657
}
@@ -671,6 +675,14 @@ const ChatPreview = (props) => {
671675
}
672676
}
673677

678+
function parseCurrentAnswer(currentAnswer) {
679+
if (currentAnswer && currentAnswer.props && currentAnswer.props.dangerouslySetInnerHTML
680+
&& isCurrentAnswer == true) {
681+
store.dispatch(setIsCurrentAnswer(false));
682+
return currentAnswer.props.dangerouslySetInnerHTML.__html;
683+
}
684+
}
685+
674686
// 表单重新对话
675687
function questionClarConfirm(params, instanceId) {
676688
queryInstance(params, 'clar', instanceId);

frontend/src/store/chatStore/action-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export const SET_READ_ONLY = 'SET_READ_ONLY';
1414
export const SET_NO_AUTH = 'SET_NO_AUTH';
1515
export const SET_PLUGIN_LIST = 'SET_PLUGIN_LIST';
1616
export const SET_CURRENT_ANSWER = 'SET_CURRENT_ANSWER';
17+
export const SET_IS_CURRENT_ANSWER = 'SET_IS_CURRENT_ANSWER';

frontend/src/store/chatStore/chatStore.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
SET_NO_AUTH,
1515
SET_USER_ROLE,
1616
SET_PLUGIN_LIST,
17-
SET_CURRENT_ANSWER
17+
SET_CURRENT_ANSWER,
18+
SET_KNOWLEDGE_CONFIG,
19+
SET_SHOW_CHAT_HISTORY,
20+
SET_IS_CURRENT_ANSWER
1821
} from './action-types';
1922

2023
export const setChatId = (item) => {
@@ -65,3 +68,12 @@ export const setPluginList = (item) => {
6568
export const setCurrentAnswer = (item) => {
6669
return { type: SET_CURRENT_ANSWER, payload: item }
6770
}
71+
export const setIsCurrentAnswer = (item) => {
72+
return { type: SET_IS_CURRENT_ANSWER, payload: item }
73+
}
74+
export const setKnowledgeConfig = (item) => {
75+
return { type: SET_KNOWLEDGE_CONFIG, payload: item }
76+
}
77+
export const setShowChatHistory = (item) => {
78+
return { type: SET_SHOW_CHAT_HISTORY, payload: item }
79+
}

frontend/src/store/chatStore/reducer.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
SET_READ_ONLY,
1515
SET_NO_AUTH,
1616
SET_PLUGIN_LIST,
17-
SET_CURRENT_ANSWER
17+
SET_CURRENT_ANSWER,
18+
SET_KNOWLEDGE_CONFIG,
19+
SET_SHOW_CHAT_HISTORY,
20+
SET_IS_CURRENT_ANSWER
1821
} from './action-types';
1922

2023
const initialState = {
@@ -33,7 +36,10 @@ const initialState = {
3336
readOnly: false,
3437
noAuth: false,
3538
pluginList: [],
36-
currentAnswer: ''
39+
currentAnswer: '',
40+
knowledgeConfig: null,
41+
showChatHistory: false,
42+
isCurrentAnswer: false
3743
}
3844

3945
const chatReducers = (state = initialState, action) => {
@@ -70,6 +76,12 @@ const chatReducers = (state = initialState, action) => {
7076
return { ...state, pluginList: action.payload };
7177
case SET_CURRENT_ANSWER:
7278
return { ...state, currentAnswer: action.payload };
79+
case SET_IS_CURRENT_ANSWER:
80+
return { ...state, isCurrentAnswer: action.payload };
81+
case SET_KNOWLEDGE_CONFIG:
82+
return { ...state, knowledgeConfig: action.payload };
83+
case SET_SHOW_CHAT_HISTORY:
84+
return { ...state, showChatHistory: action.payload };
7385
default:
7486
return state
7587
}

0 commit comments

Comments
 (0)