App.purs 1.4 KB
Newer Older
James Laver's avatar
James Laver committed
1
module Gargantext.Components.App (app) where
2

3 4
import Reactix as R
import Toestand as T
James Laver's avatar
James Laver committed
5

6 7 8
import Gargantext.Prelude

import Gargantext.AsyncTasks as GAT
James Laver's avatar
James Laver committed
9 10 11 12
import Gargantext.Components.App.Data (emptyApp)
import Gargantext.Components.Router (router)
import Gargantext.Hooks (useHashRouter)
import Gargantext.Router as Router
13
import Gargantext.Sessions as Sessions
14
import Gargantext.Utils.Reactix as R2
James Laver's avatar
James Laver committed
15

16 17
here :: R2.Here
here = R2.here "Gargantext.Components.App"
18

19 20
app :: R2.Component ()
app = R.createElement appCpt
21 22

appCpt :: R.Component ()
23
appCpt = here.component "app" cpt where
24
  cpt _ _ = do
25 26
    box    <- T.useBox emptyApp             -- global data
    boxes <- T.useFocusedFields box {}      -- read-write access for children
27
    -- tasks   <- T.useBox Nothing             -- storage for asynchronous tasks reductor
28
    R.useEffectOnce' $ do
29
      void $ Sessions.load boxes.sessions
30 31 32 33
    -- tasks <- GAT.useTasks boxes.reloadRoot boxes.reloadForest
    R.useEffectOnce' $ do
      tasksStorage <- GAT.getAsyncTasks
      T.write_ tasksStorage boxes.tasks
34 35
    -- R.useEffectOnce' $ do
    --   T.write (Just tasksReductor) tasks
36 37 38
    R.useEffectOnce' $ do
      R2.loadLocalStorageState R2.openNodesKey boxes.forestOpen
      T.listen (R2.listenLocalStorageState R2.openNodesKey) boxes.forestOpen
39
    useHashRouter Router.router boxes.route -- Install router to window
40
    pure $ router { boxes }          -- Render router component