Added map loading provider to fix bugs with multiple asset loading

This commit is contained in:
Mitchell McCaffrey
2020-05-25 15:34:22 +10:00
parent b0c1dcf9dd
commit 33d7d972be
4 changed files with 49 additions and 13 deletions

View File

@@ -0,0 +1,31 @@
import React, { useState } from "react";
const MapLoadingContext = React.createContext();
export function MapLoadingProvider({ children }) {
const [loadingAssetCount, setLoadingAssetCount] = useState(0);
function assetLoadStart() {
setLoadingAssetCount((prevLoadingAssets) => prevLoadingAssets + 1);
}
function assetLoadFinish() {
setLoadingAssetCount((prevLoadingAssets) => prevLoadingAssets - 1);
}
const isLoading = loadingAssetCount > 0;
const value = {
assetLoadStart,
assetLoadFinish,
isLoading,
};
return (
<MapLoadingContext.Provider value={value}>
{children}
</MapLoadingContext.Provider>
);
}
export default MapLoadingContext;