mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat: application and dashboard async booting.
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user