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

3 4 5
import Gargantext.Prelude

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

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

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

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