diff --git a/app/web/src/components/DelayedPingAnimation/DelayedPingAnimation.tsx b/app/web/src/components/DelayedPingAnimation/DelayedPingAnimation.tsx new file mode 100644 index 0000000..bfc4995 --- /dev/null +++ b/app/web/src/components/DelayedPingAnimation/DelayedPingAnimation.tsx @@ -0,0 +1,29 @@ + + +let timeoutId = 0 +const DelayedPingAnimation = ({isLoading: isLoading}: {isLoading: boolean}) => { + const [showLoading, setShowLoading] = React.useState(false) + React.useEffect(() => { + if (!isLoading && showLoading) { + setShowLoading(isLoading) + clearTimeout(timeoutId) + } else if (isLoading && !showLoading) { + timeoutId = setTimeout(() => { + setShowLoading(isLoading) + console.log('setloading') + }, 300) as unknown as number + } else if (!isLoading) { + setShowLoading(isLoading) + clearTimeout(timeoutId) + } + }, [isLoading]) + + if (showLoading && isLoading) return ( +
+
+
+ ) + return null +} + +export default DelayedPingAnimation diff --git a/app/web/src/components/IdeViewer/IdeViewer.tsx b/app/web/src/components/IdeViewer/IdeViewer.tsx index 3aa0c10..13d1db7 100644 --- a/app/web/src/components/IdeViewer/IdeViewer.tsx +++ b/app/web/src/components/IdeViewer/IdeViewer.tsx @@ -7,6 +7,7 @@ import { requestRender } from 'src/helpers/hooks/useIdeState' import texture from './dullFrontLitMetal.png' import { TextureLoader } from 'three/src/loaders/TextureLoader' import Customizer from 'src/components/Customizer/Customizer' + import DelayedPingAnimation from 'src/components/DelayedPingAnimation/DelayedPingAnimation' const loader = new TextureLoader() const colorMap = loader.load(texture) @@ -240,11 +241,7 @@ const IdeViewer = ({ Loading }) => { /> - {state.isLoading && ( -
-
-
- )} + ) diff --git a/app/web/src/helpers/hooks/useIdeState.ts b/app/web/src/helpers/hooks/useIdeState.ts index 900ceee..bd157b1 100644 --- a/app/web/src/helpers/hooks/useIdeState.ts +++ b/app/web/src/helpers/hooks/useIdeState.ts @@ -175,6 +175,7 @@ export const useIdeState = (): [State, (actionOrThunk: any) => any] => { case 'updateCode': return { ...state, code: payload } case 'healthyRender': + const currentParameters = (payload.currentParameters && Object.keys(payload.currentParameters).length) ? payload.currentParameters : state.currentParameters return { ...state, objectData: { @@ -183,7 +184,7 @@ export const useIdeState = (): [State, (actionOrThunk: any) => any] => { data: payload.objectData?.data, }, customizerParams: payload.customizerParams || state.customizerParams, - currentParameters: Object.keys(payload.currentParameters).length ? payload.currentParameters : state.currentParameters, + currentParameters, consoleMessages: payload.message ? [...state.consoleMessages, payload.message] : payload.message,