Separated dice loading and dice instance creation and added loading spinner for dice

This commit is contained in:
Mitchell McCaffrey
2020-05-27 14:47:51 +10:00
parent da84f923d1
commit 7f0b4e32af
11 changed files with 117 additions and 11 deletions

View File

@@ -0,0 +1,31 @@
import React, { useState } from "react";
const DiceLoadingContext = React.createContext();
export function DiceLoadingProvider({ 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 (
<DiceLoadingContext.Provider value={value}>
{children}
</DiceLoadingContext.Provider>
);
}
export default DiceLoadingContext;