Skip to content

Commit 36d6b56

Browse files
committed
Remember the state
Signed-off-by: David Gageot <[email protected]>
1 parent f551664 commit 36d6b56

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/extension/ui/src/components/tabs/ToolCatalog.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { v1 } from '@docker/extension-api-client-types';
22
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
33
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
44
import { Collapse, Grid2, Typography } from '@mui/material';
5-
import React, { useMemo, useState } from 'react';
5+
import React, { useEffect, useMemo, useState } from 'react';
66
import { CATALOG_LAYOUT_SX } from '../../Constants';
77
import { useCatalogAll } from '../../queries/useCatalog';
88
import Tile from '../tile/Index';
@@ -19,8 +19,8 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
1919
sort,
2020
}) => {
2121
const { catalogItems, registryLoading } = useCatalogAll(client);
22-
const [expandedEnabled, setExpandedEnabled] = useState(true);
23-
const [expandedNotEnabled, setExpandedNotEnabled] = useState(true);
22+
const [expandedEnabled, setExpandedEnabled] = useState(localStorage.getItem('expandedEnabled') !== 'false');
23+
const [expandedNotEnabled, setExpandedNotEnabled] = useState(localStorage.getItem('expandedNotEnabled') !== 'false');
2424

2525
// Memoize the filtered catalog items to prevent unnecessary recalculations
2626
const result = useMemo(() => {
@@ -44,10 +44,14 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
4444
<Typography
4545
variant='subtitle2'
4646
sx={{ color: "text.secondary", display: "flex", alignItems: "center", cursor: "pointer" }}
47-
onClick={() => setExpandedEnabled(!expandedEnabled)}>
47+
onClick={() => {
48+
const newExpanded = !expandedEnabled
49+
setExpandedEnabled(newExpanded);
50+
localStorage.setItem('expandedEnabled', JSON.stringify(newExpanded));
51+
}}>
4852
Enabled tools
4953
{expandedEnabled ? <KeyboardArrowDownIcon fontSize="small" /> : <KeyboardArrowRightIcon fontSize="small" />}
50-
</Typography>
54+
</Typography >
5155

5256
<Collapse in={expandedEnabled}>
5357
<Grid2 container spacing={1} sx={CATALOG_LAYOUT_SX}>
@@ -68,7 +72,11 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
6872
<Typography
6973
variant='subtitle2'
7074
sx={{ color: "text.secondary", display: "flex", alignItems: "center", cursor: "pointer" }}
71-
onClick={() => setExpandedNotEnabled(!expandedNotEnabled)}>
75+
onClick={() => {
76+
const newExpanded = !expandedNotEnabled
77+
setExpandedNotEnabled(newExpanded);
78+
localStorage.setItem('expandedNotEnabled', JSON.stringify(newExpanded));
79+
}}>
7280
All the tools
7381
{expandedNotEnabled ? <KeyboardArrowDownIcon fontSize="small" /> : <KeyboardArrowRightIcon fontSize="small" />}
7482
</Typography>

0 commit comments

Comments
 (0)