Skip to content

Commit d99b35b

Browse files
authored
fix: prevent duplicate login success messages (#977)
* fix: prevent duplicate login success messages * refactor: i18n * refactor: update * docs: update changelog
1 parent 594d0ff commit d99b35b

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fix: fix page rapidly flickering issue #935
3737
fix(view extension): broken search bar UI when opening extensions via hotkey #938
3838
fix: allow deletion after selecting all text #943
3939
fix: prevent shaking when switching between chat and search pages #955
40+
fix: prevent duplicate login success messages #977
4041

4142
### ✈️ Improvements
4243

src/components/Cloud/ServiceAuth.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FC, memo, useCallback, useEffect, useState } from "react";
22
import { Copy } from "lucide-react";
33
import { useTranslation } from "react-i18next";
44
import { v4 as uuidv4 } from "uuid";
5+
import { useDebounceFn } from "ahooks";
56

67
import { UserProfile } from "./UserProfile";
78
import { OpenURLWithBrowser } from "@/utils";
@@ -20,7 +21,6 @@ const ServiceAuth = memo(
2021
({ setRefreshLoading, refreshClick }: ServiceAuthProps) => {
2122
const { t } = useTranslation();
2223

23-
const language = useAppStore((state) => state.language);
2424
const addError = useAppStore((state) => state.addError);
2525
const ssoRequestID = useAppStore((state) => state.ssoRequestID);
2626
const setSSORequestID = useAppStore((state) => state.setSSORequestID);
@@ -61,19 +61,21 @@ const ServiceAuth = memo(
6161
[logoutServer]
6262
);
6363

64+
const { run: debouncedAuthSuccess } = useDebounceFn((event) => {
65+
const { serverId } = event.payload;
66+
if (serverId) {
67+
refreshClick(serverId, () => {
68+
setLoading(false);
69+
});
70+
addError(t("cloud.connect.hints.loginSuccess"), "info");
71+
}
72+
});
73+
6474
// handle oauth success event
6575
useEffect(() => {
6676
const unlistenOAuth = platformAdapter.listenEvent(
6777
"oauth_success",
68-
(event) => {
69-
const { serverId } = event.payload;
70-
if (serverId) {
71-
refreshClick(serverId, () => {
72-
setLoading(false);
73-
});
74-
addError(language === "zh" ? "登录成功" : "Login Success", "info");
75-
}
76-
}
78+
debouncedAuthSuccess
7779
);
7880

7981
return () => {

src/locales/en/translation.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,10 @@
494494
"serverPlaceholder": "For example: https://coco.infini.cloud/",
495495
"connecting": "Connecting...",
496496
"connect": "Connect",
497-
"closeError": "Close error message"
497+
"closeError": "Close error message",
498+
"hints": {
499+
"loginSuccess": "Login Successful"
500+
}
498501
},
499502
"dataSource": {
500503
"title": "Data Source",

src/locales/zh/translation.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,10 @@
494494
"serverPlaceholder": "例如:https://coco.infini.cloud/",
495495
"connecting": "连接中...",
496496
"connect": "连接",
497-
"closeError": "关闭错误提示"
497+
"closeError": "关闭错误提示",
498+
"hints": {
499+
"loginSuccess": "登录成功"
500+
}
498501
},
499502
"dataSource": {
500503
"title": "数据源",

0 commit comments

Comments
 (0)