Commit 7f7afc2d authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch '310-dev-frontend-lang' of...

Merge branch '310-dev-frontend-lang' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into dev-merge2
parents 4f69514a f982c6c1
...@@ -7,6 +7,7 @@ import Data.Maybe (Maybe(..)) ...@@ -7,6 +7,7 @@ import Data.Maybe (Maybe(..))
import Data.Set as Set import Data.Set as Set
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.Lang as Lang
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.Components.Themes as Themes
...@@ -25,6 +26,7 @@ type App = ...@@ -25,6 +26,7 @@ type App =
, forestOpen :: OpenNodes , forestOpen :: OpenNodes
, graphVersion :: T2.Reload , graphVersion :: T2.Reload
, handed :: Handed , handed :: Handed
, lang :: Lang.LandingLang
, reloadForest :: T2.Reload , reloadForest :: T2.Reload
, reloadMainPage :: T2.Reload , reloadMainPage :: T2.Reload
, reloadRoot :: T2.Reload , reloadRoot :: T2.Reload
...@@ -51,6 +53,7 @@ emptyApp = ...@@ -51,6 +53,7 @@ emptyApp =
, forestOpen : OpenNodes $ Set.empty , forestOpen : OpenNodes $ Set.empty
, graphVersion : T2.newReload , graphVersion : T2.newReload
, handed : RightHanded , handed : RightHanded
, lang : Lang.LL_EN
, reloadForest : T2.newReload , reloadForest : T2.newReload
, reloadMainPage : T2.newReload , reloadMainPage : T2.newReload
, reloadRoot : T2.newReload , reloadRoot : T2.newReload
...@@ -76,6 +79,7 @@ type Boxes = ...@@ -76,6 +79,7 @@ type Boxes =
, forestOpen :: T.Box OpenNodes , forestOpen :: T.Box OpenNodes
, graphVersion :: T2.ReloadS , graphVersion :: T2.ReloadS
, handed :: T.Box Handed , handed :: T.Box Handed
, lang :: T.Box Lang.LandingLang
, reloadForest :: T2.ReloadS , reloadForest :: T2.ReloadS
, reloadMainPage :: T2.ReloadS , reloadMainPage :: T2.ReloadS
, reloadRoot :: T2.ReloadS , reloadRoot :: T2.ReloadS
......
module Gargantext.Components.Lang where module Gargantext.Components.Lang where
import Gargantext.Prelude
import Data.Argonaut (class EncodeJson, encodeJson) import Data.Argonaut (class EncodeJson, encodeJson)
import Data.Array as A
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Gargantext.Prelude (class Eq, class Show, show, class Read) import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Lang"
-- Language used for search -- Language used for search
allLangs :: Array Lang allLangs :: Array Lang
...@@ -36,6 +45,44 @@ instance EncodeJson Lang where ...@@ -36,6 +45,44 @@ instance EncodeJson Lang where
-- Language used for the landing page -- Language used for the landing page
data LandingLang = LL_EN | LL_FR data LandingLang = LL_EN | LL_FR
derive instance Eq LandingLang
instance Show LandingLang where
show LL_EN = "EN"
show LL_FR = "FR"
-- @TODO a possible method/class that a real i18n logic could later replace -- @TODO a possible method/class that a real i18n logic could later replace
class Show t <= Translate t where class Show t <= Translate t where
translate :: Lang -> t -> String translate :: Lang -> t -> String
allFeLangs :: Array LandingLang
allFeLangs = [ LL_EN, LL_FR ]
type LangSwitcherProps = (
lang :: T.Box LandingLang
, langs :: Array LandingLang
)
langSwitcher :: R2.Component LangSwitcherProps
langSwitcher = R.createElement langSwitcherCpt
langSwitcherCpt :: R.Component LangSwitcherProps
langSwitcherCpt = here.component "langSwitcher" cpt
where
cpt { lang, langs} _ = do
currentLang <- T.useLive T.unequal lang
let option l = H.option { value: show l} [ H.text $ show l]
let options = map option langs
pure $ R2.select { className: "form-control"
, defaultValue: show currentLang
, on: {change: onChange lang } } options
where
onChange box e = do
let value = R.unsafeEventValue e
let mLang = A.head $ A.filter (\l -> value == show l) langs
case mLang of
Nothing -> pure unit
Just l -> do
T.write_ l box
\ No newline at end of file
...@@ -52,9 +52,7 @@ langLandingData LL_EN = En.landingData ...@@ -52,9 +52,7 @@ langLandingData LL_EN = En.landingData
------------------------------------------------------------------------ ------------------------------------------------------------------------
type HomeProps = type HomeProps =
( boxes :: Boxes ( boxes :: Boxes )
, lang :: LandingLang
)
homeLayout :: R2.Leaf HomeProps homeLayout :: R2.Leaf HomeProps
homeLayout = R2.leafComponent homeLayoutCpt homeLayout = R2.leafComponent homeLayoutCpt
...@@ -62,12 +60,14 @@ homeLayoutCpt :: R.Component HomeProps ...@@ -62,12 +60,14 @@ homeLayoutCpt :: R.Component HomeProps
homeLayoutCpt = here.component "homeLayout" cpt homeLayoutCpt = here.component "homeLayout" cpt
where where
cpt { boxes: boxes@{ backend cpt { boxes: boxes@{ backend
, lang
, sessions , sessions
, showLogin } , showLogin }
, lang } _ = do } _ = do
backend' <- T.useLive T.unequal backend backend' <- T.useLive T.unequal backend
sessions' <- T.useLive T.unequal sessions sessions' <- T.useLive T.unequal sessions
let landingData = langLandingData lang lang' <- T.useLive T.unequal lang
let landingData = langLandingData lang'
pure $ pure $
H.span {} H.span {}
[ H.div { className: "home-title container1" } [ H.div { className: "home-title container1" }
......
...@@ -451,7 +451,7 @@ home = R.createElement homeCpt ...@@ -451,7 +451,7 @@ home = R.createElement homeCpt
homeCpt :: R.Component Props homeCpt :: R.Component Props
homeCpt = here.component "home" cpt where homeCpt = here.component "home" cpt where
cpt { boxes } _ = do cpt { boxes } _ = do
pure $ homeLayout { boxes, lang: LL_EN } pure $ homeLayout { boxes }
lists :: R2.Component SessionNodeProps lists :: R2.Component SessionNodeProps
lists = R.createElement listsCpt lists = R.createElement listsCpt
......
...@@ -6,6 +6,7 @@ import Data.Foldable (intercalate) ...@@ -6,6 +6,7 @@ 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, allThemes) import Gargantext.Components.Themes (themeSwitcher, allThemes)
import Gargantext.Components.Lang (langSwitcher, allFeLangs)
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 +24,7 @@ topBar = R.createElement topBarCpt ...@@ -23,7 +24,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, theme } } children = do cpt { boxes: { handed, lang, 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"
...@@ -43,6 +44,8 @@ topBarCpt = here.component "topBar" cpt ...@@ -43,6 +44,8 @@ topBarCpt = here.component "topBar" cpt
, smiley , smiley
, H.li { className: "nav-item" } [ themeSwitcher { theme , H.li { className: "nav-item" } [ themeSwitcher { theme
, themes: allThemes } [] ] , themes: allThemes } [] ]
, H.li { className: "nav-item" } [ langSwitcher { lang
, langs: allFeLangs } [] ]
, 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