fix(explorer): properly respect folderDefaultState (closes #1827)
This commit is contained in:
parent
580c1bd608
commit
c005fe4408
1 changed files with 9 additions and 5 deletions
|
@ -161,7 +161,7 @@ async function setupExplorer(currentSlug: FullSlug) {
|
||||||
// Get folder state from local storage
|
// Get folder state from local storage
|
||||||
const storageTree = localStorage.getItem("fileTree")
|
const storageTree = localStorage.getItem("fileTree")
|
||||||
const serializedExplorerState = storageTree && opts.useSavedState ? JSON.parse(storageTree) : []
|
const serializedExplorerState = storageTree && opts.useSavedState ? JSON.parse(storageTree) : []
|
||||||
const oldIndex = new Map(
|
const oldIndex = new Map<string, boolean>(
|
||||||
serializedExplorerState.map((entry: FolderState) => [entry.path, entry.collapsed]),
|
serializedExplorerState.map((entry: FolderState) => [entry.path, entry.collapsed]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -186,10 +186,14 @@ async function setupExplorer(currentSlug: FullSlug) {
|
||||||
|
|
||||||
// Get folder paths for state management
|
// Get folder paths for state management
|
||||||
const folderPaths = trie.getFolderPaths()
|
const folderPaths = trie.getFolderPaths()
|
||||||
currentExplorerState = folderPaths.map((path) => ({
|
currentExplorerState = folderPaths.map((path) => {
|
||||||
path,
|
const previousState = oldIndex.get(path)
|
||||||
collapsed: oldIndex.get(path) === true,
|
return {
|
||||||
}))
|
path,
|
||||||
|
collapsed:
|
||||||
|
previousState === undefined ? opts.folderDefaultState === "collapsed" : previousState,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const explorerUl = explorer.querySelector(".explorer-ul")
|
const explorerUl = explorer.querySelector(".explorer-ul")
|
||||||
if (!explorerUl) continue
|
if (!explorerUl) continue
|
||||||
|
|
Loading…
Add table
Reference in a new issue