From 92b9eceba1e52d8d2c486a1a84e94d92a9718493 Mon Sep 17 00:00:00 2001 From: an-lee Date: Wed, 31 Jan 2024 10:39:54 +0800 Subject: [PATCH] Fix conversation edit failed & Mixin login (#236) * fix redundant toast error * fix Mixin login failed on occasions * fix conversation form default values --- .../conversations/conversation-form.tsx | 20 +++++++++++++------ enjoy/src/renderer/components/login-form.tsx | 7 +------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/enjoy/src/renderer/components/conversations/conversation-form.tsx b/enjoy/src/renderer/components/conversations/conversation-form.tsx index 5b587ed5..7bffe8c0 100644 --- a/enjoy/src/renderer/components/conversations/conversation-form.tsx +++ b/enjoy/src/renderer/components/conversations/conversation-form.tsx @@ -100,14 +100,22 @@ export const ConversationForm = (props: { refreshProviders(); }, []); - const defaultConfig = conversation || {}; - + const defaultConfig = JSON.parse(JSON.stringify(conversation || {})); if (defaultConfig.engine === "openai" && openai) { - defaultConfig.configuration.model = openai.model; - defaultConfig.configuration.baseUrl = openai.baseUrl; + if (!defaultConfig.configuration) { + defaultConfig.configuration = {}; + } + if (!defaultConfig.configuration.model) { + defaultConfig.configuration.model = openai.model; + } + if (!defaultConfig.configuration.baseUrl) { + defaultConfig.configuration.baseUrl = openai.baseUrl; + } } - if (defaultConfig.configuration?.tts?.engine === "openai" && openai) { - defaultConfig.configuration.tts.baseUrl = openai.baseUrl; + if (defaultConfig.configuration.tts.engine === "openai" && openai) { + if (!defaultConfig.configuration.tts.baseUrl) { + defaultConfig.configuration.tts.baseUrl = openai.baseUrl; + } } const form = useForm>({ diff --git a/enjoy/src/renderer/components/login-form.tsx b/enjoy/src/renderer/components/login-form.tsx index 2bafa422..aa260799 100644 --- a/enjoy/src/renderer/components/login-form.tsx +++ b/enjoy/src/renderer/components/login-form.tsx @@ -67,6 +67,7 @@ export const LoginForm = () => { const code = new URL(url).searchParams.get("code"); if (provider && code) { + setWebviewVisible(false); webApi .auth({ provider, code }) .then((user) => { @@ -74,13 +75,7 @@ export const LoginForm = () => { }) .catch((err) => { toast.error(err.message); - }) - .finally(() => { - setWebviewVisible(false); }); - } else { - toast.error(t("failedToLogin")); - setWebviewVisible(false); } } };