diff --git a/src/zotero_kb/templates/index.html b/src/zotero_kb/templates/index.html index f3a95c6..140f6f9 100644 --- a/src/zotero_kb/templates/index.html +++ b/src/zotero_kb/templates/index.html @@ -495,7 +495,6 @@ currentCards: [], collectionTree: [], isImportWindowOpen: false, - isImportWindowOpen: false, windowX: typeof windowSessionState.x === "number" ? windowSessionState.x : null, windowY: typeof windowSessionState.y === "number" ? windowSessionState.y : null, windowWidth: typeof windowSessionState.width === "number" ? windowSessionState.width : null, @@ -1140,8 +1139,7 @@ } async function loadImportState() { - const resp = await fetch(`/api/projects/${state.currentProjectId}/import-state`); - const data = await resp.json(); + const data = await api(`/api/projects/${state.currentProjectId}/import-state`); state.importItems = data.items; renderImportItemList(); updateImportCounts(data.pending_count, data.done_count); @@ -1159,7 +1157,7 @@
${escapeHtml(item.title)}
-
${item.creators.join(', ')} · ${item.year || 'n.d.'}
+
${escapeHtml(item.creators.join(', '))} · ${escapeHtml(item.year || 'n.d.')}
`; if (!isDone) { @@ -1178,7 +1176,7 @@ function showItemPreview(item) { document.getElementById('item-preview').innerHTML = `
${escapeHtml(item.title)}
-
${item.creators.join(', ')} · ${item.year || 'n.d.'} · ${item.item_type}
+
${escapeHtml(item.creators.join(', '))} · ${escapeHtml(item.year || 'n.d.')} · ${escapeHtml(item.item_type)}
${escapeHtml(item.abstract || 'No abstract available.')}
`; } @@ -1200,12 +1198,10 @@ updateGenerateButton(); try { - const resp = await fetch(`/api/projects/${state.currentProjectId}/cards/generate`, { + const data = await api(`/api/projects/${state.currentProjectId}/cards/generate`, { method: 'POST', - headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ item_keys: keys }), }); - const data = await resp.json(); data.items.forEach(updated => { const item = state.importItems.find(i => i.item_key === updated.item_key); @@ -1220,6 +1216,8 @@ done: state.importItems.filter(i => i.card_status === 'done').length, }; updateImportCounts(counts.pending, counts.done); + } catch (error) { + setStatus(elements.windowCollectionStatus, error.message, true); } finally { state.isGenerating = false; updateGenerateButton();