Skip to content

Commit 30df5c0

Browse files
authored
Merge pull request #173 from capdiem/feature/chat-input-improve
feat(ChatInput): add cancel button during chat sessions
2 parents 2980b53 + 88cd158 commit 30df5c0

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

web/app/chat/components/ChatInput.tsx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React, { useState, useRef } from 'react';
44
import { Button, Upload, message, Tooltip } from 'antd';
5-
import { LoadingOutlined, CloseCircleFilled } from '@ant-design/icons';
5+
import { LoadingOutlined, CloseCircleFilled, CloseCircleOutlined } from '@ant-design/icons';
66
import { createStyles } from 'antd-style';
77
import type { UploadProps } from 'antd';
88
import { ActionIcon } from '@lobehub/ui';
@@ -35,21 +35,21 @@ const useStyles = createStyles(({ css, token }) => ({
3535
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
3636
border: 1px solid ${token.colorBorderSecondary};
3737
transition: transform 0.2s ease;
38-
38+
3939
&:hover {
4040
transform: scale(1.02);
41-
41+
4242
.remove-button {
4343
opacity: 1;
4444
}
4545
}
46-
46+
4747
img {
4848
width: 100%;
4949
height: 100%;
5050
object-fit: cover;
5151
}
52-
52+
5353
.remove-button {
5454
position: absolute;
5555
top: 4px;
@@ -65,7 +65,7 @@ const useStyles = createStyles(({ css, token }) => ({
6565
cursor: pointer;
6666
opacity: 0.7;
6767
transition: all 0.2s ease;
68-
68+
6969
&:hover {
7070
background: rgba(0, 0, 0, 0.8);
7171
opacity: 1;
@@ -81,13 +81,13 @@ const useStyles = createStyles(({ css, token }) => ({
8181
padding: ${token.paddingSM}px ${token.paddingMD}px;
8282
border-color: ${token.colorBorderSecondary};
8383
transition: all 0.3s;
84-
84+
8585
&:hover, &:focus {
8686
border-color: ${token.colorPrimary};
8787
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
8888
}
8989
}
90-
90+
9191
.ant-btn {
9292
border-radius: ${token.borderRadiusLG}px;
9393
}
@@ -251,11 +251,15 @@ const ChatInput: React.FC<ChatInputProps> = ({
251251
onSend={handleSend}
252252
disabled={disabled}
253253
loading={loading}
254-
textAreaRightAddons={<ChatInputArea.SendButton
255-
icon={<ArrowUp />}
256-
onSend={handleSend}
257-
onStop={handleStop}
258-
/>}
254+
textAreaRightAddons={
255+
<ChatInputArea.SendButton
256+
disabled={imageUploading || disabled}
257+
loading={loading}
258+
icon={<ArrowUp />}
259+
onSend={handleSend}
260+
onStop={handleStop}
261+
/>
262+
}
259263
topAddons={
260264
<ChatInputActionBar
261265
leftAddons={
@@ -284,9 +288,8 @@ const ChatInput: React.FC<ChatInputProps> = ({
284288
<Tooltip title="清空消息">
285289
<ActionIcon
286290
className={styles.actionButton}
287-
style={{
291+
style={{
288292
marginLeft: 'auto',
289-
marginRight: '20px',
290293
color: 'red',
291294
}}
292295
icon={<Trash2
@@ -295,6 +298,16 @@ const ChatInput: React.FC<ChatInputProps> = ({
295298
onClick={onClear}
296299
/>
297300
</Tooltip>
301+
{loading && (
302+
<Tooltip title="停止生成">
303+
<ActionIcon
304+
className={styles.actionButton}
305+
style={{ color: 'grey' }}
306+
icon={<CloseCircleOutlined />}
307+
onClick={handleStop}
308+
/>
309+
</Tooltip>
310+
)}
298311
</>
299312
}
300313
/>

web/app/chat/workspace/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ export default function Workspace({ organizationName, name }: WorkspaceProps) {
351351

352352
const handleStopGeneration = () => {
353353
abortControllerRef.current?.abort();
354+
setIsLoading(false);
354355
}
355356

356357

web/next.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
33
output: 'standalone',
4-
reactStrictMode: true,
4+
reactStrictMode: true,
55
transpilePackages: ['antd','@ant-design/icons'],
66
// CSS配置
77
experimental: {
@@ -27,11 +27,11 @@ const nextConfig = {
2727
});
2828
}
2929
});
30-
30+
3131
return config;
3232
},
3333
async rewrites() {
34-
const apiUrl = 'http://localhost:50323/'
34+
const apiUrl = 'http://localhost:5085/'
3535

3636
// 如果NEXT_PUBLIC_API_URL环境变量有值则使用
3737
if (process.env?.NEXT_PUBLIC_API_URL) {

0 commit comments

Comments
 (0)