diff --git a/src/App.tsx b/src/App.tsx index 4782f5bc..b79b3831 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import { getFirebaseRecipe, jsonToString } from "./utils/recipeLoader"; import { getSubmitPackingUrl, JOB_STATUS } from "./constants/aws"; import { FIRESTORE_FIELDS } from "./constants/firebase"; import { + useCurrentRecipeData, useJobId, useJobLogs, useOutputsDirectory, @@ -33,6 +34,7 @@ function App() { const setPackingResults = useSetPackingResults(); const runTime = useRunTime(); const outputDir = useOutputsDirectory(); + const edits = useCurrentRecipeData()?.edits || {}; let start = 0; @@ -143,6 +145,7 @@ function App() { resultUrl: localJobStatus.result_path, runTime: range, outputDir: localJobStatus.outputs_directory, + edits: edits, }); } else if (localJobStatus.status == JOB_STATUS.FAILED) { setPackingResults({ @@ -151,6 +154,7 @@ function App() { resultUrl: "", runTime: range, outputDir: "", + edits: {} }); } }; diff --git a/src/components/PackingInput/index.tsx b/src/components/PackingInput/index.tsx index a2de51da..6ed61bd6 100644 --- a/src/components/PackingInput/index.tsx +++ b/src/components/PackingInput/index.tsx @@ -9,6 +9,7 @@ import { useCurrentRecipeObject, useInputOptions, useLoadInputOptions, + useIsLoading, } from "../../state/store"; import Dropdown from "../Dropdown"; import JSONViewer from "../JSONViewer"; @@ -36,6 +37,7 @@ const PackingInput = (props: PackingInputProps): JSX.Element => { const selectedRecipeId = useSelectedRecipeId(); const recipeObj = useCurrentRecipeObject(); const inputOptions = useInputOptions(); + const isLoading = useIsLoading(); const loadInputOptions = useLoadInputOptions(); const loadAllRecipes = useLoadAllRecipes(); @@ -73,7 +75,7 @@ const PackingInput = (props: PackingInputProps): JSX.Element => { const loadingText =
Loading...
; // No recipe or dropdown options to load - if (!recipeObj && !inputOptions[selectedRecipeId]) { + if (isLoading) { return loadingText; } diff --git a/src/components/Viewer/index.tsx b/src/components/Viewer/index.tsx index 8a2dc79d..bf103991 100644 --- a/src/components/Viewer/index.tsx +++ b/src/components/Viewer/index.tsx @@ -1,15 +1,65 @@ +import { useEffect, useRef, useState } from "react"; +import { LoadingOutlined } from "@ant-design/icons"; import { SIMULARIUM_EMBED_URL } from "../../constants/urls"; -import { useResultUrl } from "../../state/store"; +import { useIsLoading, useIsModified, useIsPacking, useResultUrl } from "../../state/store"; import "./style.css"; const Viewer = (): JSX.Element => { const resultUrl = useResultUrl(); + const isLoadingGlobally = useIsLoading(); + const isPacking = useIsPacking(); + const isModified = useIsModified(); + + const iframeSrc = resultUrl ? `${SIMULARIUM_EMBED_URL}${resultUrl}` : ""; + + const lastSrcRef = useRef(""); + const [isLoadingIframe, setIsLoadingIframe] = useState(false); + + useEffect(() => { + if (!iframeSrc) return; + if (iframeSrc === lastSrcRef.current) return; + + lastSrcRef.current = iframeSrc; + setIsLoadingIframe(true); + }, [iframeSrc]); + + + const isLoading = + isLoadingGlobally || isLoadingIframe || !iframeSrc; + + const overlayText = isPacking + ? "Running..." + : isLoading + ? "Loading..." + : isModified + ? "Re-run packing to view result" + : ""; + + const activeState = isLoading || isPacking; + const showOverlay = activeState || isModified; + return (
-