@@ -29,21 +29,30 @@ interface Demo {
2929export const DemoPage = ( ) => {
3030 const [ demoData , setDemoData ] = useState < Demo | null > ( null ) ;
3131 const [ isLoading , setIsLoading ] = useState ( true ) ;
32- const [ baseUrls , setBaseUrls ] = useState < string [ ] > ( [
33- SampleDemoJsonFile ?. steps [ 0 ] . url || '' ,
34- ] ) ;
32+ const [ activeBaseUrl , setActiveBaseUrl ] = useState < string > ( '' ) ;
33+ const [ baseUrls , setBaseUrls ] = useState < Map < string , string > > (
34+ new Map ( [
35+ [
36+ SampleDemoJsonFile ?. steps [ 0 ] . url || '' ,
37+ SampleDemoJsonFile ?. steps [ 0 ] . url || '' ,
38+ ] ,
39+ ] )
40+ ) ;
3541
3642 // const location = useLocation();
3743
3844 useEffect ( ( ) => {
3945 // const demoTitle = location.pathname.split('/')[2];
4046 // fetchDemoData()
4147 // .then(setDemoData)
42- // .catch(console.error)
4348 // .finally(() => setIsLoading(false));
4449 setIsLoading ( false ) ;
4550 setDemoData ( SampleDemoJsonFile ) ;
4651 setIframeUrl ( SampleDemoJsonFile ?. steps [ 0 ] . url ?? '' ) ;
52+ const initialUrl = SampleDemoJsonFile ?. steps [ 0 ] . url ?? '' ;
53+ const parsedUrl = new URL ( initialUrl ) ;
54+ const initialBaseUrl = `${ parsedUrl . protocol } //${ parsedUrl . hostname } ` ;
55+ setActiveBaseUrl ( initialBaseUrl ) ;
4756 } , [ ] ) ;
4857
4958 const [ currentStep , setCurrentStep ] = useState ( 0 ) ;
@@ -52,7 +61,6 @@ export const DemoPage = () => {
5261 const [ isTransitioning , setIsTransitioning ] = useState ( false ) ;
5362
5463 useEffect ( ( ) => {
55- console . log ( demoData ?. steps [ 0 ] . url ) ;
5664 let interval : NodeJS . Timeout ;
5765 if ( isAutoPlay && demoData ) {
5866 interval = setInterval ( ( ) => {
@@ -70,8 +78,10 @@ export const DemoPage = () => {
7078 setCurrentStep ( stepIndex ) ;
7179 if ( url ) {
7280 setTimeout ( ( ) => {
81+ const parsedUrl = new URL ( url ) ;
82+ const baseUrl = `${ parsedUrl . protocol } //${ parsedUrl . hostname } ` ;
83+ setActiveBaseUrl ( baseUrl ) ;
7384 getUniqueBaseUrls ( url , setBaseUrls ) ;
74- console . log ( baseUrls ) ;
7585 setIframeUrl ( url ) ;
7686 setTimeout ( ( ) => setIsTransitioning ( false ) , 300 ) ;
7787 } , 150 ) ;
@@ -106,6 +116,7 @@ export const DemoPage = () => {
106116 const handleReset = ( ) => {
107117 setIsAutoPlay ( false ) ;
108118 handleStepTransition ( 0 , 'https://sandbox.mifos.community' ) ;
119+ setActiveBaseUrl ( 'https://sandbox.mifos.community' ) ;
109120 } ;
110121
111122 if ( isLoading ) {
@@ -356,23 +367,23 @@ export const DemoPage = () => {
356367 < div className = "bg-gray-100 dark:bg-gray-800 rounded-lg px-2 flex-1 max-w-md" >
357368 < span
358369 className = "text-sm min-w-20 max-w-40 text-gray-600 dark:text-gray-400 font-mono truncate block"
359- title = { iframeUrl }
370+ title = { activeBaseUrl }
360371 >
361- { iframeUrl }
372+ { activeBaseUrl }
362373 </ span >
363374 </ div >
364375 </ div >
365376 < div className = "w-full h-full flex" >
366- { baseUrls . map ( ( baseUrl , idx ) => (
377+ { Array . from ( baseUrls . keys ( ) ) . map ( ( baseUrl , idx ) => (
367378 < Button
368379 key = { idx }
369- className = { `h-full max-w-40 rounded-none flex-1 transition-all duration-200
380+ className = { `h-full max-w-40 rounded-none flex-1 transition-all duration-200 cursor-pointer
370381 ${
371382 iframeUrl ?. startsWith ( baseUrl )
372383 ? 'bg-blue-400 hover:bg-blue-500 text-white shadow-sm dark:bg-blue-600'
373384 : 'bg-gray-200 hover:bg-gray-300 text-gray-500 dark:bg-slate-400 dark:text-gray-600'
374385 } font-semibold`}
375- onClick = { ( ) => setIframeUrl ( baseUrl ) }
386+ onClick = { ( ) => setActiveBaseUrl ( baseUrl ) }
376387 >
377388 { mapUrl . get ( baseUrl ) }
378389 </ Button >
@@ -392,7 +403,7 @@ export const DemoPage = () => {
392403 </ button >
393404 </ div >
394405
395- < div className = "flex-1 relative bg-white dark:bg-gray-900 " >
406+ < div className = "flex-1 relative bg-white dark:bg-gray-400 " >
396407 { isTransitioning && (
397408 < div className = "absolute inset-0 bg-white/80 dark:bg-gray-900/80 backdrop-blur-sm z-10 flex items-center justify-center" >
398409 < div className = "text-center space-y-4" >
@@ -406,12 +417,19 @@ export const DemoPage = () => {
406417 </ div >
407418 </ div >
408419 ) }
409- < iframe
410- src = { iframeUrl }
411- className = { `w-full h-full border-0 transition-opacity duration-300 ${ isTransitioning ? 'opacity-50' : 'opacity-100' } ` }
412- title = "MifosX Demo"
413- sandbox = "allow-scripts allow-same-origin allow-forms allow-popups allow-top-navigation-by-user-activation"
414- />
420+ { Array . from ( baseUrls . entries ( ) ) . map ( ( [ baseUrl , url ] ) => (
421+ < iframe
422+ key = { baseUrl }
423+ src = { url }
424+ className = { `w-full h-full border-0 absolute top-0 left-0 transition-opacity duration-300 ${
425+ activeBaseUrl === baseUrl
426+ ? 'opacity-100 z-10'
427+ : 'opacity-0 z-0'
428+ } `}
429+ title = "MifosX Demo"
430+ sandbox = "allow-scripts allow-same-origin allow-forms allow-popups allow-top-navigation-by-user-activation"
431+ />
432+ ) ) }
415433 </ div >
416434 </ div >
417435 </ div >
0 commit comments