Skip to content

Commit 3ed84c2

Browse files
authored
fix: web component login state (#857)
* fix: web component login state * docs: update notes * build: build error
1 parent bd03939 commit 3ed84c2

File tree

8 files changed

+7
-96
lines changed

8 files changed

+7
-96
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Information about release notes of Coco App is provided here.
2222
### 🐛 Bug fix
2323

2424
- fix: fix issue with update check failure #833
25+
- fix: web component login state #857
2526

2627
### ✈️ Improvements
2728

src/components/Assistant/Chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ const ChatAI = memo(
390390
assistantIDs={assistantIDs}
391391
/>
392392

393-
{isCurrentLogin ? (
393+
{isCurrentLogin || !isTauri ? (
394394
<>
395395
<ChatContent
396396
activeChat={activeChat}

src/components/SearchChat/index.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { isLinux, isWin } from "@/utils/platform";
2121
import { appReducer, initialAppState } from "@/reducers/appReducer";
2222
import { useWindowEvents } from "@/hooks/useWindowEvents";
2323
import { useAppStore } from "@/stores/appStore";
24-
import { useAuthStore } from "@/stores/authStore";
2524
import platformAdapter from "@/utils/platformAdapter";
2625
import { useStartupStore } from "@/stores/startupStore";
2726
import { useThemeStore } from "@/stores/themeStore";
@@ -108,10 +107,6 @@ function SearchChat({
108107

109108
useWindowEvents();
110109

111-
const initializeListeners_auth = useAuthStore((state) => {
112-
return state.initializeListeners;
113-
});
114-
115110
const setTheme = useThemeStore((state) => state.setTheme);
116111
const setIsDark = useThemeStore((state) => state.setIsDark);
117112

@@ -128,7 +123,6 @@ function SearchChat({
128123

129124
useEffect(() => {
130125
const init = async () => {
131-
await initializeListeners_auth();
132126
if (isTauri) {
133127
await platformAdapter.commands("get_app_search_source");
134128
}

src/components/Settings/GeneralSettings.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ export default function GeneralSettings() {
167167
};
168168

169169
// const clearAllCache = useCallback(() => {
170-
// setAuth(undefined, endpoint);
171-
// setUserInfo({}, endpoint);
172170

173171
// useConnectStore.persist.clearStorage();
174172

src/locales/en/translation.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@
407407
"error": "Request error. Please try again later.",
408408
"logo_alt": "Login Logo",
409409
"welcome": "Welcome to Coco AI",
410-
"connect_tip": "To start a conversation, please connect to the service and log in to your account.",
411-
"connect": "Connect"
410+
"connect_tip": "To start a conversation, please log in to your account.",
411+
"connect": "Login"
412412
},
413413
"input": {
414414
"stopMessage": "Stop message",

src/locales/zh/translation.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@
407407
"error": "请求错误,请稍后再试。",
408408
"logo_alt": "登录图标",
409409
"welcome": "欢迎使用 Coco AI",
410-
"connect_tip": "要开始对话,请连接服务并登录您的账户",
411-
"connect": "连接"
410+
"connect_tip": "要开始对话,请登录您的账户",
411+
"connect": "登录"
412412
},
413413
"input": {
414414
"stopMessage": "停止生成",

src/stores/authStore.ts

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { create } from "zustand";
22
import { persist } from "zustand/middleware";
3-
import { produce } from "immer";
4-
5-
import platformAdapter from "@/utils/platformAdapter";
6-
7-
const AUTH_CHANGE_EVENT = "auth-changed";
8-
const USERINFO_CHANGE_EVENT = "userInfo-changed";
93

104
export type Plan = {
115
upgraded: boolean;
@@ -19,93 +13,23 @@ export type AuthProp = {
1913
plan?: Plan | null;
2014
};
2115

22-
type AuthMapProp = {
23-
[key: string]: AuthProp;
24-
};
25-
26-
type userInfoMapProp = {
27-
[key: string]: any;
28-
};
29-
3016
export type IAuthStore = {
31-
[x: string]: any;
32-
auth: AuthMapProp | undefined;
33-
userInfo: userInfoMapProp;
34-
setAuth: (auth: AuthProp | undefined, key: string) => void;
35-
resetAuth: (key: string) => void;
3617
isCurrentLogin: boolean;
3718
setIsCurrentLogin: (isCurrentLogin: boolean) => void;
38-
initializeListeners: () => Promise<() => void>;
3919
};
4020

4121
export const useAuthStore = create<IAuthStore>()(
4222
persist(
4323
(set) => ({
44-
auth: undefined,
45-
userInfo: {},
46-
setAuth: async (auth, key) => {
47-
set(
48-
produce((draft) => {
49-
draft.auth[key] = auth;
50-
})
51-
);
52-
53-
await platformAdapter.emitEvent(AUTH_CHANGE_EVENT, {
54-
auth: {
55-
[key]: auth,
56-
},
57-
});
58-
},
59-
resetAuth: async (key: string) => {
60-
set(
61-
produce((draft) => {
62-
draft.auth[key] = undefined;
63-
})
64-
);
65-
66-
await platformAdapter.emitEvent(AUTH_CHANGE_EVENT, {
67-
auth: {
68-
[key]: undefined,
69-
},
70-
});
71-
},
72-
setUserInfo: async (userInfo: any, key: string) => {
73-
set(
74-
produce((draft) => {
75-
draft.userInfo[key] = userInfo;
76-
})
77-
);
78-
79-
await platformAdapter.emitEvent(USERINFO_CHANGE_EVENT, {
80-
userInfo: {
81-
[key]: userInfo,
82-
},
83-
});
84-
},
8524
isCurrentLogin: true,
8625
setIsCurrentLogin: (isCurrentLogin: boolean) => {
8726
set({ isCurrentLogin });
8827
},
89-
initializeListeners: async () => {
90-
await platformAdapter.listenEvent(AUTH_CHANGE_EVENT, (event: any) => {
91-
const { auth } = event.payload;
92-
set({ auth });
93-
});
94-
95-
return platformAdapter.listenEvent(
96-
USERINFO_CHANGE_EVENT,
97-
(event: any) => {
98-
const { userInfo } = event.payload;
99-
set({ userInfo });
100-
}
101-
);
102-
},
10328
}),
10429
{
10530
name: "auth-store",
10631
partialize: (state) => ({
107-
auth: state.auth,
108-
userInfo: state.userInfo,
32+
isCurrentLogin: state.isCurrentLogin,
10933
}),
11034
}
11135
)

src/types/platform.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ export interface EventPayloads {
1717
"showTooltip-changed": {
1818
showTooltip: boolean;
1919
};
20-
"auth-changed": {
21-
auth: Record<string, unknown>;
22-
};
23-
"userInfo-changed": {
24-
userInfo: Record<string, unknown>;
25-
};
2620
open_settings: string | "";
2721
tab_index: string | "";
2822
login_or_logout: unknown;

0 commit comments

Comments
 (0)