Skip to content

Commit 8d8f49d

Browse files
committed
Added loader state for the recent sections
1 parent fd59d86 commit 8d8f49d

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

src/client/sidebar/components/Sidebar.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ interface ChartImage {
2525

2626
const Sidebar = () => {
2727
const [tab, setTab] = useState(0);
28+
const [tabRefreshCount, setTabRefreshCount] = useState(0);
29+
const [iframeLoading, setIframeLoading] = useState(true);
2830
const [overlayEnabled, setOverlayEnabled] = useState(false);
2931
const intervalRef = useRef<number | null>(null);
3032
const [diagramsUrl, setDiagramsUrl] = useState<string>('');
@@ -52,6 +54,7 @@ const Sidebar = () => {
5254
authState.token
5355
);
5456
setDiagramsUrl(url);
57+
setIframeLoading(true);
5558
if (intervalRef.current !== null) {
5659
clearInterval(intervalRef?.current);
5760
intervalRef.current = null;
@@ -259,6 +262,10 @@ const Sidebar = () => {
259262
};
260263

261264
const handleTabSwitch = (tabIndex: number) => {
265+
if (tabIndex === 0 && tab !== 0) {
266+
setTabRefreshCount((prev) => prev + 1);
267+
setIframeLoading(true);
268+
}
262269
setTab(tabIndex);
263270
if (chartImagesState !== 'loading') {
264271
getImages();
@@ -628,15 +635,50 @@ const Sidebar = () => {
628635
</Box>
629636
</Box>
630637

638+
{tab === 0 && iframeLoading && (
639+
<Box
640+
sx={{
641+
display: 'flex',
642+
flexDirection: 'column',
643+
justifyContent: 'center',
644+
alignItems: 'center',
645+
height: 'calc(100vh - 300px)',
646+
backgroundColor: 'transparent',
647+
gap: '16px',
648+
}}
649+
>
650+
<CircularProgress
651+
size={48}
652+
sx={{
653+
color: '#1E1A2E',
654+
}}
655+
/>
656+
<Typography
657+
sx={{
658+
fontFamily: 'Recursive',
659+
fontWeight: 500,
660+
fontSize: '16px',
661+
lineHeight: '24px',
662+
color: '#5F5D7A',
663+
textAlign: 'center',
664+
margin: 0,
665+
}}
666+
>
667+
Loading recent diagrams...
668+
</Typography>
669+
</Box>
670+
)}
631671
<iframe
672+
key={tabRefreshCount}
632673
src={diagramsUrl}
633674
title="diagrams"
675+
onLoad={() => setIframeLoading(false)}
634676
style={{
635677
border: 'none',
636678
width: '100%',
637679
height: 'calc(100vh - 300px)',
638680
backgroundColor: '#ffffff',
639-
display: tab === 0 ? 'block' : 'none',
681+
display: tab === 0 && !iframeLoading ? 'block' : 'none',
640682
borderRadius: '16px',
641683
}}
642684
/>
@@ -797,6 +839,7 @@ const Sidebar = () => {
797839
alignItems: 'center',
798840
justifyContent: 'center',
799841
padding: '16px',
842+
boxSizing: 'border-box',
800843
cursor: 'pointer',
801844
}}
802845
onClick={() =>
@@ -820,6 +863,7 @@ const Sidebar = () => {
820863
width: '100%',
821864
height: '48px',
822865
padding: '8px 16px',
866+
boxSizing: 'border-box',
823867
display: 'flex',
824868
justifyContent: 'center',
825869
alignItems: 'center',

0 commit comments

Comments
 (0)