refactor: stop SSE before start connect

This commit is contained in:
Tristan Yang
2024-05-14 17:58:40 +08:00
parent 96363f1e15
commit 78e651123a
10 changed files with 397 additions and 366 deletions
+3
View File
@@ -12,6 +12,7 @@ import { UserRegDTO, UserRegResponse } from "@/types/user";
import BASE_URL, { KEY_DEVICE_ID, KEY_DEVICE_TOKEN, KEY_LOCAL_MAGIC_TOKEN } from "../config";
import { resetAuthData, setAuthData, updateInitialized, updateToken } from "../slices/auth.data";
import baseQuery from "./base.query";
import { setReady, updateSSEStatus } from "../slices/ui";
const getDeviceId = () => {
let d = localStorage.getItem(KEY_DEVICE_ID);
@@ -52,6 +53,8 @@ export const authApi = createApi({
const { data } = await queryFulfilled;
if (data) {
dispatch(setAuthData(data));
dispatch(setReady(false));
dispatch(updateSSEStatus("disconnected"));
}
// 从 localstorage 去掉 magic token
localStorage.removeItem(KEY_LOCAL_MAGIC_TOKEN);
+7 -2
View File
@@ -31,7 +31,12 @@ const whiteList = [
"preCheckFileFromUrl"
];
const whiteList401 = ["getAgoraVoicingList", "getAgoraChannels"];
const errorWhiteList = ["preCheckFileFromUrl", "getFavoriteDetails"];
const errorWhiteList = [
"preCheckFileFromUrl",
"getFavoriteDetails",
"getOGInfo",
"getArchiveMessage"
];
const baseQuery = fetchBaseQuery({
baseUrl: BASE_URL,
prepareHeaders: (headers, { endpoint }) => {
@@ -49,7 +54,7 @@ const baseQueryWithTokenCheck = async (args: any, api: any, extraOptions: any) =
if (waitingForRenew) {
await waitingForRenew;
}
// 先检查token是否过期,过期则renew [从localstorage取]
// 先检查 token 是否过期,过期则 renew [从 localstorage 取]
const { token, refreshToken, expireTime } = getLocalAuthData();
let result = null;
+4 -3
View File
@@ -4,11 +4,12 @@ import { UploadFileData } from "@/hooks/useUploadFile";
export type ListView = "item" | "grid";
export type SSEStatus = "connecting" | "connected" | "disconnected" | "reconnecting";
export type InputMode = "text" | "markdown";
export interface UIState {
SSEStatus: SSEStatus;
online: boolean;
ready: boolean;
inputMode: "text";
inputMode: InputMode;
menuExpand: boolean;
// todo
fileListView: ListView;
@@ -62,10 +63,10 @@ const uiSlice = createSlice({
toggleMenuExpand(state) {
state.menuExpand = !state.menuExpand;
},
updateInputMode(state, action) {
updateInputMode(state, action: PayloadAction<InputMode>) {
state.inputMode = action.payload;
},
updateFileListView(state, action) {
updateFileListView(state, action: PayloadAction<ListView>) {
state.fileListView = action.payload;
},
updateRememberedNavs(