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
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
gargantext
purescript-gargantext
Commits
3c163dc8
Unverified
Commit
3c163dc8
authored
Jul 02, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Loader2] working
parent
bb8227db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
17 deletions
+24
-17
Loader2.purs
src/Gargantext/Components/Loader2.purs
+16
-12
Tree.purs
src/Gargantext/Components/Tree.purs
+8
-5
No files found.
src/Gargantext/Components/Loader2.purs
View file @
3c163dc8
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 Effect.Aff (Aff, launchAff, launchAff_, killFiber)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Reactix as R
type State path loaded = { currentPath :: path, loaded :: Maybe loaded }
...
...
@@ -15,22 +15,26 @@ useLoader
. Eq path
=> Show path
=> path
-> (path ->
Effect
loaded)
-> (path -> loaded ->
Array
R.Element)
-> R.Hooks
(Array R.Element)
-> (path ->
Aff
loaded)
-> (path -> loaded -> R.Element)
-> R.Hooks
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
R.useEffect $ \_ ->
if (isNothing loaded || newPath /= currentPath) then do
logs $ "useLoader " <> show {newPath, currentPath, loadedIsNothing: isNothing loaded}
freshlyLoaded <- loader newPath
setState { currentPath: newPath, loaded: Just freshlyLoaded }
fiber <- launchAff do
freshlyLoaded <- loader newPath
liftEffect $ setState { currentPath: newPath, loaded: Just freshlyLoaded }
pure $ \_ -> launchAff_ $ killFiber (error "useLoader") fiber
else do
pure $ \_ -> pure unit
pure case loaded of
Nothing ->
-- TODO load spinner
[]
R.fragment
[]
Just loadedData ->
render currentPath loadedData
src/Gargantext/Components/Tree.purs
View file @
3c163dc8
...
...
@@ -229,10 +229,12 @@ treeview :: Spec {} Props Void
treeview = simpleSpec defaultPerformAction render
where
render :: Render {} Props Void
render _ {root} _ _ =
R.hooksComponent "TreeView" \props children ->
render _ props _ _ = [R2.scuff $ R.createElement cpt props []]
cpt =
R.hooksComponent "TreeView" \{root} _children ->
useLoader root loadNode \currentPath loaded ->
R
eact.createElement treeViewClass {tree: loaded}
R
2.buff $ React.createElement treeViewClass {tree: loaded} []
--nodePopupView :: forall s. (Action -> Effect Unit) -> FTree -> RAction s -> R.Element
...
...
@@ -588,8 +590,9 @@ fldr :: Boolean -> String
fldr open = if open then "fas fa-folder-open" else "fas fa-folder"
loadNode :: ID -> Effect FTree
loadNode a = lift ((get <<< toUrl Back Tree <<< Just) a)
loadNode :: ID -> Aff FTree
-- loadNode a = lift ((get <<< toUrl Back Tree <<< Just) a)
loadNode = get <<< toUrl Back Tree <<< Just
----- 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