diff --git a/app/components/LoadingBar.tsx b/app/components/LoadingBar.tsx index 90a112df5c..7fb2e0eb77 100644 --- a/app/components/LoadingBar.tsx +++ b/app/components/LoadingBar.tsx @@ -1,9 +1,12 @@ +import { useEffect, useState } from 'react'; +import { Transition } from '@headlessui/react'; import { twMerge } from 'tailwind-merge'; -import { H4 } from '.'; + interface LoadingBarProps{ label?: string; progress?: number; + isShowing?: boolean; variant?: string; message?: string; wrapperClassName?: string; @@ -11,12 +14,57 @@ interface LoadingBarProps{ } export const LoadingBar = ({ label, - progress = 0, + progress: propsProgress = 0, + isShowing = true, variant = 'primary', message, wrapperClassName : propsWrapperClassName, - useFakeTimer = (1000 * 60) //defaults to 1min + useFakeTimer }: LoadingBarProps) => { + const [progress, setProgress] = useState(propsProgress); + + // this takes the real progress coming from parent + useEffect(()=>{ + setProgress(propsProgress); + }, [propsProgress]); + + // this sets a fake progress, it goes to 96% + // in the amount of miliseconds provided by the flag + useEffect(()=>{ + let loop: NodeJS.Timeout; + if(useFakeTimer){ + if(useFakeTimer >= 30000){ + // this math produce 96 cuts so the progress bar updates more + loop = setInterval(function step(){ + setProgress((curr)=>{ + if(curr<96){ + return curr + 3 + }else{ + clearInterval(loop); + return curr; + } + }) + },Math.round(useFakeTimer/96)*3); + }else{ + // this math produce less cuts if useFakeTimer predicts + // a shorter load time, shorter thatn 30s + const progressPerInterval = useFakeTimer/500 + loop = loop = setInterval(function step(){ + setProgress((curr)=>{ + if(curr + progressPerInterval < 96){ + return curr + progressPerInterval + }else if (curr< 96 && curr + progressPerInterval >= 96){ + return 96; + }else{ + clearInterval(loop); + return curr; + } + }) + }, 300); + } + } + return () => clearInterval(loop); + }, []); function getVariantClassNames(variant: string) { switch (variant) { @@ -40,7 +88,16 @@ export const LoadingBar = ({ ); return ( -
+ {label && }
- {message &&

{message}

} -
+ {message &&

{message}

} +
); } \ No newline at end of file diff --git a/app/components/LoadingDots.tsx b/app/components/LoadingDots.tsx index 3abfa49eb6..2a1c53e4fa 100644 --- a/app/components/LoadingDots.tsx +++ b/app/components/LoadingDots.tsx @@ -1,22 +1,19 @@ import { useState, useEffect } from 'react'; +import { Transition } from '@headlessui/react'; import { twMerge } from 'tailwind-merge'; import { H4 } from '.'; interface LoadingDotsProps { className?: string; - show?: boolean; - transition?: boolean; - transitionDuration?: number; + isShowing?: boolean; }; interface LoadingDotsInnerProps { className?: string; - show?: boolean; + isShowing?: boolean; type?: 'typing'|'bricks'; message?: string; - transition?: boolean; - transitionDuration?: number; }; export const LoadingDotsTyping = (props: LoadingDotsProps)=>{ @@ -32,54 +29,34 @@ export const LoadingDotsBricks = (props: LoadingDotsProps)=>{ export function LoadingDots({ className, - show=true, - transition = false, + isShowing=true, type = 'typing', message, - transitionDuration = 1000, }: LoadingDotsInnerProps){ - const [state, setState] = useState<'loading'|'loaded'|'completed'>('loading'); - const transitionClasses = - (transition ? `transition-opacity duration-${transitionDuration} `: "") - + (state === 'loading' ? 'opacity-100' : 'opacity-0'); + const classNames = twMerge("w-full h-full flex flex-col justify-center items-center bg-ui-background gap-6", className); - const classNames = twMerge("w-full h-full flex flex-col justify-center items-center bg-ui-background gap-6",transitionClasses, className); - useEffect(()=>{ - if(!show){ - if(transition){ - setState((curr)=>{ - if (curr === 'loading') return 'loaded' - else return curr; - }); - setTimeout(()=>setState('completed'), 2000); - } else { - setState('completed'); + return( + + { type==='typing' && +
} - }else{ - setState((curr) => { - if (curr!=='loading') return 'loading'; - else return curr; - }); - } - }, [show, transition]); - - if(state!== 'completed'){ - return( -
- { type==='typing' && -
- } - { type==='bricks' && -
- } - { - message && -

{message}

- } -
- ); - }else{ - return null; - } + { type==='bricks' && +
+ } + { + message && +

{message}

+ } +
+ ); }; diff --git a/app/pages/PageEnigma/PageEnigmaComponent.tsx b/app/pages/PageEnigma/PageEnigmaComponent.tsx index 702a51d6d1..58389e8920 100644 --- a/app/pages/PageEnigma/PageEnigmaComponent.tsx +++ b/app/pages/PageEnigma/PageEnigmaComponent.tsx @@ -66,10 +66,9 @@ export const PageEnigmaComponent = () => { }
diff --git a/app/pages/PageEnigma/comps/PreviewEngineCamera/index.tsx b/app/pages/PageEnigma/comps/PreviewEngineCamera/index.tsx index 324a2bcad9..8630ed50d9 100644 --- a/app/pages/PageEnigma/comps/PreviewEngineCamera/index.tsx +++ b/app/pages/PageEnigma/comps/PreviewEngineCamera/index.tsx @@ -29,7 +29,7 @@ export const PreviewEngineCamera = ()=>{ src="/resources/uiAssets/video_player_placeholder.gif" />
- +
diff --git a/app/pages/PageEnigma/reducer/index.tsx b/app/pages/PageEnigma/reducer/index.tsx index e44636d058..48da7e99b6 100644 --- a/app/pages/PageEnigma/reducer/index.tsx +++ b/app/pages/PageEnigma/reducer/index.tsx @@ -5,7 +5,7 @@ const initialState:State = { timelineHeight: 260, viewMode: VIEW_MODES.EDITOR, showEditorLoader: { - isShow:true, + isShowing:true, message: 'loading Editor Engine 🦊' } } diff --git a/app/pages/PageEnigma/reducer/types.tsx b/app/pages/PageEnigma/reducer/types.tsx index a9d259ac08..e40e32c2e3 100644 --- a/app/pages/PageEnigma/reducer/types.tsx +++ b/app/pages/PageEnigma/reducer/types.tsx @@ -9,7 +9,7 @@ export type State = { viewMode: ViewModes; timelineHeight: number; showEditorLoader: { - isShow:boolean + isShowing:boolean; message:string|undefined; }; }; diff --git a/app/root.tsx b/app/root.tsx index a62b912903..f22de825a3 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -1,4 +1,5 @@ import { useState, useEffect } from "react"; +import { Transition } from "@headlessui/react"; import { LinksFunction } from "@remix-run/deno"; import { Links, @@ -47,13 +48,11 @@ export const links: LinksFunction = () => [ export default function App() { const [topBarInnerComponent, setTopBarInnerComponent] = useState(null); - const [isLoaded, setIsLoaded] = useState<'loading'|'loaded'|'completed'>('loading'); + const [showLoader, setShowLoader] = useState(true); useEffect(()=>{ - setIsLoaded('loaded'); - setTimeout(()=>setIsLoaded('completed'), 2000); + setTimeout(()=>setShowLoader(false), 2500); },[]); - return ( @@ -63,15 +62,7 @@ export default function App() { - {isLoaded !== 'completed' && - - } + - - + + ); }; \ No newline at end of file diff --git a/app/routes/ComponentLibrary.tsx b/app/routes/ComponentLibrary.tsx index acc2188c52..6024c6ec4a 100644 --- a/app/routes/ComponentLibrary.tsx +++ b/app/routes/ComponentLibrary.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { Button, ButtonLink, @@ -11,20 +11,28 @@ import { export default function ComponentLibrary () { const [progress, setProgress] = useState(0); + const loopRef = useRef(null); + + const pushProgressBar: ()=>void = useCallback(()=>{ + loopRef.current = setInterval(function timer(){ + setProgress((curr)=>{ + if (curr < 100){ + return curr+10; + }else{ + if(loopRef.current) + clearInterval(loopRef.current); + return curr; + } + })} + , 3000); + }, []); useEffect(()=>{ - if(progress === 0){ - const loop = setInterval(function timer(){ - setProgress((curr)=>{ - if (curr < 100){ - return curr+10; - }else{ - clearTimeout(loop); - return curr; - } - })} - , 3000); + pushProgressBar(); + return ()=>{ + if(loopRef.current) + clearInterval(loopRef.current) } - }, [progress]); + },[progress]); return(
@@ -57,14 +65,31 @@ export default function ComponentLibrary () {

Loading Bar

-
- - +
+ +
+ +