Skip to content

Commit

Permalink
window.requestAnimationFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshinotsuyoshi committed Dec 24, 2024
1 parent c6bce45 commit 6b72f6a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {
type ERDContentContextState = {
loading: boolean
initializeComplete: boolean
foo: boolean
}

type ERDContentContextActions = {
setLoading: (loading: boolean) => void
setInitializeComplete: (initializeComplete: boolean) => void
setFoo: (foo: boolean) => void
}

type ERDContentConextValue = {
Expand All @@ -25,10 +27,12 @@ const ERDContentContext = createContext<ERDContentConextValue>({
state: {
loading: true,
initializeComplete: false,
foo: false,
},
actions: {
setLoading: () => {},
setInitializeComplete: () => {},
setFoo: () => {},
},
})

Expand All @@ -37,12 +41,13 @@ export const useERDContentContext = () => useContext(ERDContentContext)
export const ERDContentProvider: FC<PropsWithChildren> = ({ children }) => {
const [loading, setLoading] = useState(true)
const [initializeComplete, setInitializeComplete] = useState(false)
const [foo, setFoo] = useState(false)

return (
<ERDContentContext.Provider
value={{
state: { loading, initializeComplete },
actions: { setLoading, setInitializeComplete },
state: { loading, initializeComplete, foo },
actions: { setLoading, setInitializeComplete, setFoo },
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
export const Comment: FC<Props> = ({ comment }) => {
return (
<DrawerDescription className={styles.wrapper}>
<p className={styles.text}>{comment}</p>
<span className={styles.text}>{comment}</span>
</DrawerDescription>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export const useAutoLayout = () => {
})

setNodes([...hiddenNodes, ...newNodes])
setTimeout(() => {
window.requestAnimationFrame(() => {
fitView(fitViewOptions)
setLoading(false)
setInitializeComplete(true)
}, 10)
})
},
[setNodes, fitView, setLoading, setInitializeComplete],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const useInitialAutoLayout = (nodes: Node[]) => {

const {
state: { initializeComplete },
actions: { setFoo },
} = useERDContentContext()
const { handleLayout } = useAutoLayout()

Expand Down Expand Up @@ -65,9 +66,17 @@ export const useInitialAutoLayout = (nodes: Node[]) => {

if (tableNodesInitialized) {
handleLayout(updatedNodes, updatedEdges, fitViewOptions)
setFoo(true) // make effect
}
}

initialize()
}, [tableNodesInitialized, initializeComplete, handleLayout, nodes, getEdges])
}, [
tableNodesInitialized,
initializeComplete,
handleLayout,
nodes,
getEdges,
setFoo,
])
}

0 comments on commit 6b72f6a

Please sign in to comment.