Skip to content

Commit 8380a6d

Browse files
author
colinmcneil
committed
Cache catalog
Resolves #42
1 parent 3d51ce8 commit 8380a6d

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/extension/ui/src/App.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import { FolderOpenRounded, } from '@mui/icons-material';
1212

1313
const NEVER_SHOW_AGAIN_KEY = 'registry-sync-never-show-again';
1414

15-
type RegistryItem = {
16-
ref: string;
17-
}
18-
1915
const client = createDockerDesktopClient();
2016

2117
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() {
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 () => {

src/extension/ui/src/components/ClaudeConfigSyncStatus.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,17 @@ export const ClaudeConfigSyncStatus = ({ client, setHasConfig }: { client: v1.Do
6868
const [configPath, setConfigPath] = useState<string | null>(null)
6969
useEffect(() => {
7070
const refreshConfig = async () => {
71-
const cachedConfig = localStorage.getItem('claude-config')
7271
try {
73-
const config = cachedConfig ? JSON.parse(cachedConfig) : await getClaudeConfig(client)
72+
const config = await getClaudeConfig(client)
7473
const newConfig = JSON.parse(config)
7574
setClaudeConfig(newConfig)
76-
// Dumb cache, no way to see if config changed
77-
localStorage.setItem('claude-config', config)
75+
7876
} catch (error) {
7977
console.error('Error parsing config. Using cached config if available.', error)
80-
if (cachedConfig) {
81-
setClaudeConfig(JSON.parse(cachedConfig))
82-
}
8378
}
84-
}
8579

80+
}
8681
refreshConfig()
87-
8882
const interval = setInterval(() => {
8983
refreshConfig()
9084
}, 30000)

0 commit comments

Comments
 (0)