Fix delay in app state being set
This commit is contained in:
@@ -153,7 +153,7 @@ export const ClientConfigStore: FC = () => {
|
|||||||
const [currentUser, setCurrentUser] = useRecoilState(currentUserAtom);
|
const [currentUser, setCurrentUser] = useRecoilState(currentUserAtom);
|
||||||
const setChatAuthenticated = useSetRecoilState<boolean>(chatAuthenticatedAtom);
|
const setChatAuthenticated = useSetRecoilState<boolean>(chatAuthenticatedAtom);
|
||||||
const [clientConfig, setClientConfig] = useRecoilState<ClientConfig>(clientConfigStateAtom);
|
const [clientConfig, setClientConfig] = useRecoilState<ClientConfig>(clientConfigStateAtom);
|
||||||
const setServerStatus = useSetRecoilState<ServerStatus>(serverStatusState);
|
const [serverStatus, setServerStatus] = useRecoilState<ServerStatus>(serverStatusState);
|
||||||
const setClockSkew = useSetRecoilState<Number>(clockSkewAtom);
|
const setClockSkew = useSetRecoilState<Number>(clockSkewAtom);
|
||||||
const [chatMessages, setChatMessages] = useRecoilState<ChatMessage[]>(chatMessagesAtom);
|
const [chatMessages, setChatMessages] = useRecoilState<ChatMessage[]>(chatMessagesAtom);
|
||||||
const [accessToken, setAccessToken] = useRecoilState<string>(accessTokenAtom);
|
const [accessToken, setAccessToken] = useRecoilState<string>(accessTokenAtom);
|
||||||
@@ -173,15 +173,11 @@ export const ClientConfigStore: FC = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const sendEvent = (event: string) => {
|
const sendEvent = (event: string) => {
|
||||||
// console.log('---- sending event:', event);
|
console.debug('---- sending event:', event);
|
||||||
appStateSend({ type: event });
|
appStateSend({ type: event });
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateClientConfig = async () => {
|
const updateClientConfig = async () => {
|
||||||
if (hasLoadedConfig) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const config = await ClientConfigService.getConfig();
|
const config = await ClientConfigService.getConfig();
|
||||||
setClientConfig(config);
|
setClientConfig(config);
|
||||||
@@ -197,10 +193,6 @@ export const ClientConfigStore: FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateServerStatus = async () => {
|
const updateServerStatus = async () => {
|
||||||
if (hasLoadedStatus) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const status = await ServerStatusService.getStatus();
|
const status = await ServerStatusService.getStatus();
|
||||||
setServerStatus(status);
|
setServerStatus(status);
|
||||||
@@ -210,11 +202,6 @@ export const ClientConfigStore: FC = () => {
|
|||||||
const clockSkew = new Date(serverTime).getTime() - Date.now();
|
const clockSkew = new Date(serverTime).getTime() - Date.now();
|
||||||
setClockSkew(clockSkew);
|
setClockSkew(clockSkew);
|
||||||
|
|
||||||
if (status.online) {
|
|
||||||
sendEvent(AppStateEvent.Online);
|
|
||||||
} else if (!status.online) {
|
|
||||||
sendEvent(AppStateEvent.Offline);
|
|
||||||
}
|
|
||||||
setGlobalFatalErrorMessage(null);
|
setGlobalFatalErrorMessage(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
sendEvent(AppStateEvent.Fail);
|
sendEvent(AppStateEvent.Fail);
|
||||||
@@ -360,6 +347,12 @@ export const ClientConfigStore: FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hasLoadedStatus && hasLoadedConfig) {
|
if (hasLoadedStatus && hasLoadedConfig) {
|
||||||
sendEvent(AppStateEvent.Loaded);
|
sendEvent(AppStateEvent.Loaded);
|
||||||
|
|
||||||
|
if (serverStatus.online) {
|
||||||
|
sendEvent(AppStateEvent.Online);
|
||||||
|
} else {
|
||||||
|
sendEvent(AppStateEvent.Offline);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [hasLoadedStatus, hasLoadedConfig]);
|
}, [hasLoadedStatus, hasLoadedConfig]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user