Skip to content

Commit

Permalink
feat: Add hiddenNodes store and related actions and hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sasamuku committed Dec 16, 2024
1 parent 90fae17 commit d086741
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions frontend/packages/erd-core/src/stores/hiddenNodes/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { hiddenNodesStore } from './store'

export const addHiddenNode = (nodeId: string) => {
if (!hiddenNodesStore.nodes.includes(nodeId)) {
hiddenNodesStore.nodes.push(nodeId)
}
}

export const removeHiddenNode = (nodeId: string) => {
const index = hiddenNodesStore.nodes.indexOf(nodeId)
if (index !== -1) {
hiddenNodesStore.nodes.splice(index, 1)
}
}
7 changes: 7 additions & 0 deletions frontend/packages/erd-core/src/stores/hiddenNodes/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useSnapshot } from 'valtio'
import { hiddenNodesStore } from './store'

export const useHiddenNodesStore = () => {
const { nodes } = useSnapshot(hiddenNodesStore)
return nodes
}
3 changes: 3 additions & 0 deletions frontend/packages/erd-core/src/stores/hiddenNodes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './store'
export * from './actions'
export * from './hooks'
9 changes: 9 additions & 0 deletions frontend/packages/erd-core/src/stores/hiddenNodes/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { proxy } from 'valtio'

type HiddenNodesStore = {
nodes: string[]
}

export const hiddenNodesStore = proxy<HiddenNodesStore>({
nodes: [],
})

0 comments on commit d086741

Please sign in to comment.