fix: dynamic sidebar tree refresh after import

- reloadTreePreservingExpanded no longer replaces the whole tree,
  only patches children of expanded nodes in-place
- New refreshParentNode(nodeId) function updates a single parent's children
- createFile, duplicateItem, confirmImport use refreshParentNode instead of reloadTreePreservingExpanded
- No intermediate render where children are lost
This commit is contained in:
mirivlad 2026-06-03 04:34:27 +08:00
parent 81405ed61b
commit 3c9b9edf8c
3 changed files with 17 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
background: #13131f; background: #13131f;
} }
</style> </style>
<script type="module" crossorigin src="/assets/main-BMgCQPLa.js"></script> <script type="module" crossorigin src="/assets/main-BZ3I06Px.js"></script>
<link rel="stylesheet" crossorigin href="/assets/main-DsSP02cl.css"> <link rel="stylesheet" crossorigin href="/assets/main-DsSP02cl.css">
</head> </head>
<body> <body>

View File

@ -316,7 +316,7 @@
const parentId = currentFolderId || selectedNode.id const parentId = currentFolderId || selectedNode.id
await wailsCall('CreateEmptyFile', parentId, name.trim()) await wailsCall('CreateEmptyFile', parentId, name.trim())
await loadFolder(parentId) await loadFolder(parentId)
await reloadTreePreservingExpanded() await refreshParentNode(parentId)
} catch (e) { } catch (e) {
error = String(e) error = String(e)
} }
@ -327,7 +327,7 @@
await wailsCall('DuplicateNode', id) await wailsCall('DuplicateNode', id)
const parentId = currentFolderId || selectedNode.id const parentId = currentFolderId || selectedNode.id
await loadFolder(parentId) await loadFolder(parentId)
await reloadTreePreservingExpanded() await refreshParentNode(parentId)
} catch (e) { } catch (e) {
error = String(e) error = String(e)
} }
@ -772,16 +772,20 @@
} }
async function reloadTreePreservingExpanded() { async function reloadTreePreservingExpanded() {
workspaceTree = await wailsCall('ListWorkspaceTree') || [] const expandedIds = Object.keys(expanded).filter(id => expanded[id])
for (const nodeId of Object.keys(expanded)) { for (const nodeId of expandedIds) {
if (expanded[nodeId]) { const children = await wailsCall('ListWorkspaceChildren', nodeId) || []
const children = await wailsCall('ListWorkspaceChildren', nodeId) || [] setNodeChildren(workspaceTree, nodeId, children)
setNodeChildren(workspaceTree, nodeId, children)
}
} }
workspaceTree = [...workspaceTree] workspaceTree = [...workspaceTree]
} }
async function refreshParentNode(nodeId) {
const children = await wailsCall('ListWorkspaceChildren', nodeId) || []
setNodeChildren(workspaceTree, nodeId, children)
workspaceTree = [...workspaceTree]
}
// ===== Notes ===== // ===== Notes =====
function openCreateNote() { showCreateNote = true; newNoteTitle = '' } function openCreateNote() { showCreateNote = true; newNoteTitle = '' }
function cancelCreateNote() { showCreateNote = false; newNoteTitle = '' } function cancelCreateNote() { showCreateNote = false; newNoteTitle = '' }
@ -907,7 +911,7 @@
await Promise.all([ await Promise.all([
loadTabData(selectedNode.id), loadTabData(selectedNode.id),
loadFolder(selectedNode.id), loadFolder(selectedNode.id),
reloadTreePreservingExpanded(), refreshParentNode(selectedNode.id),
]) ])
} catch (e) { } catch (e) {
error = String(e) error = String(e)