refactor: derive modal project label from canonical state

This commit is contained in:
Saberlve 2026-04-15 12:53:04 +08:00
parent 1660e1203d
commit 3667e313a4
2 changed files with 3 additions and 11 deletions

View File

@ -379,7 +379,6 @@
</main>
<script>
const ABSTRACT_PREVIEW_DELAY_MS = 3000;
const IMPORT_SESSION_STORAGE_KEY = "zotero-kb.import-modal";
function readImportSessionState() {
@ -400,7 +399,6 @@
const state = {
projects: [],
currentProjectId: null,
currentProjectName: null,
currentCards: [],
collectionTree: [],
isImportModalOpen: false,
@ -596,8 +594,9 @@
}
function syncCurrentProjectLabels() {
if (state.currentProjectName) {
const label = `当前项目:${state.currentProjectName}`;
const currentProject = state.projects.find((project) => project.id === state.currentProjectId) || null;
if (currentProject) {
const label = `当前项目:${currentProject.name}`;
elements.currentProjectLabel.textContent = label;
elements.importModalProjectLabel.textContent = label;
return;
@ -921,7 +920,6 @@
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) {
@ -933,7 +931,6 @@
async function selectProject(projectId, rerender = true) {
state.currentProjectId = projectId;
state.currentProjectName = state.projects.find((project) => project.id === projectId)?.name || projectId;
updateImportActionState();
if (rerender) {
renderProjects();

View File

@ -39,13 +39,8 @@ def test_index_contains_import_modal_controls(tmp_path) -> None:
assert 'id="modal-clear-selection-button"' in html
assert 'id="modal-import-selected-items-button"' in html
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 "collectionItemsLoaded: false" in html
assert "nextCollectionItemsRequestToken: 0" in html
assert "function openImportModal()" in html
assert "function closeImportModal()" in html
assert "function updateImportActionState()" in html
assert "function normalizeSelectedCollectionKey()" in html
assert 'document.body.classList.toggle("modal-open"' in html