Store.purs 4.2 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
  , source              :: T.Box String
  , sources             :: T.Box (Array Source)
  , terms               :: T.Box (Array Term)
arturo's avatar
arturo committed
45
  -- Sidebar
46 47 48 49 50
  , 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
51
  -- Toolbar
52
  , displayView         :: T.Box DisplayView
arturo's avatar
arturo committed
53 54 55 56
  )

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

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

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