Skip to content

Commit 8102227

Browse files
committed
fix: stop button to work when streaming is going on and after stopping save whatever message was streamed
1 parent 367e504 commit 8102227

File tree

3 files changed

+93
-23
lines changed

3 files changed

+93
-23
lines changed

chatbot-ui/src/components/App.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,16 @@ function App() {
383383
} catch (error) {
384384
if (error instanceof Error && error.name === 'AbortError') {
385385
console.log('Stream aborted');
386-
updatedMessages.pop();
387-
updateMessagesInUI(conversationId, updatedMessages);
386+
// Instead of removing the message, just mark it as not loading
387+
const lastMessage = updatedMessages[updatedMessages.length - 1];
388+
if (lastMessage) {
389+
lastMessage.loading = false;
390+
// Only keep the message if it has content
391+
if (!lastMessage.content || (typeof lastMessage.content === 'string' && lastMessage.content.trim() === '')) {
392+
lastMessage.content = '[Message stream stopped]';
393+
}
394+
updateMessagesInUI(conversationId, updatedMessages);
395+
}
388396
} else {
389397
handleError(error as Error, 'Error during streaming');
390398
const lastMessage = updatedMessages[updatedMessages.length - 1];

chatbot-ui/src/components/MessageInput.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,26 +218,23 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(({ onSend, o
218218
<button
219219
onClick={isProcessing ? onStop : handleSend}
220220
disabled={(!input.trim() && imagePreviews.length === 0) && !isProcessing}
221+
className={isProcessing ? 'stop-button' : ''}
221222
>
222223
{isProcessing ? (
223224
<svg
224225
xmlns="http://www.w3.org/2000/svg"
225-
height="24"
226-
width="24"
227226
viewBox="0 0 24 24"
228-
fill="#FF3B30"
227+
fill="currentColor"
229228
>
230-
<path d="M19 13H5v-2h14v2z" />
229+
<rect x="7" y="7" width="10" height="10" />
231230
</svg>
232231
) : (
233232
<svg
234233
xmlns="http://www.w3.org/2000/svg"
235-
height="24"
236-
width="24"
237234
viewBox="0 0 24 24"
238-
fill="#007AFF"
235+
fill="currentColor"
239236
>
240-
<path d="M2 21l21-9L2 3v7l15 2-15 2v7z" />
237+
<path d="M20 12l-6-6v3.5c-7 1-8.5 6.5-9 11.5 2-5 6-6 9-6V19l6-7z" />
241238
</svg>
242239
)}
243240
</button>

chatbot-ui/src/styles/MessageInput.css

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
.input-container {
1616
display: flex;
1717
gap: 8px;
18-
align-items: flex-end;
18+
align-items: center;
1919
background: #fff;
2020
border: 1px solid #ddd;
2121
border-radius: 8px;
22-
padding: 8px;
22+
padding: 8px 12px;
2323
width: 100%;
2424
}
2525

@@ -79,37 +79,42 @@
7979

8080
.message-input textarea {
8181
flex: 1;
82-
padding: 10px 15px;
82+
padding: 0;
8383
font-size: 16px;
8484
resize: none;
85-
border: 1px solid #e0e0e0;
86-
border-radius: 20px;
87-
background-color: #f7f7f8;
88-
min-height: 40px;
89-
max-height: 240px;
85+
border: none;
86+
background: transparent;
87+
min-height: 24px;
88+
max-height: 200px;
9089
box-sizing: border-box;
9190
overflow: auto;
91+
line-height: 1.5;
92+
margin: 0;
9293
}
9394

9495
.message-input textarea:focus {
9596
outline: none;
96-
border-color: #007aff;
9797
}
9898

9999
.message-input button {
100-
background-color: transparent;
100+
background: none;
101101
border: none;
102-
cursor: pointer;
103102
padding: 8px;
103+
cursor: pointer;
104104
display: flex;
105105
align-items: center;
106106
justify-content: center;
107-
margin-left: 8px;
107+
border-radius: 6px;
108+
transition: background-color 0.2s ease;
108109
}
109110

110111
.message-input button:disabled {
111-
cursor: not-allowed;
112112
opacity: 0.5;
113+
cursor: not-allowed;
114+
}
115+
116+
.message-input button:not(:disabled):hover {
117+
background-color: rgba(0, 0, 0, 0.05);
113118
}
114119

115120
/* Send and Stop icons */
@@ -119,6 +124,66 @@
119124
transition: all 0.2s ease;
120125
}
121126

127+
/* Specific styles for the stop button */
128+
.message-input button.stop-button {
129+
width: 36px;
130+
height: 36px;
131+
padding: 0;
132+
border: none;
133+
border-radius: 6px;
134+
background-color: #f2f2f2;
135+
display: flex;
136+
align-items: center;
137+
justify-content: center;
138+
}
139+
140+
.message-input button.stop-button:hover {
141+
background-color: #e5e5e5;
142+
}
143+
144+
.message-input button.stop-button svg {
145+
width: 30px;
146+
height: 30px;
147+
fill: #1a1a1a;
148+
stroke: none;
149+
}
150+
151+
/* Send button styles */
152+
.message-input button:not(.stop-button):not(.upload-button) {
153+
width: 36px;
154+
height: 36px;
155+
padding: 0;
156+
display: flex;
157+
align-items: center;
158+
justify-content: center;
159+
border-radius: 6px;
160+
margin-left: 4px;
161+
}
162+
163+
.message-input button:not(.stop-button):not(.upload-button):disabled {
164+
background: none;
165+
}
166+
167+
.message-input button:not(.stop-button):not(.upload-button):not(:disabled) {
168+
background: #007AFF;
169+
color: white;
170+
}
171+
172+
.message-input button:not(.stop-button):not(.upload-button):not(:disabled):hover {
173+
background: #0056b3;
174+
}
175+
176+
.message-input button:not(.stop-button):not(.upload-button) svg {
177+
width: 16px;
178+
height: 16px;
179+
fill: currentColor;
180+
color: #d1d5db;
181+
}
182+
183+
.message-input button:not(.stop-button):not(.upload-button):not(:disabled) svg {
184+
color: white;
185+
}
186+
122187
.upload-button {
123188
background: none;
124189
border: none;

0 commit comments

Comments
 (0)