mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: get visible nodes properly
This commit is contained in:
parent
8cb16fff6c
commit
ec78f36e67
2 changed files with 20 additions and 13 deletions
|
|
@ -40,17 +40,17 @@ export function useVisibleNodesGenerator(metaData: MetaData) {
|
|||
|
||||
setStateContext('tree-rendering')
|
||||
|
||||
const visibleNodesGenerator = new VisibleNodesGenerator({
|
||||
root: treeRoot,
|
||||
defer,
|
||||
compress: config.compressSingletonFolder,
|
||||
async getTreeData(path) {
|
||||
const { root } = await platform.getTreeData(metaData, path, false, accessToken)
|
||||
return root
|
||||
},
|
||||
})
|
||||
|
||||
setVisibleNodesGenerator(visibleNodesGenerator)
|
||||
setVisibleNodesGenerator(
|
||||
new VisibleNodesGenerator({
|
||||
root: treeRoot,
|
||||
defer,
|
||||
compress: config.compressSingletonFolder,
|
||||
async getTreeData(path) {
|
||||
const { root } = await platform.getTreeData(metaData, path, false, accessToken)
|
||||
return root
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
setStateContext('tree-rendered')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,7 +2,14 @@ import { useEffect, useState } from 'react'
|
|||
import { VisibleNodes, VisibleNodesGenerator } from 'utils/VisibleNodesGenerator'
|
||||
|
||||
export function useVisibleNodes(visibleNodesGenerator: VisibleNodesGenerator | null) {
|
||||
const [visibleNodes, setVisibleNodes] = useState<VisibleNodes | null>(null)
|
||||
useEffect(() => visibleNodesGenerator?.onUpdate(setVisibleNodes), [visibleNodesGenerator])
|
||||
const [visibleNodes, setVisibleNodes] = useState<VisibleNodes | null>(
|
||||
visibleNodesGenerator?.visibleNodes || null,
|
||||
)
|
||||
useEffect(() => {
|
||||
const $visibleNodes = visibleNodesGenerator?.visibleNodes || null
|
||||
if (visibleNodes !== $visibleNodes) setVisibleNodes($visibleNodes)
|
||||
|
||||
return visibleNodesGenerator?.onUpdate(setVisibleNodes)
|
||||
}, [visibleNodesGenerator]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
return visibleNodes
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue