Skip to content

Commit c625dfb

Browse files
committed
fix: sidebar and button fixes
1 parent 28cbf4d commit c625dfb

File tree

4 files changed

+45
-55
lines changed

4 files changed

+45
-55
lines changed

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/client/components/button.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@
2929
color: rgb(150, 150, 150);
3030
border-color: rgb(207, 207, 211);
3131
}
32+
33+
.flexContainer {
34+
display: flex;
35+
align-items: center;
36+
gap: 8px;
37+
}

src/client/components/button.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@ const Button: FunctionComponent<ButtonProps> = ({
2626
disabled={disabled}
2727
{...rest}
2828
>
29-
<Box display="flex" alignItems="center">
30-
{loading && (
31-
<CircularProgress
32-
size={14}
33-
color="inherit"
34-
sx={{ marginRight: '8px' }}
35-
/>
36-
)}{' '}
29+
<Box display="flex" alignItems="center" gap="8px">
30+
{loading && <CircularProgress size={14} color="inherit" />}
3731
{children}
3832
</Box>
3933
</button>

src/client/sidebar/components/Sidebar.tsx

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const Sidebar = () => {
6060

6161
useEffect(() => {
6262
getImages();
63-
}, [getImages, tab]);
63+
}, [getImages]);
6464

6565
useEffect(() => {
6666
const handleMessage = async (e: MessageEvent) => {
@@ -117,6 +117,13 @@ const Sidebar = () => {
117117
};
118118
}, [getImages]);
119119

120+
const handleTabSwitch = (tabIndex: number) => {
121+
setTab(tabIndex);
122+
if (chartImagesState !== 'loading') {
123+
getImages();
124+
}
125+
};
126+
120127
const handleLoginClick = async () => {
121128
const width = 500;
122129
const height = 650;
@@ -292,7 +299,7 @@ const Sidebar = () => {
292299
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
293300
<Tabs
294301
value={tab}
295-
onChange={(_, newValue) => setTab(newValue)}
302+
onChange={(_, newValue) => handleTabSwitch(newValue)}
296303
aria-label="basic tabs example"
297304
>
298305
<Tab
@@ -324,7 +331,7 @@ const Sidebar = () => {
324331
/>
325332
<Container
326333
sx={{
327-
display: tab === 1 ? 'flex' : 'none',
334+
display: tab === 1 ? 'grid' : 'none',
328335
flexDirection: 'column',
329336
alignItems: 'center',
330337
gap: '20px',
@@ -333,32 +340,36 @@ const Sidebar = () => {
333340
overflowY: 'auto',
334341
}}
335342
>
336-
{chartImagesState !== 'error' &&
337-
(chartImages.length > 0 ? (
338-
chartImages.map((image) => (
339-
<div
340-
key={image.altDescription}
341-
onClick={() =>
342-
handleSelectedImage(image.altDescription)
343-
}
344-
>
345-
<img
346-
src={image.image}
347-
alt={image.altDescription}
348-
style={{
349-
width: '200px',
350-
height: 'auto',
351-
marginBottom: '10px',
352-
cursor: 'pointer',
353-
}}
354-
/>
355-
</div>
356-
))
357-
) : (
343+
{chartImagesState === 'loading' &&
344+
chartImages.length === 0 && (
345+
<CircularProgress sx={{ justifySelf: 'center' }} />
346+
)}
347+
{chartImages.length > 0 &&
348+
chartImages.map((image) => (
349+
<div
350+
key={image.altDescription}
351+
onClick={() =>
352+
handleSelectedImage(image.altDescription)
353+
}
354+
>
355+
<img
356+
src={image.image}
357+
alt={image.altDescription}
358+
style={{
359+
width: '200px',
360+
height: 'auto',
361+
marginBottom: '10px',
362+
cursor: 'pointer',
363+
}}
364+
/>
365+
</div>
366+
))}
367+
{chartImagesState === 'success' &&
368+
chartImages.length === 0 && (
358369
<Typography title="h4" textAlign="center">
359370
No selected diagrams
360371
</Typography>
361-
))}
372+
)}
362373
</Container>
363374
</Box>
364375
</>

0 commit comments

Comments
 (0)