Commit 023702d0 authored by arturo's avatar arturo

>>> BEGIN 333

* add Theme to global box container
parent 8a629d69
module Gargantext.Components.App.Data (App, Boxes, emptyApp) where module Gargantext.Components.App.Data (App, Boxes, emptyApp) where
import Gargantext.Prelude import Gargantext.Prelude
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Set as Set import Data.Set as Set
import Toestand as T
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
import Gargantext.Components.GraphExplorer.Sidebar.Types as GEST import Gargantext.Components.GraphExplorer.Sidebar.Types as GEST
import Gargantext.Components.Nodes.Lists.Types as ListsT import Gargantext.Components.Nodes.Lists.Types as ListsT
import Gargantext.Components.Nodes.Texts.Types as TextsT import Gargantext.Components.Nodes.Texts.Types as TextsT
import Gargantext.Components.Themes as Themes
import Gargantext.Ends (Backend) import Gargantext.Ends (Backend)
import Gargantext.Routes (AppRoute(Home), Tile) import Gargantext.Routes (AppRoute(Home), Tile)
import Gargantext.Sessions (Session, Sessions) import Gargantext.Sessions (Session, Sessions)
...@@ -17,6 +17,7 @@ import Gargantext.Sessions as Sessions ...@@ -17,6 +17,7 @@ import Gargantext.Sessions as Sessions
import Gargantext.Sessions.Types (OpenNodes(..)) import Gargantext.Sessions.Types (OpenNodes(..))
import Gargantext.Types (FrontendError, Handed(RightHanded), SidePanelState(..)) import Gargantext.Types (FrontendError, Handed(RightHanded), SidePanelState(..))
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
import Toestand as T
type App = type App =
{ backend :: Maybe Backend { backend :: Maybe Backend
...@@ -38,6 +39,7 @@ type App = ...@@ -38,6 +39,7 @@ type App =
, sidePanelTexts :: Maybe (Record TextsT.SidePanel) , sidePanelTexts :: Maybe (Record TextsT.SidePanel)
, sidePanelState :: SidePanelState , sidePanelState :: SidePanelState
, tasks :: GAT.Storage , tasks :: GAT.Storage
, theme :: Themes.Theme
, tileAxisXList :: Array (Record Tile) , tileAxisXList :: Array (Record Tile)
, tileAxisYList :: Array (Record Tile) , tileAxisYList :: Array (Record Tile)
} }
...@@ -63,6 +65,7 @@ emptyApp = ...@@ -63,6 +65,7 @@ emptyApp =
, sidePanelTexts : TextsT.initialSidePanel , sidePanelTexts : TextsT.initialSidePanel
, sidePanelState : InitialClosed , sidePanelState : InitialClosed
, tasks : GAT.empty , tasks : GAT.empty
, theme : Themes.defaultTheme
, tileAxisXList : mempty , tileAxisXList : mempty
, tileAxisYList : mempty , tileAxisYList : mempty
} }
...@@ -87,6 +90,7 @@ type Boxes = ...@@ -87,6 +90,7 @@ type Boxes =
, sidePanelTexts :: T.Box (Maybe (Record TextsT.SidePanel)) , sidePanelTexts :: T.Box (Maybe (Record TextsT.SidePanel))
, sidePanelState :: T.Box SidePanelState , sidePanelState :: T.Box SidePanelState
, tasks :: T.Box GAT.Storage , tasks :: T.Box GAT.Storage
, theme :: T.Box Themes.Theme
, tileAxisXList :: T.Box (Array (Record Tile)) , tileAxisXList :: T.Box (Array (Record Tile))
, tileAxisYList :: T.Box (Array (Record Tile)) , tileAxisYList :: T.Box (Array (Record Tile))
} }
...@@ -86,7 +86,7 @@ markThemeToDOMTree (Theme { name }) = do ...@@ -86,7 +86,7 @@ markThemeToDOMTree (Theme { name }) = do
type ThemeSwitcherProps = ( type ThemeSwitcherProps = (
theme :: Theme theme :: T.Box Theme
, themes :: Array Theme , themes :: Array Theme
) )
...@@ -97,19 +97,18 @@ themeSwitcherCpt :: R.Component ThemeSwitcherProps ...@@ -97,19 +97,18 @@ themeSwitcherCpt :: R.Component ThemeSwitcherProps
themeSwitcherCpt = here.component "themeSwitcher" cpt themeSwitcherCpt = here.component "themeSwitcher" cpt
where where
cpt { theme, themes } _ = do cpt { theme, themes } _ = do
currentTheme <- T.useBox theme currentTheme <- T.useLive T.unequal theme
currentTheme' <- T.useLive T.unequal currentTheme
let option (Theme { name }) = H.option { value: name } [ H.text name ] let option (Theme { name }) = H.option { value: name } [ H.text name ]
let options = map option themes let options = map option themes
R.useEffectOnce' $ markThemeToDOMTree currentTheme' R.useEffectOnce' $ markThemeToDOMTree currentTheme
pure $ R2.select { className: "form-control" pure $ R2.select { className: "form-control"
, defaultValue: themeName currentTheme' , defaultValue: themeName currentTheme
, on: { change: onChange currentTheme } } options , on: { change: onChange theme } } options
where where
onChange currentTheme e = do onChange box e = do
let value = R.unsafeEventValue e let value = R.unsafeEventValue e
let mTheme = A.head $ A.filter (\(Theme { name }) -> value == name) themes let mTheme = A.head $ A.filter (\(Theme { name }) -> value == name) themes
...@@ -118,4 +117,4 @@ themeSwitcherCpt = here.component "themeSwitcher" cpt ...@@ -118,4 +117,4 @@ themeSwitcherCpt = here.component "themeSwitcher" cpt
Just t -> do Just t -> do
switchTheme t switchTheme t
markThemeToDOMTree t markThemeToDOMTree t
T.write_ t currentTheme T.write_ t box
...@@ -5,7 +5,7 @@ import Gargantext.Prelude ...@@ -5,7 +5,7 @@ import Gargantext.Prelude
import Data.Foldable (intercalate) import Data.Foldable (intercalate)
import Gargantext.Components.App.Data (Boxes) import Gargantext.Components.App.Data (Boxes)
import Gargantext.Components.GraphExplorer.ToggleButton as Toggle import Gargantext.Components.GraphExplorer.ToggleButton as Toggle
import Gargantext.Components.Themes (themeSwitcher, defaultTheme, allThemes) import Gargantext.Components.Themes (themeSwitcher, allThemes)
import Gargantext.Types (Handed(..), reverseHanded) import Gargantext.Types (Handed(..), reverseHanded)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
...@@ -23,7 +23,7 @@ topBar = R.createElement topBarCpt ...@@ -23,7 +23,7 @@ topBar = R.createElement topBarCpt
topBarCpt :: R.Component TopBarProps topBarCpt :: R.Component TopBarProps
topBarCpt = here.component "topBar" cpt topBarCpt = here.component "topBar" cpt
where where
cpt { boxes: { handed, showTree } } children = do cpt { boxes: { handed, showTree, theme } } children = do
handed' <- T.useLive T.unequal handed handed' <- T.useLive T.unequal handed
pure $ H.div { className: "navbar navbar-expand-lg navbar-dark bg-dark" pure $ H.div { className: "navbar navbar-expand-lg navbar-dark bg-dark"
...@@ -41,7 +41,7 @@ topBarCpt = here.component "topBar" cpt ...@@ -41,7 +41,7 @@ topBarCpt = here.component "topBar" cpt
([ divDropdownLeft {} [] ([ divDropdownLeft {} []
, handButton , handButton
, smiley , smiley
, H.li { className: "nav-item" } [ themeSwitcher { theme: defaultTheme , H.li { className: "nav-item" } [ themeSwitcher { theme
, themes: allThemes } [] ] , themes: allThemes } [] ]
, Toggle.treeToggleButton { state: showTree } [] , Toggle.treeToggleButton { state: showTree } []
] <> children) ] <> children)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment