Shared:Selectors:Files: add timer to showing list loader

This commit is contained in:
Timofey Boyko 2024-08-05 15:58:57 +03:00
parent 888cbebce4
commit 1f36216278
2 changed files with 13 additions and 6 deletions

View File

@ -44,6 +44,7 @@ const useLoadersHelper = () => {
const [isFirstLoad, setIsFirstLoad] = React.useState(true);
const startLoader = React.useRef<Date | null>(new Date());
const loaderTimeout = React.useRef<NodeJS.Timeout | null>(null);
const breadCrumbsLoaderTimeout = React.useRef<NodeJS.Timeout | null>(null);
const breadCrumbsStartLoader = React.useRef<Date | null>(new Date());
@ -59,9 +60,10 @@ const useLoadersHelper = () => {
const calculateLoader = React.useCallback(() => {
if (isFirstLoad) {
setShowLoader(true);
startLoader.current = new Date();
loaderTimeout.current = setTimeout(() => {
startLoader.current = new Date();
if (isMount.current) setShowLoader(true);
}, SHOW_LOADER_TIMER);
} else if (startLoader.current) {
const currentDate = new Date();
@ -80,6 +82,11 @@ const useLoadersHelper = () => {
setShowLoader(false);
}
}, MIN_LOADER_TIMER - ms);
loaderTimeout.current = null;
} else if (loaderTimeout.current) {
clearTimeout(loaderTimeout.current);
loaderTimeout.current = null;
}
}, [isFirstLoad]);

View File

@ -238,7 +238,7 @@ const FilesSelectorComponent = ({
setSelectedItemType(undefined);
getRootData();
} else {
setItems([]);
// setItems([]);
setBreadCrumbs((bc) => {
const idx = bc.findIndex(
@ -302,7 +302,7 @@ const FilesSelectorComponent = ({
if (item.isFolder) {
setIsFirstLoad(true);
setItems([]);
// setItems([]);
setBreadCrumbs((value) => [
...value,
{
@ -506,7 +506,7 @@ const FilesSelectorComponent = ({
submitButtonLabel,
submitButtonId,
disableSubmitButton: getIsDisabled(
isFirstLoad,
isFirstLoad && showLoader,
isSelectedParentFolder,
selectedItemId,
selectedItemType,