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
4f0eb144
Commit
4f0eb144
authored
Mar 11, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[toestand] fixes to forest storing state
parent
ddc424fc
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
50 deletions
+60
-50
App.purs
src/Gargantext/Components/App.purs
+3
-0
Forest.purs
src/Gargantext/Components/Forest.purs
+14
-17
Lists.purs
src/Gargantext/Components/Nodes/Lists.purs
+1
-1
Texts.purs
src/Gargantext/Components/Nodes/Texts.purs
+1
-1
Router.purs
src/Gargantext/Components/Router.purs
+25
-13
Reactix.purs
src/Gargantext/Utils/Reactix.purs
+16
-18
No files found.
src/Gargantext/Components/App.purs
View file @
4f0eb144
...
...
@@ -31,5 +31,8 @@ appCpt = here.component "app" cpt where
tasksReductor <- GAT.useTasks boxes.reloadRoot boxes.reloadForest
R.useEffectOnce' $ do
T.write (Just tasksReductor) tasks
R.useEffectOnce' $ do
R2.loadLocalStorageState R2.openNodesKey boxes.forestOpen
T.listen (R2.listenLocalStorageState R2.openNodesKey) boxes.forestOpen
useHashRouter Router.router boxes.route -- Install router to window
pure $ router { boxes, tasks } -- Render router component
src/Gargantext/Components/Forest.purs
View file @
4f0eb144
...
...
@@ -5,7 +5,7 @@ module Gargantext.Components.Forest
, forestLayoutMain
, forestLayoutRaw
, Common
,
Layout
Props
, Props
) where
import Data.Array as A
...
...
@@ -41,18 +41,15 @@ type Common =
, tasks :: T.Box (Maybe GAT.Reductor)
)
type
Layout
Props =
type Props =
( backend :: T.Box (Maybe Backend)
, forestOpen :: T.Box OpenNodes
, reloadForest :: T.Box T2.Reload
, sessions :: T.Box Sessions
, showLogin :: T.Box Boolean
| Common
)
type Props = (
forestOpen :: T.Box OpenNodes
| LayoutProps )
type TreeExtra = (
forestOpen :: T.Box OpenNodes
, session :: Session
...
...
@@ -129,10 +126,10 @@ plus handed showLogin backend = H.div { className: "row" }
"btn btn-primary col-5 " <> switchHanded "ml-1 mr-auto" "mr-1 ml-auto" handed
forestLayout :: R2.Component
Layout
Props
forestLayout :: R2.Component Props
forestLayout = R.createElement forestLayoutCpt
forestLayoutCpt :: R.Component
Layout
Props
forestLayoutCpt :: R.Component Props
forestLayoutCpt = here.component "forestLayout" cpt where
cpt props@{ handed } children =
pure $ R.fragment
...
...
@@ -141,10 +138,10 @@ forestLayoutCpt = here.component "forestLayout" cpt where
-- Renders its first child component in the top bar and the rest in
-- the main view.
forestLayoutWithTopBar :: R2.Component
Layout
Props
forestLayoutWithTopBar :: R2.Component Props
forestLayoutWithTopBar = R.createElement forestLayoutWithTopBarCpt
forestLayoutWithTopBarCpt :: R.Component
Layout
Props
forestLayoutWithTopBarCpt :: R.Component Props
forestLayoutWithTopBarCpt = here.component "forestLayoutWithTopBar" cpt where
cpt props@{ handed } children = do
let { head: topBarChild, tail: mainChildren } =
...
...
@@ -153,19 +150,20 @@ forestLayoutWithTopBarCpt = here.component "forestLayoutWithTopBar" cpt where
[ topBar { handed } [ topBarChild ]
, forestLayoutMain props mainChildren ]
forestLayoutMain :: R2.Component
Layout
Props
forestLayoutMain :: R2.Component Props
forestLayoutMain = R.createElement forestLayoutMainCpt
forestLayoutMainCpt :: R.Component
Layout
Props
forestLayoutMainCpt :: R.Component Props
forestLayoutMainCpt = here.component "forestLayoutMain" cpt where
cpt props children = pure $ forestLayoutRaw props [ mainPage {} children ]
forestLayoutRaw :: R2.Component
Layout
Props
forestLayoutRaw :: R2.Component Props
forestLayoutRaw = R.createElement forestLayoutRawCpt
forestLayoutRawCpt :: R.Component
Layout
Props
forestLayoutRawCpt :: R.Component Props
forestLayoutRawCpt = here.component "forestLayoutRaw" cpt where
cpt p@{ backend
, forestOpen
, frontends
, reloadForest
, reloadRoot
...
...
@@ -174,15 +172,14 @@ forestLayoutRawCpt = here.component "forestLayoutRaw" cpt where
, showLogin
, tasks } children = do
handed' <- T.useLive T.unequal p.handed
forestOpen <- T.useBox $ Set.empty
pure $ R2.row $ reverseHanded
([ H.div { className: "col-md-2 forest-layout-raw-tree" }
[ forest' p.handed
forestOpen
]
[ forest' p.handed ]
] <> children
) handed'
where
forest' handed
forestOpen
=
forest' handed =
forest { backend
, frontends
, forestOpen
...
...
src/Gargantext/Components/Nodes/Lists.purs
View file @
4f0eb144
...
...
@@ -34,7 +34,7 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Lists"
type ListsWithForest =
( forestProps :: Record Forest.
Layout
Props
( forestProps :: Record Forest.Props
, listsProps :: Record CommonProps
)
...
...
src/Gargantext/Components/Nodes/Texts.purs
View file @
4f0eb144
...
...
@@ -41,7 +41,7 @@ here = R2.here "Gargantext.Components.Nodes.Texts"
--------------------------------------------------------
type TextsWithForest = (
forestProps :: Record Forest.
Layout
Props
forestProps :: Record Forest.Props
, textsProps :: Record CommonProps
)
...
...
src/Gargantext/Components/Router.purs
View file @
4f0eb144
...
...
@@ -92,8 +92,16 @@ forested = R.createElement forestedCpt
forestedCpt :: R.Component Props
forestedCpt = here.component "forested" cpt
where
cpt { boxes: { backend, handed, reloadForest, reloadRoot, route, sessions, showLogin }, tasks } children = do
cpt { boxes: { backend
, forestOpen
, handed
, reloadForest
, reloadRoot
, route
, sessions
, showLogin }, tasks } children = do
pure $ forestLayout { backend
, forestOpen
, frontends: defaultFrontends
, handed
, reloadForest
...
...
@@ -189,6 +197,7 @@ lists = R.createElement listsCpt
listsCpt :: R.Component SessionNodeProps
listsCpt = here.component "lists" cpt where
cpt props@{ boxes: { backend
, forestOpen
, handed
, reloadForest
, reloadRoot
...
...
@@ -204,6 +213,7 @@ listsCpt = here.component "lists" cpt where
pure $ authed sessionProps $
Lists.listsWithForest
{ forestProps: { backend
, forestOpen
, frontends
, handed
, reloadForest
...
...
@@ -291,6 +301,7 @@ textsCpt :: R.Component SessionNodeProps
textsCpt = here.component "texts" cpt
where
cpt props@{ boxes: { backend
, forestOpen
, handed
, reloadForest
, reloadRoot
...
...
@@ -306,6 +317,7 @@ textsCpt = here.component "texts" cpt
pure $ authed sessionProps $
Texts.textsWithForest
{ forestProps: { backend
, forestOpen
, frontends
, handed
, route
...
...
src/Gargantext/Utils/Reactix.purs
View file @
4f0eb144
...
...
@@ -35,6 +35,7 @@ import Reactix.DOM.HTML as H
import Reactix.React (react)
import Reactix.SyntheticEvent as RE
import Reactix.Utils (currySecond, hook, tuple)
import Toestand as T
import Unsafe.Coerce (unsafeCoerce)
import Web.File.Blob (Blob)
import Web.File.File as WF
...
...
@@ -327,25 +328,22 @@ openNodesKey = "garg-open-nodes"
type LocalStorageKey = String
useLocalStorageState :: forall s. Argonaut.DecodeJson s => Argonaut.EncodeJson s => LocalStorageKey -> s -> R.Hooks (R.State s)
useLocalStorageState key s = do
-- we need to synchronously get the initial state from local storage
Tuple state setState' <- R.useState \_ -> unsafePerformEffect do
item :: Maybe String <- getItem key =<< getls
loadLocalStorageState :: forall s. Argonaut.DecodeJson s => LocalStorageKey -> T.Box s -> Effect Unit
loadLocalStorageState key cell = do
storage <- getls
item :: Maybe String <- getItem key storage
let json = hush <<< Argonaut.jsonParser =<< item
let parsed = hush <<< Argonaut.decodeJson =<< json
pure $ fromMaybe s parsed
case parsed of
Nothing -> pure unit
Just p -> void $ T.write p cell
let
setState update = do
let new = update state
setState' (\_ -> new)
listenLocalStorageState :: forall s. Argonaut.EncodeJson s => LocalStorageKey -> T.Change s -> Effect Unit
listenLocalStorageState key { old, new } = do
let json = Json.stringify $ Argonaut.encodeJson new
storage <- getls
setItem key json storage
pure (Tuple state setState)
getMessageDataStr :: DE.MessageEvent -> String
getMessageDataStr = getMessageData
...
...
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