Commit d0ee31c0 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngramsTable] reloadMainPage and activeTab refresh

parent cd469dce
...@@ -76,12 +76,18 @@ remove id task storage = T.modify_ newStorage storage ...@@ -76,12 +76,18 @@ remove id task storage = T.modify_ newStorage storage
-- When a task is finished: which tasks cause forest or app reload -- When a task is finished: which tasks cause forest or app reload
asyncTaskTriggersAppReload :: GT.AsyncTaskType -> Boolean asyncTaskTriggersAppReload :: GT.AsyncTaskType -> Boolean
asyncTaskTriggersAppReload GT.UpdateNgramsCharts = true
asyncTaskTriggersAppReload _ = false asyncTaskTriggersAppReload _ = false
asyncTaskTTriggersAppReload :: GT.AsyncTaskWithType -> Boolean asyncTaskTTriggersAppReload :: GT.AsyncTaskWithType -> Boolean
asyncTaskTTriggersAppReload (GT.AsyncTaskWithType { typ }) = asyncTaskTriggersAppReload typ asyncTaskTTriggersAppReload (GT.AsyncTaskWithType { typ }) = asyncTaskTriggersAppReload typ
asyncTaskTriggersMainPageReload :: GT.AsyncTaskType -> Boolean
asyncTaskTriggersMainPageReload GT.UpdateNgramsCharts = true
asyncTaskTriggersMainPageReload _ = false
asyncTaskTTriggersMainPageReload :: GT.AsyncTaskWithType -> Boolean
asyncTaskTTriggersMainPageReload (GT.AsyncTaskWithType { typ }) = asyncTaskTriggersMainPageReload typ
asyncTaskTriggersTreeReload :: GT.AsyncTaskType -> Boolean asyncTaskTriggersTreeReload :: GT.AsyncTaskType -> Boolean
asyncTaskTriggersTreeReload GT.Form = true asyncTaskTriggersTreeReload GT.Form = true
asyncTaskTriggersTreeReload GT.UploadFile = true asyncTaskTriggersTreeReload GT.UploadFile = true
......
...@@ -164,7 +164,7 @@ forestLayoutMain = R.createElement forestLayoutMainCpt ...@@ -164,7 +164,7 @@ forestLayoutMain = R.createElement forestLayoutMainCpt
forestLayoutMainCpt :: R.Component Props forestLayoutMainCpt :: R.Component Props
forestLayoutMainCpt = here.component "forestLayoutMain" cpt where forestLayoutMainCpt = here.component "forestLayoutMain" cpt where
cpt props@{ reloadMainPage } children = cpt props@{ reloadMainPage } children =
pure $ forestLayoutRaw props [ mainPage { reloadMainPage } children ] pure $ forestLayoutRaw props [ mainPage {} children ]
forestLayoutRaw :: R2.Component Props forestLayoutRaw :: R2.Component Props
forestLayoutRaw = R.createElement forestLayoutRawCpt forestLayoutRaw = R.createElement forestLayoutRawCpt
...@@ -203,20 +203,15 @@ forestLayoutRawCpt = here.component "forestLayoutRaw" cpt where ...@@ -203,20 +203,15 @@ forestLayoutRawCpt = here.component "forestLayoutRaw" cpt where
, showLogin , showLogin
, tasks } [] , tasks } []
type MainPage = mainPage :: R2.Component ()
( reloadMainPage :: T2.ReloadS )
mainPage :: R2.Component MainPage
mainPage = R.createElement mainPageCpt mainPage = R.createElement mainPageCpt
-- mainPageCpt :: R.Memo () -- mainPageCpt :: R.Memo ()
-- mainPageCpt = R.memo (here.component "mainPage" cpt) where -- mainPageCpt = R.memo (here.component "mainPage" cpt) where
mainPageCpt :: R.Component MainPage mainPageCpt :: R.Component ()
mainPageCpt = here.component "mainPage" cpt mainPageCpt = here.component "mainPage" cpt
where where
cpt { reloadMainPage } children = do cpt _ children = do
reloadMainPage' <- T.useLive T.unequal reloadMainPage
pure $ H.div { className: "col-md-10" } pure $ H.div { className: "col-md-10" }
[ H.div { id: "page-wrapper" } [ H.div { id: "page-wrapper" }
[ H.div { className: "container-fluid" } children ] [ H.div { className: "container-fluid" } children ]
......
...@@ -85,6 +85,7 @@ nodeMainSpanCpt = here.component "nodeMainSpan" cpt ...@@ -85,6 +85,7 @@ nodeMainSpanCpt = here.component "nodeMainSpan" cpt
, isLeaf , isLeaf
, name , name
, nodeType , nodeType
, reload
, reloadMainPage , reloadMainPage
, reloadRoot , reloadRoot
, route , route
...@@ -152,12 +153,19 @@ nodeMainSpanCpt = here.component "nodeMainSpan" cpt ...@@ -152,12 +153,19 @@ nodeMainSpanCpt = here.component "nodeMainSpan" cpt
if GAT.asyncTaskTTriggersAppReload t then do if GAT.asyncTaskTTriggersAppReload t then do
here.log2 "reloading root for task" t here.log2 "reloading root for task" t
T2.reload reloadRoot T2.reload reloadRoot
else if GAT.asyncTaskTTriggersTreeReload t then do
here.log2 "reloading tree for task" t
T2.reload reloadMainPage
else do else do
here.log2 "task doesn't trigger a reload" t if GAT.asyncTaskTTriggersTreeReload t then do
pure unit here.log2 "reloading tree for task" t
T2.reload reload
else do
here.log2 "task doesn't trigger a tree reload" t
pure unit
if GAT.asyncTaskTTriggersMainPageReload t then do
here.log2 "reloading main page for task" t
T2.reload reloadMainPage
else do
here.log2 "task doesn't trigger a main page reload" t
pure unit
-- snd tasks $ GAT.Finish id' t -- snd tasks $ GAT.Finish id' t
-- mT <- T.read tasks -- mT <- T.read tasks
-- case mT of -- case mT of
......
...@@ -70,8 +70,9 @@ tabs props = R.createElement tabsCpt props [] ...@@ -70,8 +70,9 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component TabsProps tabsCpt :: R.Component TabsProps
tabsCpt = here.component "tabs" cpt where tabsCpt = here.component "tabs" cpt where
cpt props _ = do cpt props _ = do
active <- R.useState' 0 activeTab <- T.useBox 0
pure $ Tab.tabs { selected: fst active, tabs: tabs' props }
pure $ Tab.tabs { activeTab, tabs: tabs' props }
tabs' props@{ sidePanel, sidePanelState } = tabs' props@{ sidePanel, sidePanelState } =
[ "Documents" /\ docs [ "Documents" /\ docs
, "Patents" /\ ngramsView (viewProps Patents) , "Patents" /\ ngramsView (viewProps Patents)
......
...@@ -77,8 +77,9 @@ tabsCpt = here.component "tabs" cpt ...@@ -77,8 +77,9 @@ tabsCpt = here.component "tabs" cpt
, sidePanel , sidePanel
, sidePanelState , sidePanelState
, reloadForest } _ = do , reloadForest } _ = do
active <- R.useState' 0 activeTab <- T.useBox 0
pure $ Tab.tabs { selected: fst active, tabs: tabs' }
pure $ Tab.tabs { activeTab, tabs: tabs' }
where where
tabs' = tabs' =
[ "Documents" /\ docs [ "Documents" /\ docs
......
...@@ -4,6 +4,7 @@ import Prelude hiding (div) ...@@ -4,6 +4,7 @@ import Prelude hiding (div)
import Data.Array (fromFoldable) import Data.Array (fromFoldable)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Reactix as R import Reactix as R
import Toestand as T
import Gargantext.Components.GraphExplorer.Types (GraphSideCorpus(..)) import Gargantext.Components.GraphExplorer.Types (GraphSideCorpus(..))
import Gargantext.Components.FacetsTable (docView) import Gargantext.Components.FacetsTable (docView)
...@@ -32,7 +33,9 @@ tabsCpt :: R.Component Props ...@@ -32,7 +33,9 @@ tabsCpt :: R.Component Props
tabsCpt = here.component "tabs" cpt tabsCpt = here.component "tabs" cpt
where where
cpt {frontends, query, session, sides} _ = do cpt {frontends, query, session, sides} _ = do
pure $ Tab.tabs { selected: 0, tabs: tabs' } activeTab <- T.useBox 0
pure $ Tab.tabs { activeTab, tabs: tabs' }
where where
tabs' = fromFoldable $ tab frontends session query <$> sides tabs' = fromFoldable $ tab frontends session query <$> sides
......
module Gargantext.Components.Nodes.Lists where module Gargantext.Components.Nodes.Lists where
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (launchAff_) import Effect.Aff (launchAff_)
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
...@@ -41,6 +39,7 @@ listsWithSessionContextCpt = here.component "listsWithSessionContext" cpt where ...@@ -41,6 +39,7 @@ listsWithSessionContextCpt = here.component "listsWithSessionContext" cpt where
type CommonPropsNoSession = type CommonPropsNoSession =
( nodeId :: Int ( nodeId :: Int
, reloadForest :: T2.ReloadS , reloadForest :: T2.ReloadS
, reloadMainPage :: T2.ReloadS
, reloadRoot :: T2.ReloadS , reloadRoot :: T2.ReloadS
, sessionUpdate :: Session -> Effect Unit , sessionUpdate :: Session -> Effect Unit
, sidePanel :: T.Box (Maybe (Record SidePanel)) , sidePanel :: T.Box (Maybe (Record SidePanel))
...@@ -72,12 +71,16 @@ listsLayoutWithKeyCpt :: R.Component KeyProps ...@@ -72,12 +71,16 @@ listsLayoutWithKeyCpt :: R.Component KeyProps
listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
cpt { nodeId cpt { nodeId
, reloadForest , reloadForest
, reloadMainPage
, reloadRoot , reloadRoot
, session , session
, sessionUpdate , sessionUpdate
, sidePanel , sidePanel
, sidePanelState , sidePanelState
, tasks } _ = do , tasks } _ = do
activeTab <- T.useBox 0
reloadMainPage' <- T.useLive T.unequal reloadMainPage
let path = { nodeId, session } let path = { nodeId, session }
cacheState <- T.useBox $ getCacheState CacheOn session nodeId cacheState <- T.useBox $ getCacheState CacheOn session nodeId
...@@ -101,7 +104,8 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where ...@@ -101,7 +104,8 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
, title: "Corpus " <> name , title: "Corpus " <> name
, user: authors } [] , user: authors } []
, Tabs.tabs { , Tabs.tabs {
cacheState activeTab
, cacheState
, corpusData , corpusData
, corpusId , corpusId
, key: "listsLayoutWithKey-tabs-" <> (show cacheState') , key: "listsLayoutWithKey-tabs-" <> (show cacheState')
......
...@@ -34,13 +34,14 @@ here :: R2.Here ...@@ -34,13 +34,14 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Lists.Tabs" here = R2.here "Gargantext.Components.Nodes.Lists.Tabs"
type Props = ( type Props = (
cacheState :: T.Box CacheState activeTab :: T.Box Int
, corpusData :: CorpusData , cacheState :: T.Box CacheState
, corpusId :: Int , corpusData :: CorpusData
, reloadForest :: T2.ReloadS , corpusId :: Int
, reloadRoot :: T2.ReloadS , reloadForest :: T2.ReloadS
, session :: Session , reloadRoot :: T2.ReloadS
, tasks :: T.Box GAT.Storage , session :: Session
, tasks :: T.Box GAT.Storage
) )
type PropsWithKey = ( key :: String | Props ) type PropsWithKey = ( key :: String | Props )
...@@ -50,9 +51,9 @@ tabs props = R.createElement tabsCpt props [] ...@@ -50,9 +51,9 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component PropsWithKey tabsCpt :: R.Component PropsWithKey
tabsCpt = here.component "tabs" cpt where tabsCpt = here.component "tabs" cpt where
cpt props _ = do cpt props@{ activeTab } _ = do
(selected /\ setSelected) <- R.useState' 0 pure $ Tab.tabs { activeTab
pure $ Tab.tabs { selected, tabs: tabs' } where , tabs: tabs' } where
tabs' = [ "Terms" /\ view Terms [] tabs' = [ "Terms" /\ view Terms []
, "Authors" /\ view Authors [] , "Authors" /\ view Authors []
, "Institutes" /\ view Institutes [] , "Institutes" /\ view Institutes []
......
...@@ -160,8 +160,10 @@ tabsCpt = here.component "tabs" cpt ...@@ -160,8 +160,10 @@ tabsCpt = here.component "tabs" cpt
cpt { cacheState, corpusId, corpusData, frontends, session, sidePanel, sidePanelState } _ = do cpt { cacheState, corpusId, corpusData, frontends, session, sidePanel, sidePanelState } _ = do
let path = initialPath let path = initialPath
activeTab <- T.useBox 0
pure $ Tab.tabs { pure $ Tab.tabs {
selected: 0 activeTab
, tabs: [ , tabs: [
"Documents" /\ R.fragment [ "Documents" /\ R.fragment [
histo { path, session } histo { path, session }
......
...@@ -352,6 +352,7 @@ listsCpt = here.component "lists" cpt where ...@@ -352,6 +352,7 @@ listsCpt = here.component "lists" cpt where
, forestOpen , forestOpen
, handed , handed
, reloadForest , reloadForest
, reloadMainPage
, reloadRoot , reloadRoot
, route , route
, sessions , sessions
...@@ -366,6 +367,7 @@ listsCpt = here.component "lists" cpt where ...@@ -366,6 +367,7 @@ listsCpt = here.component "lists" cpt where
pure $ authed sessionProps $ pure $ authed sessionProps $
Lists.listsWithSessionContext { nodeId Lists.listsWithSessionContext { nodeId
, reloadForest , reloadForest
, reloadMainPage
, reloadRoot , reloadRoot
, session , session
, sessionUpdate: \_ -> pure unit , sessionUpdate: \_ -> pure unit
......
module Gargantext.Components.Tab where module Gargantext.Components.Tab where
import Prelude hiding (div)
import Data.FunctorWithIndex (mapWithIndex) import Data.FunctorWithIndex (mapWithIndex)
import Data.Tuple (Tuple) import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
...@@ -8,14 +7,16 @@ import Reactix as R ...@@ -8,14 +7,16 @@ import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T import Toestand as T
import Gargantext.Prelude
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Tab" here = R2.here "Gargantext.Components.Tab"
type TabsProps = ( type TabsProps = (
selected :: Int activeTab :: T.Box Int
, tabs :: Array (Tuple String R.Element) , tabs :: Array (Tuple String R.Element)
) )
tabs :: R2.Leaf TabsProps tabs :: R2.Leaf TabsProps
...@@ -24,18 +25,17 @@ tabs props = R.createElement tabsCpt props [] ...@@ -24,18 +25,17 @@ tabs props = R.createElement tabsCpt props []
-- this is actually just the list of tabs, not the tab contents itself -- this is actually just the list of tabs, not the tab contents itself
tabsCpt :: R.Component TabsProps tabsCpt :: R.Component TabsProps
tabsCpt = here.component "tabs" cpt where tabsCpt = here.component "tabs" cpt where
cpt props _ = do cpt props@{ activeTab, tabs } _ = do
activeTab <- T.useBox props.selected
activeTab' <- T.useLive T.unequal activeTab activeTab' <- T.useLive T.unequal activeTab
pure $ H.div {} pure $ H.div {}
[ H.nav {} [ H.nav {}
[ H.br {} [ H.br {}
, H.div { className: "nav nav-tabs", title: "Search result" } , H.div { className: "nav nav-tabs", title: "Search result" }
(mapWithIndex (button activeTab activeTab') props.tabs) (mapWithIndex (button activeTab activeTab') tabs)
] ]
, H.div { className: "tab-content" } , H.div { className: "tab-content" }
(mapWithIndex (item activeTab') props.tabs) (mapWithIndex (item activeTab') tabs)
] ]
button activeTab selected index (name /\ _) = button activeTab selected index (name /\ _) =
H.a { className, on: { click } } [ H.text name ] where H.a { className, on: { click } } [ H.text name ] where
......
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