Skip to content

Commit 6d6bd9c

Browse files
fix: reload of iframe on dpg tab change
1 parent 4133904 commit 6d6bd9c

3 files changed

Lines changed: 48 additions & 28 deletions

File tree

src/lib/demofileparser/getBaseUrl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ export const mapUrl = new Map<string, string>([
55

66
export const getUniqueBaseUrls = (
77
url: string,
8-
setBaseUrls: React.Dispatch<React.SetStateAction<string[]>>
8+
setBaseUrls: React.Dispatch<React.SetStateAction<Map<string, string>>>
99
) => {
1010
const parsedUrl = new URL(url);
1111
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.hostname}`;
1212
if (mapUrl.has(baseUrl)) {
1313
setBaseUrls(prev => {
14-
if (prev.includes(baseUrl)) {
15-
return prev;
16-
}
17-
return [...prev, baseUrl];
14+
const newMap = new Map(prev);
15+
newMap.set(baseUrl, url);
16+
return newMap;
1817
});
1918
}
19+
return baseUrl;
2020
};

src/pages/demo-list/mifosx.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
} from 'lucide-react';
2121
import { useNavigate } from 'react-router-dom';
2222
import slugify from 'slugify';
23-
import { fetchDemoListData } from '@/lib/api/fetchDemoListData';
23+
// import { fetchDemoListData } from '@/lib/api/fetchDemoListData';
24+
import { DemoSampleData } from '@/data/DemoTableSampleData';
2425

2526
interface DemoData {
2627
demoID: string;
@@ -42,10 +43,11 @@ export default function MifosXDemos() {
4243

4344
useEffect(() => {
4445
setLoading(true);
45-
fetchDemoListData()
46-
.then(setData)
47-
.catch(console.error)
48-
.finally(() => setLoading(false));
46+
setData(DemoSampleData);
47+
setLoading(false);
48+
// fetchDemoListData()
49+
// .then(setData)
50+
// .finally(() => setLoading(false));
4951
}, []);
5052

5153
const columns = useMemo(

src/pages/demo/demo-page.tsx

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,30 @@ interface Demo {
2929
export 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

Comments
 (0)