Commit
·
985fa34
1
Parent(s):
2adbd33
Optimized the chat interface (including the chat API after sharing) (#1215)
Browse files### What problem does this PR solve?
Optimized the chat interface (including the chat API after sharing)
1. Change the background color of the dialog box between the assistant
and the user (use the theme color of the interface)
2. Add rounded corners to the dialog box
3. When the input box is empty, you can't click the send button(because
some models will report an error when sending empty data)
Color reference(can be a bit subjective):

### Type of change
- [x] Refactor
Co-authored-by: 海贼宅 <[email protected]>
web/src/pages/chat/chat-container/index.less
CHANGED
@@ -27,8 +27,18 @@
|
|
27 |
.messageText {
|
28 |
.chunkText();
|
29 |
padding: 0 14px;
|
30 |
-
background-color:
|
31 |
word-break: break-all;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
.messageEmpty {
|
34 |
width: 300px;
|
|
|
27 |
.messageText {
|
28 |
.chunkText();
|
29 |
padding: 0 14px;
|
30 |
+
background-color: rgb(230, 230, 232);
|
31 |
word-break: break-all;
|
32 |
+
border-radius: 10px;
|
33 |
+
}
|
34 |
+
.messageUserText {
|
35 |
+
.chunkText();
|
36 |
+
padding: 0 14px;
|
37 |
+
background-color: rgb(45, 100, 245);
|
38 |
+
word-break: break-all;
|
39 |
+
border-radius: 10px;
|
40 |
+
color: #fdfdfd;
|
41 |
+
text-align: justify;
|
42 |
}
|
43 |
.messageEmpty {
|
44 |
width: 300px;
|
web/src/pages/chat/chat-container/index.tsx
CHANGED
@@ -14,7 +14,7 @@ import {
|
|
14 |
useFetchConversationOnMount,
|
15 |
useGetFileIcon,
|
16 |
useGetSendButtonDisabled,
|
17 |
-
useSelectConversationLoading,
|
18 |
useSendMessage,
|
19 |
} from '../hooks';
|
20 |
import MarkdownContent from '../markdown-content';
|
@@ -87,7 +87,7 @@ const MessageItem = ({
|
|
87 |
)}
|
88 |
<Flex vertical gap={8} flex={1}>
|
89 |
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
90 |
-
<div className={styles.messageText}>
|
91 |
<MarkdownContent
|
92 |
content={content}
|
93 |
reference={reference}
|
@@ -157,6 +157,7 @@ const ChatContainer = () => {
|
|
157 |
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
|
158 |
useClickDrawer();
|
159 |
const disabled = useGetSendButtonDisabled();
|
|
|
160 |
useGetFileIcon();
|
161 |
const loading = useSelectConversationLoading();
|
162 |
const { t } = useTranslate('chat');
|
@@ -196,7 +197,7 @@ const ChatContainer = () => {
|
|
196 |
type="primary"
|
197 |
onClick={handlePressEnter}
|
198 |
loading={sendLoading}
|
199 |
-
disabled={
|
200 |
>
|
201 |
{t('send')}
|
202 |
</Button>
|
|
|
14 |
useFetchConversationOnMount,
|
15 |
useGetFileIcon,
|
16 |
useGetSendButtonDisabled,
|
17 |
+
useSelectConversationLoading, useSendButtonDisabled,
|
18 |
useSendMessage,
|
19 |
} from '../hooks';
|
20 |
import MarkdownContent from '../markdown-content';
|
|
|
87 |
)}
|
88 |
<Flex vertical gap={8} flex={1}>
|
89 |
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
90 |
+
<div className={isAssistant ? styles.messageText : styles.messageUserText}>
|
91 |
<MarkdownContent
|
92 |
content={content}
|
93 |
reference={reference}
|
|
|
157 |
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
|
158 |
useClickDrawer();
|
159 |
const disabled = useGetSendButtonDisabled();
|
160 |
+
const sendDisabled = useSendButtonDisabled(value);
|
161 |
useGetFileIcon();
|
162 |
const loading = useSelectConversationLoading();
|
163 |
const { t } = useTranslate('chat');
|
|
|
197 |
type="primary"
|
198 |
onClick={handlePressEnter}
|
199 |
loading={sendLoading}
|
200 |
+
disabled={sendDisabled}
|
201 |
>
|
202 |
{t('send')}
|
203 |
</Button>
|
web/src/pages/chat/hooks.ts
CHANGED
@@ -54,6 +54,7 @@ import {
|
|
54 |
} from './interface';
|
55 |
import { ChatModelState } from './model';
|
56 |
import { isConversationIdExist } from './utils';
|
|
|
57 |
|
58 |
export const useSelectCurrentDialog = () => {
|
59 |
const currentDialog: IDialog = useSelector(
|
@@ -630,6 +631,7 @@ export const useSendMessage = (
|
|
630 |
handlePressEnter,
|
631 |
handleInputChange,
|
632 |
value,
|
|
|
633 |
loading: !done,
|
634 |
};
|
635 |
};
|
@@ -762,6 +764,10 @@ export const useGetSendButtonDisabled = () => {
|
|
762 |
|
763 |
return dialogId === '' && conversationId === '';
|
764 |
};
|
|
|
|
|
|
|
|
|
765 |
//#endregion
|
766 |
|
767 |
//#region API provided for external calls
|
|
|
54 |
} from './interface';
|
55 |
import { ChatModelState } from './model';
|
56 |
import { isConversationIdExist } from './utils';
|
57 |
+
import {public_path} from "@/utils/api";
|
58 |
|
59 |
export const useSelectCurrentDialog = () => {
|
60 |
const currentDialog: IDialog = useSelector(
|
|
|
631 |
handlePressEnter,
|
632 |
handleInputChange,
|
633 |
value,
|
634 |
+
setValue,
|
635 |
loading: !done,
|
636 |
};
|
637 |
};
|
|
|
764 |
|
765 |
return dialogId === '' && conversationId === '';
|
766 |
};
|
767 |
+
|
768 |
+
export const useSendButtonDisabled = (value: string) => {
|
769 |
+
return value === '';
|
770 |
+
};
|
771 |
//#endregion
|
772 |
|
773 |
//#region API provided for external calls
|
web/src/pages/chat/share/index.less
CHANGED
@@ -33,8 +33,18 @@
|
|
33 |
.messageText {
|
34 |
.chunkText();
|
35 |
padding: 0 14px;
|
36 |
-
background-color:
|
37 |
word-break: break-all;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
.messageEmpty {
|
40 |
width: 300px;
|
|
|
33 |
.messageText {
|
34 |
.chunkText();
|
35 |
padding: 0 14px;
|
36 |
+
background-color: rgb(230, 230, 232);
|
37 |
word-break: break-all;
|
38 |
+
border-radius: 10px;
|
39 |
+
}
|
40 |
+
.messageUserText {
|
41 |
+
.chunkText();
|
42 |
+
padding: 0 14px;
|
43 |
+
background-color: rgb(45, 100, 245);
|
44 |
+
word-break: break-all;
|
45 |
+
border-radius: 10px;
|
46 |
+
color: #fdfdfd;
|
47 |
+
text-align: justify;
|
48 |
}
|
49 |
.messageEmpty {
|
50 |
width: 300px;
|
web/src/pages/chat/share/large.tsx
CHANGED
@@ -19,6 +19,7 @@ import {
|
|
19 |
} from '../shared-hooks';
|
20 |
import { buildMessageItemReference } from '../utils';
|
21 |
import styles from './index.less';
|
|
|
22 |
|
23 |
const MessageItem = ({
|
24 |
item,
|
@@ -76,7 +77,7 @@ const MessageItem = ({
|
|
76 |
)}
|
77 |
<Flex vertical gap={8} flex={1}>
|
78 |
<b>{isAssistant ? '' : 'You'}</b>
|
79 |
-
<div className={styles.messageText}>
|
80 |
<MarkdownContent
|
81 |
reference={reference}
|
82 |
clickDocumentButton={() => {}}
|
@@ -149,6 +150,7 @@ const ChatContainer = () => {
|
|
149 |
setCurrentConversation,
|
150 |
addNewestAnswer,
|
151 |
);
|
|
|
152 |
|
153 |
return (
|
154 |
<>
|
@@ -184,7 +186,7 @@ const ChatContainer = () => {
|
|
184 |
type="primary"
|
185 |
onClick={handlePressEnter}
|
186 |
loading={sendLoading}
|
187 |
-
|
188 |
>
|
189 |
{t('send')}
|
190 |
</Button>
|
|
|
19 |
} from '../shared-hooks';
|
20 |
import { buildMessageItemReference } from '../utils';
|
21 |
import styles from './index.less';
|
22 |
+
import {useSendButtonDisabled} from "@/pages/chat/hooks";
|
23 |
|
24 |
const MessageItem = ({
|
25 |
item,
|
|
|
77 |
)}
|
78 |
<Flex vertical gap={8} flex={1}>
|
79 |
<b>{isAssistant ? '' : 'You'}</b>
|
80 |
+
<div className={isAssistant ? styles.messageText : styles.messageUserText}>
|
81 |
<MarkdownContent
|
82 |
reference={reference}
|
83 |
clickDocumentButton={() => {}}
|
|
|
150 |
setCurrentConversation,
|
151 |
addNewestAnswer,
|
152 |
);
|
153 |
+
const sendDisabled = useSendButtonDisabled(value);
|
154 |
|
155 |
return (
|
156 |
<>
|
|
|
186 |
type="primary"
|
187 |
onClick={handlePressEnter}
|
188 |
loading={sendLoading}
|
189 |
+
disabled={sendDisabled}
|
190 |
>
|
191 |
{t('send')}
|
192 |
</Button>
|
web/src/pages/chat/shared-hooks.ts
CHANGED
@@ -133,6 +133,10 @@ export const useSelectCurrentSharedConversation = (conversationId: string) => {
|
|
133 |
};
|
134 |
};
|
135 |
|
|
|
|
|
|
|
|
|
136 |
export const useSendSharedMessage = (
|
137 |
conversation: IClientConversation,
|
138 |
addNewestConversation: (message: string) => void,
|
|
|
133 |
};
|
134 |
};
|
135 |
|
136 |
+
export const useSendButtonDisabled = (value: string) => {
|
137 |
+
return value === '';
|
138 |
+
};
|
139 |
+
|
140 |
export const useSendSharedMessage = (
|
141 |
conversation: IClientConversation,
|
142 |
addNewestConversation: (message: string) => void,
|