States.purs 2.18 KB
Newer Older
1
module Gargantext.Pages.Layout.States where
2 3 4

import Prelude hiding (div)

5 6
import Data.Lens                                       (Lens', lens)
import Data.Maybe                                      (Maybe(Just))
7
import Effect (Effect)
8
import Gargantext.Components.Login                  as LN
9

10
import Gargantext.Pages.Corpus.Document       as D
11
import Gargantext.Pages.Corpus.Graph     as GE
12 13
import Gargantext.Pages.Layout.Specs.AddCorpus      as AC
import Gargantext.Pages.Layout.Specs.Search         as S
14
import Gargantext.Pages.Layout.Specs.SearchBar      as SB
15
import Gargantext.Router                               (Routes(..))
16 17

type AppState =
18 19 20 21 22 23 24 25 26 27
  { currentRoute       :: Maybe Routes
  , loginState         :: LN.State
  , addCorpusState     :: AC.State
  , searchState        :: S.State
  , documentState      :: D.State
  , searchBarState     :: SB.State
  , showLogin          :: Boolean
  , showCorpus         :: Boolean
  , graphExplorerState :: GE.State
  , showTree           :: Boolean
28 29
  }

30 31 32 33 34 35 36 37 38
initAppState :: Effect AppState
initAppState = do
  loginState <- LN.initialState
  pure
    { currentRoute   : Just Home
    , loginState
    , addCorpusState : AC.initialState
    , searchState    : S.initialState
    , documentState  : D.initialState {}
39
    , searchBarState : SB.initialState
40 41 42 43 44
    , showLogin      : false
    , showCorpus     : false
    , graphExplorerState : GE.initialState
    , showTree : false
    }
45

46

47
---------------------------------------------------------
48

49 50 51 52 53 54 55 56 57
_loginState :: Lens' AppState LN.State
_loginState = lens (\s -> s.loginState) (\s ss -> s{loginState = ss})

_addCorpusState :: Lens' AppState AC.State
_addCorpusState = lens (\s -> s.addCorpusState) (\s ss -> s{addCorpusState = ss})

_searchState :: Lens' AppState S.State
_searchState = lens (\s -> s.searchState) (\s ss -> s{searchState = ss})

58 59 60
_searchBarState :: Lens' AppState SB.State
_searchBarState = lens (\s -> s.searchBarState) (\s ss -> s{searchBarState = ss})

61 62
_documentViewState :: Lens' AppState D.State
_documentViewState = lens (\s -> s.documentState) (\s ss -> s{documentState = ss})
63 64

_graphExplorerState :: Lens' AppState GE.State
65
_graphExplorerState = lens (\s -> s.graphExplorerState) (\s ss -> s{graphExplorerState = ss})
66