@@ -2,36 +2,30 @@ import { v1 } from '@docker/extension-api-client-types';
2
2
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' ;
3
3
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight' ;
4
4
import { Collapse , Grid2 , Typography } from '@mui/material' ;
5
- import React , { useMemo , useState } from 'react' ;
5
+ import React , { useEffect , useMemo , useState } from 'react' ;
6
6
import { CATALOG_LAYOUT_SX } from '../../Constants' ;
7
7
import { useCatalogAll } from '../../queries/useCatalog' ;
8
8
import Tile from '../tile/Index' ;
9
9
10
10
interface ToolCatalogProps {
11
11
search : string ;
12
12
client : v1 . DockerDesktopClient ;
13
- showMine : boolean ;
14
13
sort : 'name-asc' | 'name-desc' ;
15
14
}
16
15
17
16
const ToolCatalog : React . FC < ToolCatalogProps > = ( {
18
17
search,
19
18
client,
20
- showMine,
21
19
sort,
22
20
} ) => {
23
21
const { catalogItems, registryLoading } = useCatalogAll ( client ) ;
24
- const [ expandedEnabled , setExpandedEnabled ] = useState ( true ) ;
25
- const [ expandedNotEnabled , setExpandedNotEnabled ] = useState ( true ) ;
22
+ const [ expandedEnabled , setExpandedEnabled ] = useState ( localStorage . getItem ( 'expandedEnabled' ) !== 'false' ) ;
23
+ const [ expandedNotEnabled , setExpandedNotEnabled ] = useState ( localStorage . getItem ( 'expandedNotEnabled' ) !== 'false' ) ;
26
24
27
25
// Memoize the filtered catalog items to prevent unnecessary recalculations
28
26
const result = useMemo ( ( ) => {
29
27
const filteredItems = catalogItems . filter ( ( item ) => {
30
- const matchesSearch = item . name
31
- . toLowerCase ( )
32
- . includes ( search . toLowerCase ( ) ) ;
33
- const hideBecauseItsNotMine = showMine && ! item . registered ;
34
- return matchesSearch && ! hideBecauseItsNotMine ;
28
+ return item . name . toLowerCase ( ) . includes ( search . toLowerCase ( ) ) ;
35
29
} ) ;
36
30
37
31
return sort === 'name-asc'
@@ -43,19 +37,21 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
43
37
return b . name . localeCompare ( a . name ) ;
44
38
} )
45
39
: filteredItems ;
46
- } , [ catalogItems , search , showMine , sort ] ) ;
47
-
48
-
40
+ } , [ catalogItems , search , sort ] ) ;
49
41
50
42
return (
51
43
< >
52
44
< Typography
53
45
variant = 'subtitle2'
54
- sx = { { color : "text.secondary" , display : "flex" , alignItems : "center" , cursor : "pointer" } }
55
- onClick = { ( ) => setExpandedEnabled ( ! expandedEnabled ) } >
46
+ sx = { { color : "text.secondary" , display : "flex" , alignItems : "center" , cursor : "pointer" , width : 'fit-content' } }
47
+ onClick = { ( ) => {
48
+ const newExpanded = ! expandedEnabled
49
+ setExpandedEnabled ( newExpanded ) ;
50
+ localStorage . setItem ( 'expandedEnabled' , JSON . stringify ( newExpanded ) ) ;
51
+ } } >
56
52
Enabled tools
57
53
{ expandedEnabled ? < KeyboardArrowDownIcon fontSize = "small" /> : < KeyboardArrowRightIcon fontSize = "small" /> }
58
- </ Typography >
54
+ </ Typography >
59
55
60
56
< Collapse in = { expandedEnabled } >
61
57
< Grid2 container spacing = { 1 } sx = { CATALOG_LAYOUT_SX } >
@@ -75,8 +71,12 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
75
71
76
72
< Typography
77
73
variant = 'subtitle2'
78
- sx = { { color : "text.secondary" , display : "flex" , alignItems : "center" , cursor : "pointer" } }
79
- onClick = { ( ) => setExpandedNotEnabled ( ! expandedNotEnabled ) } >
74
+ sx = { { color : "text.secondary" , display : "flex" , alignItems : "center" , cursor : "pointer" , width : 'fit-content' } }
75
+ onClick = { ( ) => {
76
+ const newExpanded = ! expandedNotEnabled
77
+ setExpandedNotEnabled ( newExpanded ) ;
78
+ localStorage . setItem ( 'expandedNotEnabled' , JSON . stringify ( newExpanded ) ) ;
79
+ } } >
80
80
All the tools
81
81
{ expandedNotEnabled ? < KeyboardArrowDownIcon fontSize = "small" /> : < KeyboardArrowRightIcon fontSize = "small" /> }
82
82
</ Typography >
0 commit comments