@@ -12,10 +12,6 @@ import { FolderOpenRounded, } from '@mui/icons-material';
1212
1313const NEVER_SHOW_AGAIN_KEY = 'registry-sync-never-show-again' ;
1414
15- type RegistryItem = {
16- ref : string ;
17- }
18-
1915const client = createDockerDesktopClient ( ) ;
2016
2117const 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() {
2925 const [ showReloadModal , setShowReloadModal ] = useState ( false ) ;
3026 const [ hasConfig , setHasConfig ] = useState ( false ) ;
3127
32- const loadCatalog = async ( ) => {
28+ const loadCatalog = async ( showNotification = true ) => {
29+ const cachedCatalog = localStorage . getItem ( 'catalog' ) ;
3330 try {
3431 const response = await fetch ( CATALOG_URL ) ;
3532 const catalog = await response . text ( ) ;
3633 const items = parse ( catalog ) [ 'registry' ] as { [ key : string ] : CatalogItem }
3734 const itemsWithName = Object . entries ( items ) . map ( ( [ name , item ] ) => ( { name, ...item } ) ) ;
3835 setCatalogItems ( itemsWithName ) ;
36+ localStorage . setItem ( 'catalog' , JSON . stringify ( itemsWithName ) ) ;
37+ if ( showNotification ) {
38+ client . desktopUI . toast . success ( 'Catalog updated successfully.' ) ;
39+ }
3940 }
4041 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+ }
4248 }
4349 }
4450
@@ -106,7 +112,7 @@ export function App() {
106112 loadCatalog ( ) ;
107113 loadRegistry ( ) ;
108114 const interval = setInterval ( ( ) => {
109- loadCatalog ( ) ;
115+ loadCatalog ( false ) ;
110116 loadRegistry ( ) ;
111117 } , 30000 )
112118 return ( ) => {
0 commit comments