diff --git a/src/zotero_kb/templates/index.html b/src/zotero_kb/templates/index.html index 00760b4..ac59792 100644 --- a/src/zotero_kb/templates/index.html +++ b/src/zotero_kb/templates/index.html @@ -400,6 +400,7 @@ const state = { projects: [], currentProjectId: null, + currentProjectName: null, currentCards: [], collectionTree: [], isImportModalOpen: false, @@ -582,10 +583,21 @@ elements.selectedCount.textContent = `已选 ${state.selectedItemKeys.size} 篇`; } + function syncCurrentProjectLabels() { + if (state.currentProjectName) { + const label = `当前项目:${state.currentProjectName}`; + elements.currentProjectLabel.textContent = label; + elements.importModalProjectLabel.textContent = label; + return; + } + elements.currentProjectLabel.textContent = "当前未选择项目。"; + elements.importModalProjectLabel.textContent = "未选择项目"; + } + function updateImportActionState() { const hasProject = Boolean(state.currentProjectId); const hasSelection = state.selectedItemKeys.size > 0; - elements.importModalProjectLabel.textContent = hasProject ? `当前项目:${state.currentProjectId}` : "未选择项目"; + syncCurrentProjectLabels(); elements.importSelectedItemsButton.disabled = !hasProject || !hasSelection; elements.importSelectedItemsButton.title = !hasProject ? "请先选择项目" : (hasSelection ? "" : "请先选择文献"); elements.selectDescendantsButton.disabled = !state.visibleCollectionItems.length; @@ -709,7 +721,6 @@
${item.title}
${item.item_key} · ${item.year || "-"} · ${item.item_type || "-"}
-

${item.abstract || "暂无摘要"}

`; row.querySelector("input").addEventListener("change", () => toggleItemSelection(item.item_key)); @@ -843,19 +854,19 @@ if (!state.currentProjectId && projects.length) { state.currentProjectId = projects[0].id; } + state.currentProjectName = state.projects.find((project) => project.id === state.currentProjectId)?.name || null; renderProjects(); updateImportActionState(); if (state.currentProjectId) { await selectProject(state.currentProjectId, false); return; } - elements.currentProjectLabel.textContent = "当前未选择项目。"; renderCards([]); } async function selectProject(projectId, rerender = true) { state.currentProjectId = projectId; - elements.currentProjectLabel.textContent = `当前项目:${projectId}`; + state.currentProjectName = state.projects.find((project) => project.id === projectId)?.name || projectId; updateImportActionState(); if (rerender) { renderProjects(); diff --git a/tests/test_ui.py b/tests/test_ui.py index ee2ff68..a576122 100644 --- a/tests/test_ui.py +++ b/tests/test_ui.py @@ -41,7 +41,9 @@ def test_index_contains_import_modal_controls(tmp_path) -> None: assert 'id="item-preview-popover"' in html assert 'const ABSTRACT_PREVIEW_DELAY_MS = 3000;' in html assert 'isImportModalOpen: false' in html + assert "currentProjectName: null" in html assert "function openImportModal()" in html assert "function closeImportModal()" in html assert "function updateImportActionState()" in html assert 'document.body.classList.toggle("modal-open"' in html + assert "${item.abstract" not in html