Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
bb8227db
Unverified
Commit
bb8227db
authored
Jun 25, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP loader2
parent
2dad09a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
17 deletions
+47
-17
Loader2.purs
src/Gargantext/Components/Loader2.purs
+36
-0
Tree.purs
src/Gargantext/Components/Tree.purs
+11
-17
No files found.
src/Gargantext/Components/Loader2.purs
0 → 100644
View file @
bb8227db
module Gargantext.Components.Loader2 where
--import Control.Monad.Cont.Trans (lift)
import Data.Maybe (Maybe(..), isNothing)
import Data.Tuple.Nested ((/\))
import Gargantext.Prelude
import Effect (Effect)
--import Effect.Aff (Aff)
import Reactix as R
type State path loaded = { currentPath :: path, loaded :: Maybe loaded }
useLoader
:: forall path loaded
. Eq path
=> Show path
=> path
-> (path -> Effect loaded)
-> (path -> loaded -> Array R.Element)
-> R.Hooks (Array R.Element)
useLoader newPath loader render = do
{currentPath, loaded} /\ setState <- R.useState' { currentPath: newPath, loaded: Nothing }
-- What about cleanup handlers?
R.useEffect' $ \_ ->
when (isNothing loaded || newPath /= currentPath) do
logs $ "useLoader " <> show {newPath, currentPath, loadedIsNothing: isNothing loaded}
freshlyLoaded <- loader newPath
setState { currentPath: newPath, loaded: Just freshlyLoaded }
pure case loaded of
Nothing ->
-- TODO load spinner
[]
Just loadedData ->
render currentPath loadedData
src/Gargantext/Components/Tree.purs
View file @
bb8227db
...
...
@@ -19,7 +19,7 @@ import Effect.Class (liftEffect)
import Effect.Exception (error)
import Effect.Uncurried (mkEffectFn1)
import FFI.Simple ((..), (.=))
import Gargantext.Components.Loader
as Loader
import Gargantext.Components.Loader
2 (useLoader)
import Gargantext.Config (toUrl, End(..), NodeType(..), readNodeType)
import Gargantext.Config.REST (get, put, post, postWwwUrlencoded, delete)
import Gargantext.Types (class ToQuery, toQuery)
...
...
@@ -209,12 +209,12 @@ nodeOptionsRename d activated id = case activated of
]
false -> []
type
LoadedTreeViewProps = Loader.InnerProps Int FTree ()
type
TreeViewProps = { tree :: FTree }
loadedTreeview :: Spec State
Loaded
TreeViewProps Action
loadedTreeview :: Spec State TreeViewProps Action
loadedTreeview = simpleSpec performAction render
where
render :: Render State
Loaded
TreeViewProps Action
render :: Render State TreeViewProps Action
render dispatch _ {state, currentNode} _ =
[ div [className "tree"]
[ --toHtml dispatch state currentNode
...
...
@@ -222,23 +222,17 @@ loadedTreeview = simpleSpec performAction render
]
]
treeViewClass :: ReactClass (Loader.InnerProps Int FTree (children :: React.Children))
treeViewClass = createClass "TreeView" loadedTreeview (\{loaded: t} -> {state: t, currentNode: Nothing})
treeLoaderClass :: Loader.LoaderClass Int FTree
treeLoaderClass = Loader.createLoaderClass "TreeLoader" loadNode
treeLoader :: Loader.Props' Int FTree -> ReactElement
treeLoader props = React.createElement treeLoaderClass props []
treeViewClass :: ReactClass { tree :: FTree, children :: React.Children }
treeViewClass = createClass "TreeView" loadedTreeview (\{tree} -> {state: tree, currentNode: Nothing})
treeview :: Spec {} Props Void
treeview = simpleSpec defaultPerformAction render
where
render :: Render {} Props Void
render _ {root} _ _ =
[ treeLoader { path: root
, component: treeViewClass
} ]
R.hooksComponent "TreeView" \props children ->
useLoader root loadNode \currentPath loaded ->
React.createElement treeViewClass {tree: loaded}
--nodePopupView :: forall s. (Action -> Effect Unit) -> FTree -> RAction s -> R.Element
...
...
@@ -594,8 +588,8 @@ fldr :: Boolean -> String
fldr open = if open then "fas fa-folder-open" else "fas fa-folder"
loadNode :: ID ->
Aff
FTree
loadNode
= get <<< toUrl Back Tree <<< Just
loadNode :: ID ->
Effect
FTree
loadNode
a = lift ((get <<< toUrl Back Tree <<< Just) a)
----- TREE CRUD Operations
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment