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

3 4 5
import Gargantext.Prelude

import Gargantext.AsyncTasks as GAT
arturo's avatar
arturo committed
6
import Gargantext.Components.App.Store as AppStore
James Laver's avatar
James Laver committed
7 8 9
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
arturo's avatar
arturo committed
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
arturo's avatar
arturo committed
24
    boxes <- AppStore.use
25
    -- tasks   <- T.useBox Nothing             -- storage for asynchronous tasks reductor
26
    R.useEffectOnce' $ do
27
      void $ Sessions.load boxes.sessions
28 29 30 31
    -- tasks <- GAT.useTasks boxes.reloadRoot boxes.reloadForest
    R.useEffectOnce' $ do
      tasksStorage <- GAT.getAsyncTasks
      T.write_ tasksStorage boxes.tasks
32 33
    -- R.useEffectOnce' $ do
    --   T.write (Just tasksReductor) tasks
34 35 36
    R.useEffectOnce' $ do
      R2.loadLocalStorageState R2.openNodesKey boxes.forestOpen
      T.listen (R2.listenLocalStorageState R2.openNodesKey) boxes.forestOpen
37
    useHashRouter Router.router boxes.route -- Install router to window
38
    pure $ router { boxes }          -- Render router component