From 166a4fa44f473da8960a3cd2fd1268e883b491ff Mon Sep 17 00:00:00 2001
From: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Date: Thu, 30 Nov 2023 10:23:57 -0500
Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20fix:=20Improve=20SSE=20?=
=?UTF-8?q?Handling=20and=20Fix=20Typo=20in=20`sendEmail`=20Template=20(#1?=
=?UTF-8?q?245)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* fix: typo for passwordReset.handlebars
* fix(useSSE): prevent unnecessary JSON.parse abort error, handle immediate abort-submit gracefully by reverting to previous state before immediate abort-submit, add showStopButton state to explicitly render disabled sendButton when message generation is cancelled, filter undefined messages and replace undefined convo for cancelHandler
---
api/server/middleware/abortMiddleware.js | 2 +-
api/server/services/AuthService.js | 2 +-
client/src/components/Chat/Input/ChatForm.tsx | 8 +++---
.../src/components/Chat/Input/StopButton.tsx | 7 +++--
client/src/hooks/useChatHelpers.ts | 4 +++
client/src/hooks/useSSE.ts | 27 ++++++++++++-------
6 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/api/server/middleware/abortMiddleware.js b/api/server/middleware/abortMiddleware.js
index 1177d71d99..ea331bcbbd 100644
--- a/api/server/middleware/abortMiddleware.js
+++ b/api/server/middleware/abortMiddleware.js
@@ -8,7 +8,7 @@ async function abortMessage(req, res) {
const { abortKey } = req.body;
if (!abortControllers.has(abortKey) && !res.headersSent) {
- return res.status(404).send('Request not found');
+ return res.status(404).send({ message: 'Request not found' });
}
const { abortController } = abortControllers.get(abortKey);
diff --git a/api/server/services/AuthService.js b/api/server/services/AuthService.js
index 06273826cc..363042a753 100644
--- a/api/server/services/AuthService.js
+++ b/api/server/services/AuthService.js
@@ -185,7 +185,7 @@ const resetPassword = async (userId, token, password) => {
{
name: user.name,
},
- 'resetPassword.handlebars',
+ 'passwordReset.handlebars',
);
await passwordResetToken.deleteOne();
diff --git a/client/src/components/Chat/Input/ChatForm.tsx b/client/src/components/Chat/Input/ChatForm.tsx
index 062b5cd60c..632944eb8e 100644
--- a/client/src/components/Chat/Input/ChatForm.tsx
+++ b/client/src/components/Chat/Input/ChatForm.tsx
@@ -19,6 +19,8 @@ export default function ChatForm({ index = 0 }) {
handleStopGenerating,
filesLoading,
setFilesLoading,
+ showStopButton,
+ setShowStopButton,
} = useChatContext();
const submitMessage = () => {
@@ -46,10 +48,10 @@ export default function ChatForm({ index = 0 }) {
endpoint={conversation?.endpoint}
/>
- {isSubmitting ? (
-
+ {isSubmitting && showStopButton ? (
+
) : (
-
+
)}
diff --git a/client/src/components/Chat/Input/StopButton.tsx b/client/src/components/Chat/Input/StopButton.tsx
index 0ce8416ffa..69303adb97 100644
--- a/client/src/components/Chat/Input/StopButton.tsx
+++ b/client/src/components/Chat/Input/StopButton.tsx
@@ -1,4 +1,4 @@
-export default function StopButton({ stop }) {
+export default function StopButton({ stop, setShowStopButton }) {
return (
@@ -7,7 +7,10 @@ export default function StopButton({ stop }) {
type="button"
className="border-gizmo-gray-950 rounded-full border-2 p-1 dark:border-gray-200"
aria-label="Stop generating"
- onClick={stop}
+ onClick={(e) => {
+ setShowStopButton(false);
+ stop(e);
+ }}
>