fix: #589 improve unauthorized tips

This commit is contained in:
Yidadaa
2023-04-09 23:51:12 +08:00
parent 4a492264a1
commit 0e05733bbb
6 changed files with 66 additions and 48 deletions

View File

@@ -9,6 +9,7 @@ export interface AccessControlStore {
updateToken: (_: string) => void;
updateCode: (_: string) => void;
enabledAccessControl: () => boolean;
isAuthorized: () => boolean;
}
export const ACCESS_KEY = "access-control";
@@ -27,10 +28,13 @@ export const useAccessStore = create<AccessControlStore>()(
updateToken(token: string) {
set((state) => ({ token }));
},
isAuthorized() {
return !!get().token || !!get().accessCode;
},
}),
{
name: ACCESS_KEY,
version: 1,
}
)
},
),
);

View File

@@ -333,17 +333,23 @@ export const useChatStore = create<ChatStore>()(
if (!isMobileScreen() || confirm(Locale.Home.DeleteChat)) {
get().removeSession(index);
showToast(Locale.Home.DeleteToast, {
text: Locale.Home.Revert,
onClick() {
set((state) => ({
sessions: state.sessions
.slice(0, index)
.concat([deletedSession])
.concat(state.sessions.slice(index + Number(isLastSession))),
}));
showToast(
Locale.Home.DeleteToast,
{
text: Locale.Home.Revert,
onClick() {
set((state) => ({
sessions: state.sessions
.slice(0, index)
.concat([deletedSession])
.concat(
state.sessions.slice(index + Number(isLastSession)),
),
}));
},
},
});
5000,
);
}
},