Commit 06a87aa3 authored by Justin Woo's avatar Justin Woo

fix constant remounting of the tree view

parent 33bb55e6
...@@ -41,36 +41,43 @@ treeViewCpt = R.hooksComponent "G.C.Tree.treeView" cpt ...@@ -41,36 +41,43 @@ treeViewCpt = R.hooksComponent "G.C.Tree.treeView" cpt
-- NOTE: this is a hack to reload the tree view on demand -- NOTE: this is a hack to reload the tree view on demand
reload <- R.useState' (0 :: Reload) reload <- R.useState' (0 :: Reload)
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: Set TreeId) openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: Set TreeId)
pure $ treeLoadView reload pure $ treeLoadView
{ root, mCurrentRoute, session, frontends, openNodes } { root, mCurrentRoute, session, frontends, openNodes, reload }
type Props' = ( root :: ID type Props' = ( root :: ID
, mCurrentRoute :: Maybe AppRoute , mCurrentRoute :: Maybe AppRoute
, session :: Session , session :: Session
, frontends :: Frontends , frontends :: Frontends
, openNodes :: R.State (Set TreeId) , openNodes :: R.State (Set TreeId)
, reload :: R.State Reload
) )
treeLoadView :: R.State Reload -> Record Props' -> R.Element treeLoadView :: Record Props' -> R.Element
treeLoadView reload p = R.createElement el p [] treeLoadView p = R.createElement treeLoadView' p []
treeLoadView' :: R.Component Props'
treeLoadView' = R.staticComponent "TreeLoadView" cpt
where where
el = R.staticComponent "TreeLoadView" cpt cpt {root, mCurrentRoute, session, frontends, openNodes, reload} _ = do
cpt {root, mCurrentRoute, session, frontends, openNodes} _ = do
loader root (loadNode session) $ \loaded -> loader root (loadNode session) $ \loaded ->
loadedTreeView reload {tree: loaded, mCurrentRoute, session, frontends, openNodes} loadedTreeView {tree: loaded, mCurrentRoute, session, frontends, openNodes, reload}
type TreeViewProps = ( tree :: FTree type TreeViewProps = ( tree :: FTree
, mCurrentRoute :: Maybe AppRoute , mCurrentRoute :: Maybe AppRoute
, frontends :: Frontends , frontends :: Frontends
, session :: Session , session :: Session
, openNodes :: R.State (Set TreeId) , openNodes :: R.State (Set TreeId)
, reload :: R.State Reload
) )
loadedTreeView :: R.State Reload -> Record TreeViewProps -> R.Element
loadedTreeView reload p = R.createElement el p [] loadedTreeView :: Record TreeViewProps -> R.Element
loadedTreeView p = R.createElement loadedTreeView' p []
loadedTreeView' :: R.Component TreeViewProps
loadedTreeView' = R.hooksComponent "LoadedTreeView" cpt
where where
el = R.hooksComponent "LoadedTreeView" cpt cpt {tree, mCurrentRoute, session, frontends, openNodes, reload} _ = do
cpt {tree, mCurrentRoute, session, frontends, openNodes} _ = do
treeState <- R.useState' {tree, asyncTasks: []} treeState <- R.useState' {tree, asyncTasks: []}
pure $ H.div {className: "tree"} pure $ H.div {className: "tree"}
...@@ -110,9 +117,9 @@ toHtml reload treeState@(ts@{tree: (NTree (LNode {id, name, nodeType}) ary), asy ...@@ -110,9 +117,9 @@ toHtml reload treeState@(ts@{tree: (NTree (LNode {id, name, nodeType}) ary), asy
) )
] ]
onAsyncTaskFinish (AsyncTask {id}) = setTreeState $ const $ ts { asyncTasks = newAsyncTasks } onAsyncTaskFinish (AsyncTask {id: id_}) = setTreeState $ const $ ts { asyncTasks = newAsyncTasks }
where where
newAsyncTasks = A.filter (\(AsyncTask {id: id'}) -> id /= id') asyncTasks newAsyncTasks = A.filter (\(AsyncTask {id: id'}) -> id_ /= id') asyncTasks
childNodes :: Session childNodes :: Session
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment