Skip to content

Commit

Permalink
Make useTreeExpansion hook accept expandedKeys as param
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Sep 14, 2024
1 parent c98ea5b commit cb1fe2c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/components/sidebar/tabs/NodeLibrarySidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ import { useNodeBookmarkStore } from '@/stores/nodeBookmarkStore'
const nodeDefStore = useNodeDefStore()
const nodeBookmarkStore = useNodeBookmarkStore()
const { expandedKeys, expandNode, toggleNodeOnEvent } = useTreeExpansion()
const expandedKeys = ref<Record<string, boolean>>({})
const { expandNode, toggleNodeOnEvent } = useTreeExpansion(expandedKeys)
const nodeBookmarkTreeExplorerRef = ref<InstanceType<
typeof NodeBookmarkTreeExplorer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const props = defineProps<{
filteredNodeDefs: ComfyNodeDefImpl[]
}>()
const { expandedKeys, expandNode, toggleNodeOnEvent } = useTreeExpansion()
const expandedKeys = ref<Record<string, boolean>>({})
const { expandNode, toggleNodeOnEvent } = useTreeExpansion(expandedKeys)
const handleNodeClick = (
node: RenderedTreeExplorerNode<ComfyNodeDefImpl>,
Expand Down
7 changes: 2 additions & 5 deletions src/hooks/treeHooks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ref } from 'vue'
import { Ref } from 'vue'
import type { TreeNode } from 'primevue/treenode'

export function useTreeExpansion() {
const expandedKeys = ref<Record<string, boolean>>({})

export function useTreeExpansion(expandedKeys: Ref<Record<string, boolean>>) {
const toggleNode = (node: TreeNode) => {
if (node.key && typeof node.key === 'string') {
if (node.key in expandedKeys.value) {
Expand Down Expand Up @@ -63,7 +61,6 @@ export function useTreeExpansion() {
}

return {
expandedKeys,
toggleNode,
toggleNodeRecursive,
expandNode,
Expand Down

0 comments on commit cb1fe2c

Please sign in to comment.