Store.purs 4.48 KB
Newer Older
arturo's avatar
arturo committed
1 2 3 4 5 6 7 8 9 10 11 12 13
module Gargantext.Components.PhyloExplorer.Store
  ( Store
  , State
  , options
  , context
  , provide
  , use
  ) where


import Gargantext.Prelude

import Data.Maybe (Maybe(..))
arturo's avatar
arturo committed
14
import Gargantext.Components.PhyloExplorer.Types (CorpusId, DisplayView(..), ExtractedCount, ExtractedTerm, FrameDoc, PhyloData, Source, TabView(..), Term, ListId, defaultCacheParams)
arturo's avatar
arturo committed
15
import Gargantext.Types (NodeID, SidePanelState(..))
16
import Gargantext.Utils (getter)
arturo's avatar
arturo committed
17 18 19 20 21 22 23 24 25 26 27
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Stores as Stores
import Reactix as R
import Toestand as T
import Unsafe.Coerce (unsafeCoerce)

here :: R2.Here
here = R2.here "Gargantext.Components.GraphExplorer.Store"

type Store =
  -- Data
arturo's avatar
arturo committed
28
  ( phyloData           :: T.Box PhyloData
29
  , phyloId             :: T.Box NodeID
arturo's avatar
arturo committed
30 31
  , corpusId            :: T.Box CorpusId
  , listId              :: T.Box ListId
32
  , isBuilt             :: T.Box Boolean
arturo's avatar
arturo committed
33
  -- Layout
34 35 36 37 38 39 40
  , toolBarDisplayed    :: T.Box Boolean
  , isIsolineDisplayed  :: T.Box Boolean
  , sideBarDisplayed    :: T.Box SidePanelState
  , sideBarTabView      :: T.Box TabView
  , frameDoc            :: T.Box (Maybe FrameDoc)
  , expandSelection     :: T.Box Boolean
  , expandNeighborhood  :: T.Box Boolean
arturo's avatar
arturo committed
41
  -- Topbar
42 43 44 45 46
  , source              :: T.Box String
  , sources             :: T.Box (Array Source)
  , terms               :: T.Box (Array Term)
  , search              :: T.Box String
  , result              :: T.Box (Maybe Term)
arturo's avatar
arturo committed
47
  -- Sidebar
48 49 50 51 52
  , extractedTerms      :: T.Box (Array ExtractedTerm)
  , selectedTerm        :: T.Box (Maybe String)
  , selectedBranch      :: T.Box (Maybe String)
  , selectedSource      :: T.Box (Maybe String)
  , extractedCount      :: T.Box (Maybe ExtractedCount)
arturo's avatar
arturo committed
53
  -- Toolbar
54
  , displayView         :: T.Box DisplayView
arturo's avatar
arturo committed
55 56 57 58
  )

type State =
  -- Data
arturo's avatar
arturo committed
59
  ( phyloData           :: PhyloData
60
  , phyloId             :: NodeID
arturo's avatar
arturo committed
61 62
  , corpusId            :: CorpusId
  , listId              :: ListId
63
  , isBuilt             :: Boolean
arturo's avatar
arturo committed
64
  -- Layout
65 66 67 68 69 70 71
  , toolBarDisplayed    :: Boolean
  , isIsolineDisplayed  :: Boolean
  , sideBarDisplayed    :: SidePanelState
  , sideBarTabView      :: TabView
  , frameDoc            :: Maybe FrameDoc
  , expandSelection     :: Boolean
  , expandNeighborhood  :: Boolean
arturo's avatar
arturo committed
72
  -- Topbar
73 74 75 76 77
  , source              :: String
  , sources             :: Array Source
  , terms               :: Array Term
  , search              :: String
  , result              :: Maybe Term
arturo's avatar
arturo committed
78
  -- Sidebar
79 80 81 82 83
  , extractedTerms      :: Array ExtractedTerm
  , selectedTerm        :: Maybe String
  , selectedBranch      :: Maybe String
  , selectedSource      :: Maybe String
  , extractedCount      :: Maybe ExtractedCount
arturo's avatar
arturo committed
84
  -- Toolbar
85
  , displayView         :: DisplayView
arturo's avatar
arturo committed
86 87 88
  )

options ::
89
  { isBuilt             :: Boolean
arturo's avatar
arturo committed
90
  -- Layout
91 92 93 94 95 96 97
  , toolBarDisplayed    :: Boolean
  , isIsolineDisplayed  :: Boolean
  , sideBarDisplayed    :: SidePanelState
  , sideBarTabView      :: TabView
  , frameDoc            :: Maybe FrameDoc
  , expandSelection     :: Boolean
  , expandNeighborhood  :: Boolean
arturo's avatar
arturo committed
98
  -- Topbar
99 100 101 102 103
  , source              :: String
  , sources             :: Array Source
  , terms               :: Array Term
  , search              :: String
  , result              :: Maybe Term
arturo's avatar
arturo committed
104
  -- Sidebar
105 106 107 108 109
  , extractedTerms      :: Array ExtractedTerm
  , selectedTerm        :: Maybe String
  , selectedBranch      :: Maybe String
  , selectedSource      :: Maybe String
  , extractedCount      :: Maybe ExtractedCount
arturo's avatar
arturo committed
110
  -- Toolbar
111
  , displayView         :: DisplayView
arturo's avatar
arturo committed
112 113 114
  }
options =
  -- Data
115
  { isBuilt             : false
arturo's avatar
arturo committed
116
  -- Layout
117 118 119 120 121 122 123
  , toolBarDisplayed    : false
  , isIsolineDisplayed  : false
  , sideBarDisplayed    : InitialClosed
  , sideBarTabView      : DetailsTab
  , frameDoc            : Nothing
  , expandSelection     : getter _.expandSelection defaultCacheParams
  , expandNeighborhood  : getter _.expandNeighborhood defaultCacheParams
arturo's avatar
arturo committed
124
  -- Topbar
125 126 127 128 129
  , source              : ""
  , sources             : mempty
  , terms               : mempty
  , search              : ""
  , result              : Nothing
arturo's avatar
arturo committed
130
  -- Sidebar
131 132 133 134 135
  , extractedTerms      : mempty
  , selectedTerm        : Nothing
  , selectedBranch      : Nothing
  , selectedSource      : Nothing
  , extractedCount      : Nothing
arturo's avatar
arturo committed
136
  -- Toolbar
137
  , displayView         : HeadingMode
arturo's avatar
arturo committed
138 139 140 141 142 143 144 145 146 147
  }

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