@@ -12,10 +12,6 @@ import { FolderOpenRounded, } from '@mui/icons-material';
12
12
13
13
const NEVER_SHOW_AGAIN_KEY = 'registry-sync-never-show-again' ;
14
14
15
- type RegistryItem = {
16
- ref : string ;
17
- }
18
-
19
15
const client = createDockerDesktopClient ( ) ;
20
16
21
17
const CATALOG_URL = 'https://raw.githubusercontent.com/docker/labs-ai-tools-for-devs/refs/heads/main/prompts/catalog.yaml'
@@ -29,16 +25,26 @@ export function App() {
29
25
const [ showReloadModal , setShowReloadModal ] = useState ( false ) ;
30
26
const [ hasConfig , setHasConfig ] = useState ( false ) ;
31
27
32
- const loadCatalog = async ( ) => {
28
+ const loadCatalog = async ( showNotification = true ) => {
29
+ const cachedCatalog = localStorage . getItem ( 'catalog' ) ;
33
30
try {
34
31
const response = await fetch ( CATALOG_URL ) ;
35
32
const catalog = await response . text ( ) ;
36
33
const items = parse ( catalog ) [ 'registry' ] as { [ key : string ] : CatalogItem }
37
34
const itemsWithName = Object . entries ( items ) . map ( ( [ name , item ] ) => ( { name, ...item } ) ) ;
38
35
setCatalogItems ( itemsWithName ) ;
36
+ localStorage . setItem ( 'catalog' , JSON . stringify ( itemsWithName ) ) ;
37
+ if ( showNotification ) {
38
+ client . desktopUI . toast . success ( 'Catalog updated successfully.' ) ;
39
+ }
39
40
}
40
41
catch ( error ) {
41
- client . desktopUI . toast . error ( 'Failed to get latest catalog: ' + error ) ;
42
+ if ( cachedCatalog ) {
43
+ setCatalogItems ( JSON . parse ( cachedCatalog ) ) ;
44
+ }
45
+ if ( showNotification ) {
46
+ client . desktopUI . toast . error ( `Failed to get latest catalog.${ cachedCatalog ? ' Using cached catalog.' : '' } ` + error ) ;
47
+ }
42
48
}
43
49
}
44
50
@@ -106,7 +112,7 @@ export function App() {
106
112
loadCatalog ( ) ;
107
113
loadRegistry ( ) ;
108
114
const interval = setInterval ( ( ) => {
109
- loadCatalog ( ) ;
115
+ loadCatalog ( false ) ;
110
116
loadRegistry ( ) ;
111
117
} , 30000 )
112
118
return ( ) => {
0 commit comments