feat: application and dashboard async booting.

This commit is contained in:
a.bouhuolia
2021-11-26 22:27:27 +02:00
parent ca3ff3fd8f
commit 1be30fd142
3 changed files with 35 additions and 28 deletions

View File

@@ -1,5 +1,4 @@
import React from 'react';
import * as R from 'ramda';
import {
useAuthenticatedAccount,
useCurrentOrganization,
@@ -10,9 +9,9 @@ import { useWatch, useWatchImmediate, useWhen } from '../../hooks';
import { setCookie, getCookie } from '../../utils';
/**
* Boots dashboard meta.
* Dashboard meta async booting.
*/
function useDashboardMetaBoot() {
export function useDashboardMetaBoot() {
const {
data: dashboardMeta,
isLoading: isDashboardMetaLoading,
@@ -20,7 +19,7 @@ function useDashboardMetaBoot() {
} = useDashboardMeta();
const [startLoading, stopLoading] = useSplashLoading();
useWatchImmediate((value) => {
value && startLoading();
}, isDashboardMetaLoading);
@@ -28,12 +27,26 @@ function useDashboardMetaBoot() {
useWatchImmediate(() => {
isDashboardMetaSuccess && stopLoading();
}, isDashboardMetaSuccess);
return {
isLoading: isDashboardMetaLoading,
};
}
/**
* Dashboard async booting.
* @returns {{ isLoading: boolean }}
*/
export function DashboardBoot({ authenticatedUserId }) {
export function useDashboardBoot() {
const { isLoading } = useDashboardMetaBoot();
return { isLoading };
}
/**
* Application async booting.
*/
export function useApplicationBoot() {
// Fetches the current user's organization.
const {
isSuccess: isCurrentOrganizationSuccess,
@@ -45,8 +58,6 @@ export function DashboardBoot({ authenticatedUserId }) {
const { isSuccess: isAuthUserSuccess, isLoading: isAuthUserLoading } =
useAuthenticatedAccount();
useDashboardMetaBoot();
// Initial locale cookie value.
const localeCookie = getCookie('locale');
@@ -109,5 +120,8 @@ export function DashboardBoot({ authenticatedUserId }) {
isBooted.current = true;
},
);
return null;
return {
isLoading: isOrgLoading || isAuthUserLoading,
};
}