refactor: remove get server from preload

This commit is contained in:
Tristan Yang
2023-07-20 16:00:03 +08:00
parent 2ca6049a16
commit 4c5b5274e1
3 changed files with 7 additions and 25 deletions
-6
View File
@@ -1,7 +1,6 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { AuthData, RenewTokenResponse } from "@/types/auth";
// import { isNull, omitBy } from "lodash";
import {
KEY_EXPIRE,
KEY_LOGIN_USER,
@@ -12,8 +11,6 @@ import {
} from "../config";
import { StoredUser } from "./users";
// import { updateUsersByLogs } from './users';
interface State {
initialized: boolean;
guest: boolean;
@@ -71,7 +68,6 @@ const authDataSlice = createSlice({
},
updateLoginUser(state, { payload }: PayloadAction<Partial<StoredUser>>) {
if (!state.user) return;
const obj = { ...state.user, ...payload };
Object.keys(obj).forEach((key) => {
// @ts-ignore
@@ -80,7 +76,6 @@ const authDataSlice = createSlice({
delete obj[key];
}
});
console.log("upppp", obj);
state.user = obj;
localStorage.setItem(KEY_LOGIN_USER, JSON.stringify(obj));
},
@@ -94,7 +89,6 @@ const authDataSlice = createSlice({
localStorage.removeItem(KEY_REFRESH_TOKEN);
localStorage.removeItem(KEY_UID);
localStorage.removeItem(KEY_PWA_INSTALLED);
return emptyState;
},
updateInitialized(state, action: PayloadAction<boolean>) {
+2
View File
@@ -1,9 +1,11 @@
import { FC } from "react";
import { Helmet } from "react-helmet";
import { useAppSelector } from "@/app/store";
import { useGetServerQuery } from "@/app/services/server";
type Props = {};
const Meta: FC<Props> = () => {
useGetServerQuery();
const { name, logo } = useAppSelector((store) => store.server);
return (
<Helmet>
+5 -19
View File
@@ -3,11 +3,7 @@ import dayjs from "dayjs";
import initCache, { useRehydrate } from "@/app/cache";
import { useLazyGetFavoritesQuery, useLazyLoadMoreMessagesQuery } from "@/app/services/message";
import {
useLazyGetServerQuery,
useLazyGetServerVersionQuery,
useLazyGetSystemCommonQuery
} from "@/app/services/server";
import { useLazyGetServerVersionQuery, useLazyGetSystemCommonQuery } from "@/app/services/server";
import { useLazyGetContactsQuery, useLazyGetUsersQuery } from "@/app/services/user";
import { useAppSelector } from "@/app/store";
import useLicense from "./useLicense";
@@ -63,10 +59,7 @@ export default function usePreload() {
data: contacts
}
] = useLazyGetContactsQuery();
const [
getServer,
{ isLoading: serverLoading, isSuccess: serverSuccess, isError: serverError, data: server }
] = useLazyGetServerQuery();
const [
getServerVersion,
{ data: serverVersion, isSuccess: serverVersionSuccess, isLoading: loadingServerVersion }
@@ -100,7 +93,6 @@ export default function usePreload() {
getContacts();
}
});
getServer();
getFavorites();
getSystemCommon();
}
@@ -114,17 +106,11 @@ export default function usePreload() {
}, [canStreaming]);
return {
loading:
usersLoading ||
serverLoading ||
favoritesLoading ||
!rehydrated ||
loadingLicense ||
loadingServerVersion,
error: usersError && serverError && favoritesError,
success: usersSuccess && serverSuccess && favoritesSuccess && serverVersionSuccess,
usersLoading || favoritesLoading || !rehydrated || loadingLicense || loadingServerVersion,
error: usersError && favoritesError,
success: usersSuccess && favoritesSuccess && serverVersionSuccess,
data: {
users: enableContacts ? contacts : users,
server,
favorites
}
};