mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Accounts datatable.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, {useState, useEffect, useMemo} from 'react';
|
||||
import { Spinner } from '@blueprintjs/core';
|
||||
|
||||
export default function LoadingIndicator({
|
||||
@@ -6,15 +6,33 @@ export default function LoadingIndicator({
|
||||
spinnerSize = 40,
|
||||
children
|
||||
}) {
|
||||
const [rendered, setRendered] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) { setRendered(true); }
|
||||
}, [loading]);
|
||||
|
||||
const componentStyle = useMemo(() => {
|
||||
return {display: !loading ? 'block' : 'none'};
|
||||
}, [loading]);
|
||||
|
||||
const loadingComponent = useMemo(() => (
|
||||
<div class='dashboard__loading-indicator'>
|
||||
<Spinner size={spinnerSize} value={null} />
|
||||
</div>
|
||||
), [spinnerSize]);
|
||||
|
||||
const renderComponent = useMemo(() => (
|
||||
<div style={componentStyle}>{ children }</div>
|
||||
), [children, componentStyle]);
|
||||
|
||||
const maybeRenderComponent = rendered && renderComponent;
|
||||
const maybeRenderLoadingSpinner = loading && loadingComponent;
|
||||
|
||||
return (
|
||||
<>
|
||||
{loading ? (
|
||||
<div class='dashboard__loading-indicator'>
|
||||
<Spinner size={spinnerSize} value={null} />
|
||||
</div>
|
||||
) : (
|
||||
children
|
||||
)}
|
||||
{ maybeRenderLoadingSpinner }
|
||||
{ maybeRenderComponent }
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user