Store.purs 4.1 KB
Newer Older
arturo's avatar
arturo committed
1 2 3 4 5 6 7 8 9 10
module Gargantext.Components.App.Store
  ( Store
  , State
  , options
  , context
  , provide
  , use
  -- legacy
  , Boxes
  ) where
James Laver's avatar
James Laver committed
11

12

13 14
import Gargantext.Prelude

James Laver's avatar
James Laver committed
15
import Data.Maybe (Maybe(..))
16
import Data.Set as Set
17
import Gargantext.AsyncTasks as GAT
18
import Gargantext.Components.Lang as Lang
19 20
import Gargantext.Components.Nodes.Lists.Types as ListsT
import Gargantext.Components.Nodes.Texts.Types as TextsT
21
import Gargantext.Components.Themes as Themes
James Laver's avatar
James Laver committed
22
import Gargantext.Ends (Backend)
23
import Gargantext.Routes (AppRoute(Home), Tile)
24
import Gargantext.Sessions (Session, Sessions)
25
import Gargantext.Sessions as Sessions
26
import Gargantext.Sessions.Types (OpenNodes(..))
27
import Gargantext.Types (FrontendError, Handed(RightHanded), SidePanelState(..))
arturo's avatar
arturo committed
28 29
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Stores as Stores
James Laver's avatar
James Laver committed
30
import Gargantext.Utils.Toestand as T2
arturo's avatar
arturo committed
31
import Reactix as R
32
import Toestand as T
arturo's avatar
arturo committed
33
import Unsafe.Coerce (unsafeCoerce)
James Laver's avatar
James Laver committed
34

arturo's avatar
arturo committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
here :: R2.Here
here = R2.here "Gargantext.Components.App.Store"

type Store =
  ( backend             :: T.Box (Maybe Backend)
  , errors              :: T.Box (Array FrontendError)
  , forestOpen          :: T.Box OpenNodes
  , graphVersion        :: T2.ReloadS
  , handed              :: T.Box Handed
  , lang                :: T.Box Lang.LandingLang
  , reloadForest        :: T2.ReloadS
  , reloadMainPage      :: T2.ReloadS
  , reloadRoot          :: T2.ReloadS
  , route               :: T.Box AppRoute
  , session             :: T.Box (Maybe Session)
  , sessions            :: T.Box Sessions
  , showCorpus          :: T.Box Boolean
  , showLogin           :: T.Box Boolean
  , showTree            :: T.Box Boolean
  , sidePanelLists      :: T.Box (Maybe (Record ListsT.SidePanel))
  , sidePanelTexts      :: T.Box (Maybe (Record TextsT.SidePanel))
  , sidePanelState      :: T.Box SidePanelState
  , tasks               :: T.Box GAT.Storage
  , theme               :: T.Box Themes.Theme
  , tileAxisXList       :: T.Box (Array (Record Tile))
  , tileAxisYList       :: T.Box (Array (Record Tile))
  )

type State =
  ( backend             :: Maybe Backend
65 66 67 68
  , errors              :: Array FrontendError
  , forestOpen          :: OpenNodes
  , graphVersion        :: T2.Reload
  , handed              :: Handed
69
  , lang                :: Lang.LandingLang
70 71 72 73 74 75 76 77 78 79 80 81 82
  , reloadForest        :: T2.Reload
  , reloadMainPage      :: T2.Reload
  , reloadRoot          :: T2.Reload
  , route               :: AppRoute
  , session             :: Maybe Session
  , sessions            :: Sessions
  , showCorpus          :: Boolean
  , showLogin           :: Boolean
  , showTree            :: Boolean
  , sidePanelLists      :: Maybe (Record ListsT.SidePanel)
  , sidePanelTexts      :: Maybe (Record TextsT.SidePanel)
  , sidePanelState      :: SidePanelState
  , tasks               :: GAT.Storage
83
  , theme               :: Themes.Theme
84 85
  , tileAxisXList       :: Array (Record Tile)
  , tileAxisYList       :: Array (Record Tile)
arturo's avatar
arturo committed
86
  )
James Laver's avatar
James Laver committed
87

arturo's avatar
arturo committed
88 89
options :: Record State
options =
90 91 92 93 94
  { backend             : Nothing
  , errors              : []
  , forestOpen          : OpenNodes $ Set.empty
  , graphVersion        : T2.newReload
  , handed              : RightHanded
95
  , lang                : Lang.LL_EN
96 97 98 99 100 101 102 103 104 105 106 107 108
  , reloadForest        : T2.newReload
  , reloadMainPage      : T2.newReload
  , reloadRoot          : T2.newReload
  , route               : Home
  , session             : Nothing
  , sessions            : Sessions.empty
  , showCorpus          : false
  , showLogin           : false
  , showTree            : true
  , sidePanelLists      : ListsT.initialSidePanel
  , sidePanelTexts      : TextsT.initialSidePanel
  , sidePanelState      : InitialClosed
  , tasks               : GAT.empty
109
  , theme               : Themes.defaultTheme
110 111
  , tileAxisXList       : mempty
  , tileAxisYList       : mempty
James Laver's avatar
James Laver committed
112 113
  }

arturo's avatar
arturo committed
114 115 116 117 118 119 120 121 122 123 124 125
context :: R.Context (Record Store)
context = R.createContext $ unsafeCoerce unit

provide :: Record State -> Array R.Element -> R.Element
provide values = Stores.provideStore here.name values context

use :: R.Hooks (Record Store)
use = Stores.useStore context

------------------------------------------------------

type Boxes = Record Store