Skip to content

Commit 62feb55

Browse files
committed
Lazy load Statistics Modal
1 parent 26e0a4f commit 62feb55

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

frontend/src/components/LinkList.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { lazy, Suspense } from 'react'
2+
13
import { useEffect, useState } from 'react'
24
import { Link } from '../types/api'
35
import { getAllLinks, deleteLink } from '../api/client'
@@ -22,7 +24,7 @@ import {
2224
DialogFooter,
2325
} from "@/components/ui/dialog"
2426

25-
import { StatisticsModal } from "./StatisticsModal"
27+
const StatisticsModal = lazy(() => import('./StatisticsModal'))
2628

2729
interface LinkListProps {
2830
refresh?: number;
@@ -85,13 +87,13 @@ export function LinkList({ refresh = 0 }: LinkListProps) {
8587
const baseUrl = window.location.origin
8688
navigator.clipboard.writeText(`${baseUrl}/${shortCode}`)
8789
toast({
88-
description: (
89-
<>
90-
Link copied to clipboard
91-
<br />
92-
You can add ?source=TextHere to the end of the link to track the source of clicks
93-
</>
94-
),
90+
description: (
91+
<>
92+
Link copied to clipboard
93+
<br />
94+
You can add ?source=TextHere to the end of the link to track the source of clicks
95+
</>
96+
),
9597
})
9698
}
9799

@@ -186,11 +188,15 @@ export function LinkList({ refresh = 0 }: LinkListProps) {
186188
</div>
187189
</CardContent>
188190
</Card>
189-
<StatisticsModal
190-
isOpen={statsModal.isOpen}
191-
onClose={() => setStatsModal({ isOpen: false, linkId: null })}
192-
linkId={statsModal.linkId!}
193-
/>
191+
{statsModal.isOpen && (
192+
<Suspense fallback={<div>Loading...</div>}>
193+
<StatisticsModal
194+
isOpen={statsModal.isOpen}
195+
onClose={() => setStatsModal({ isOpen: false, linkId: null })}
196+
linkId={statsModal.linkId!}
197+
/>
198+
</Suspense>
199+
)}
194200
</>
195201
)
196202
}

frontend/src/components/StatisticsModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const CustomTooltip = ({
5858
return null;
5959
};
6060

61-
export function StatisticsModal({ isOpen, onClose, linkId }: StatisticsModalProps) {
61+
export default function StatisticsModal({ isOpen, onClose, linkId }: StatisticsModalProps) {
6262
const [clicksOverTime, setClicksOverTime] = useState<EnhancedClickStats[]>([]);
6363
const [sourcesData, setSourcesData] = useState<SourceStats[]>([]);
6464
const [loading, setLoading] = useState(true);

0 commit comments

Comments
 (0)