Commit bb5ba306 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev-bootstrap-v4-upgrade' of...

Merge branch 'dev-bootstrap-v4-upgrade' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into dev-merge
parents 97bad477 5ddf1bee
......@@ -16,6 +16,7 @@ import Gargantext.Prelude
import Gargantext.Types as GT
import Gargantext.Utils as GU
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
localStorageKey :: String
......@@ -48,15 +49,15 @@ removeTaskFromList ts (GT.AsyncTaskWithType { task: GT.AsyncTask { id: id' } })
A.filter (\(GT.AsyncTaskWithType { task: GT.AsyncTask { id: id'' } }) -> id' /= id'') ts
type ReductorProps = (
appReload :: GT.ReloadS
, treeReload :: GT.ReloadS
appReload :: GUR.ReloadS
, treeReload :: GUR.ReloadS
, storage :: Storage
)
type Reductor = R2.Reductor (Record ReductorProps) Action
type ReductorAction = Action -> Effect Unit
useTasks :: GT.ReloadS -> GT.ReloadS -> R.Hooks Reductor
useTasks :: GUR.ReloadS -> GUR.ReloadS -> R.Hooks Reductor
useTasks appReload treeReload = R2.useReductor act initializer unit
where
act :: R2.Actor (Record ReductorProps) Action
......@@ -72,18 +73,18 @@ data Action =
action :: Record ReductorProps -> Action -> Effect (Record ReductorProps)
action p@{ treeReload, storage } (Insert nodeId t) = do
_ <- snd treeReload $ (_ + 1)
_ <- GUR.bump treeReload
let newStorage = Map.alter (maybe (Just [t]) (\ts -> Just $ A.cons t ts)) nodeId storage
pure $ p { storage = newStorage }
action p (Finish nodeId t) = do
action p (Remove nodeId t)
action p@{ appReload, treeReload, storage } (Remove nodeId t@(GT.AsyncTaskWithType { typ })) = do
_ <- if GT.asyncTaskTriggersAppReload typ then
snd appReload $ (_ + 1)
GUR.bump appReload
else
pure unit
_ <- if GT.asyncTaskTriggersTreeReload typ then
snd treeReload $ (_ + 1)
GUR.bump treeReload
else
pure unit
let newStorage = Map.alter (maybe Nothing $ (\ts -> Just $ removeTaskFromList ts t)) nodeId storage
......
......@@ -30,6 +30,7 @@ import Gargantext.Routes (AppRoute(..))
import Gargantext.Sessions (useSessions)
import Gargantext.Sessions as Sessions
import Gargantext.Types as GT
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.App"
......@@ -48,12 +49,12 @@ appCpt = R.hooksComponentWithModule thisModule "app" cpt where
route <- useHashRouter router Home
asyncTasksRef <- R.useRef Nothing
treeReloadRef <- R.useRef Nothing
treeReloadRef <- GUR.newI
showLogin <- R.useState' false
backend <- R.useState' Nothing
appReload <- R.useState' 0
appReload <- GUR.new
showCorpus <- R.useState' false
......
......@@ -36,11 +36,12 @@ import Gargantext.Hooks.Loader (useLoader, useLoaderWithCacheAPI, HashedResponse
import Gargantext.Routes as Routes
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, sessionId, get, delete)
import Gargantext.Types (ListId, NodeID, NodeType(..), OrderBy(..), ReloadS, TableResult, TabSubType, TabType, showTabType')
import Gargantext.Types (ListId, NodeID, NodeType(..), OrderBy(..), TableResult, TabSubType, TabType, showTabType')
import Gargantext.Utils (sortWith)
import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.QueryString (joinQueryStrings, mQueryParamS, queryParam, queryParamS)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.DocsTable"
......@@ -415,7 +416,7 @@ type DocChooser = (
, nodeId :: NodeID
, selected :: Boolean
, sidePanelTriggers :: Record SidePanelTriggers
, tableReload :: ReloadS
, tableReload :: GUR.ReloadS
)
docChooser :: R2.Component DocChooser
......@@ -432,7 +433,7 @@ docChooserCpt = R.hooksComponentWithModule thisModule "docChooser" cpt
, nodeId
, selected
, sidePanelTriggers: { triggerAnnotatedDocIdChange }
, tableReload: (_ /\ setReload) } _ = do
, tableReload } _ = do
let eyeClass = if selected then "fa-eye" else "fa-eye-slash"
......@@ -446,7 +447,7 @@ docChooserCpt = R.hooksComponentWithModule thisModule "docChooser" cpt
-- log2 "[docChooser] onClick, corpusId" corpusId
-- log2 "[docChooser] onClick, nodeId" nodeId
R2.callTrigger triggerAnnotatedDocIdChange { corpusId, listId, nodeId }
setReload $ (_ + 1)
GUR.bump tableReload
newtype SearchQuery = SearchQuery {
......
......@@ -17,14 +17,15 @@ import Gargantext.Ends (Frontends, Backend(..))
import Gargantext.Prelude
import Gargantext.Routes (AppRoute)
import Gargantext.Sessions (Session(..), Sessions, OpenNodes, unSessions)
import Gargantext.Types (Reload, ReloadS, Handed(..))
import Gargantext.Types (Handed(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.Forest"
type Props = (
appReload :: ReloadS
appReload :: GUR.ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, backend :: R.State (Maybe Backend)
, currentRoute :: AppRoute
......@@ -32,7 +33,7 @@ type Props = (
, handed :: Handed
, sessions :: Sessions
, showLogin :: R.Setter Boolean
, treeReloadRef :: R.Ref (Maybe ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
)
forest :: R2.Component Props
......@@ -51,16 +52,14 @@ forest = R.createElement forestCpt
, showLogin
, treeReloadRef } _ = do
-- NOTE: this is a hack to reload the tree view on demand
reload <- R.useState' (0 :: Reload)
reload <- GUR.new
asyncTasks <- GAT.useTasks appReload reload
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes)
-- TODO If `treeReloadRef` is set, `reload` state should be updated
R.useEffect' $ do
R.setRef asyncTasksRef $ Just asyncTasks
case R.readRef treeReloadRef of
Nothing -> R.setRef treeReloadRef $ Just reload
Just _ -> pure unit
GUR.initializeI treeReloadRef reload
R2.useCache (
frontends
......@@ -112,7 +111,7 @@ plus handed showLogin backend = H.div { className: "row" } [
-------------------------
type ForestLayoutProps = (
appReload :: ReloadS
appReload :: GUR.ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, backend :: R.State (Maybe Backend)
, currentRoute :: AppRoute
......@@ -120,7 +119,7 @@ type ForestLayoutProps = (
, handed :: R.State Handed
, sessions :: Sessions
, showLogin :: R.Setter Boolean
, treeReloadRef :: R.Ref (Maybe ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
)
forestLayout :: R2.Component ForestLayoutProps
......
This diff is collapsed.
......@@ -36,13 +36,14 @@ import Gargantext.Types (Name, ID)
import Gargantext.Types as GT
import Gargantext.Utils.Popover as Popover
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.Forest.Tree.Node"
-- Main Node
type NodeMainSpanProps = (
appReload :: GT.ReloadS
appReload :: GUR.ReloadS
, asyncTasks :: GAT.Reductor
, currentRoute :: Routes.AppRoute
, folderOpen :: R.State Boolean
......@@ -151,7 +152,7 @@ nodeMainSpan = R.createElement nodeMainSpanCpt
where
onTaskFinish id t _ = do
dispatchAsyncTasks $ GAT.Finish id t
snd appReload $ (_ + 1)
GUR.bump appReload
SettingsBox {show: showBox} = settingsBox nodeType
onPopoverClose popoverRef _ = Popover.setOpen popoverRef false
......
......@@ -37,6 +37,7 @@ import Gargantext.Sessions (Session, Sessions, get)
import Gargantext.Types as Types
import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.GraphExplorer"
......@@ -55,7 +56,7 @@ type LayoutProps = (
type Props =
( graph :: SigmaxT.SGraph
, graphVersion :: Types.ReloadS
, graphVersion :: GUR.ReloadS
, hyperdataGraph :: GET.HyperdataGraph
, mMetaData :: Maybe GET.MetaData
| LayoutProps
......@@ -69,10 +70,10 @@ explorerLayoutCpt :: R.Component LayoutProps
explorerLayoutCpt = R.hooksComponentWithModule thisModule "explorerLayout" cpt
where
cpt props _ = do
graphVersion <- R.useState' 0
graphVersion <- GUR.new
pure $ explorerLayoutView graphVersion props
explorerLayoutView :: Types.ReloadS -> Record LayoutProps -> R.Element
explorerLayoutView :: GUR.ReloadS -> Record LayoutProps -> R.Element
explorerLayoutView graphVersion p = R.createElement el p []
where
el = R.hooksComponentWithModule thisModule "explorerLayoutView" cpt
......@@ -115,16 +116,16 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt
dataRef <- R.useRef graph
graphRef <- R.useRef null
graphVersionRef <- R.useRef (fst graphVersion)
treeReload <- R.useState' 0
treeReloadRef <- R.useRef $ Just treeReload
controls <- Controls.useGraphControls { forceAtlasS
, graph
, graphId
, hyperdataGraph
, session
, treeReload: \_ -> (snd treeReload) $ (+) 1
}
graphVersionRef <- R.useRef (GUR.value graphVersion)
treeReload <- GUR.new
treeReloadRef <- GUR.newIInitialized treeReload
controls <- Controls.useGraphControls { forceAtlasS
, graph
, graphId
, hyperdataGraph
, session
, treeReload: \_ -> GUR.bump treeReload
}
multiSelectEnabledRef <- R.useRef $ fst controls.multiSelectEnabled
R.useEffect' $ do
......@@ -137,7 +138,7 @@ explorerCpt = R.hooksComponentWithModule thisModule "explorer" cpt
let rSigma = R.readRef controls.sigmaRef
Sigmax.cleanupSigma rSigma "explorerCpt"
R.setRef dataRef graph
R.setRef graphVersionRef (fst graphVersion)
R.setRef graphVersionRef (GUR.value graphVersion)
-- Reinitialize bunch of state as well.
snd controls.removedNodeIds $ const SigmaxT.emptyNodeIds
snd controls.selectedNodeIds $ const SigmaxT.emptyNodeIds
......@@ -246,23 +247,23 @@ type TreeProps =
, currentRoute :: AppRoute
, frontends :: Frontends
, handed :: Types.Handed
, reload :: Types.ReloadS
, reload :: GUR.ReloadS
, sessions :: Sessions
, show :: Boolean
, showLogin :: R.Setter Boolean
, treeReloadRef :: R.Ref (Maybe Types.ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
)
type MSidebarProps =
( frontends :: Frontends
, graph :: SigmaxT.SGraph
, graphId :: GET.GraphId
, graphVersion :: Types.ReloadS
, graphVersion :: GUR.ReloadS
, removedNodeIds :: R.State SigmaxT.NodeIds
, showSidePanel :: R.State GET.SidePanelState
, selectedNodeIds :: R.State SigmaxT.NodeIds
, session :: Session
, treeReload :: Types.ReloadS
, treeReload :: GUR.ReloadS
)
type GraphProps = (
......@@ -370,11 +371,11 @@ modeGraphType Types.Sources = "star"
modeGraphType Types.Terms = "def"
getNodes :: Session -> Types.ReloadS -> GET.GraphId -> Aff GET.HyperdataGraph
getNodes session (graphVersion /\ _) graphId =
getNodes :: Session -> GUR.ReloadS -> GET.GraphId -> Aff GET.HyperdataGraph
getNodes session graphVersion graphId =
get session $ NodeAPI Types.Graph
(Just graphId)
("?version=" <> show graphVersion)
("?version=" <> (show $ GUR.value graphVersion))
transformGraph :: Record Controls.Controls -> SigmaxT.SGraph -> SigmaxT.SGraph
......
......@@ -32,8 +32,9 @@ import Gargantext.Data.Array (mapMaybe)
import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType, ReloadS, TabSubType(..), TabType(..), TermList(..), modeTabType)
import Gargantext.Types (CTabNgramType, TabSubType(..), TabType(..), TermList(..), modeTabType)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Partial.Unsafe (unsafePartial)
thisModule = "Gargantext.Components.GraphExplorer.Sidebar"
......@@ -42,13 +43,13 @@ type Props =
( frontends :: Frontends
, graph :: SigmaxT.SGraph
, graphId :: Int
, graphVersion :: ReloadS
, graphVersion :: GUR.ReloadS
, metaData :: GET.MetaData
, removedNodeIds :: R.State SigmaxT.NodeIds
, selectedNodeIds :: R.State SigmaxT.NodeIds
, session :: Session
, showSidePanel :: R.State GET.SidePanelState
, treeReload :: ReloadS
, treeReload :: GUR.ReloadS
)
sidebar :: Record Props -> R.Element
......@@ -204,7 +205,7 @@ type DeleteNodes =
, nodes :: Array (Record SigmaxT.Node)
, session :: Session
, termList :: TermList
, treeReload :: ReloadS
, treeReload :: GUR.ReloadS
)
deleteNodes :: Record DeleteNodes -> Effect Unit
......@@ -215,7 +216,7 @@ deleteNodes { graphId, metaData, nodes, session, termList, treeReload } = do
case mPatch of
Nothing -> pure unit
Just (NTC.Versioned patch) -> do
liftEffect $ snd treeReload $ (+) 1
liftEffect $ GUR.bump treeReload
-- Why is this called delete node?
deleteNode :: TermList
......
......@@ -45,10 +45,11 @@ import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as T
import Gargantext.Routes (SessionRoute(..)) as R
import Gargantext.Sessions (Session, get)
import Gargantext.Types (CTabNgramType, OrderBy(..), ReloadS, SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
import Gargantext.Utils (queryMatchesLabel, toggleSet, sortWith)
import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Seq (mapMaybe) as Seq
thisModule :: String
......@@ -280,11 +281,11 @@ tableContainerCpt { dispatch
type CommonProps = (
afterSync :: Unit -> Aff Unit
, appReload :: ReloadS
, appReload :: GUR.ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, sidePanelTriggers :: Record NT.SidePanelTriggers
, tabNgramType :: CTabNgramType
, treeReloadRef :: R.Ref (Maybe ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
, withAutoUpdate :: Boolean
)
......@@ -324,7 +325,7 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
]
, search ]
<>
[ T.table { syncResetButton
[ T.table { syncResetButton: [ syncResetButton ]
, colNames
, container: tableContainer { dispatch: performAction
, ngramsChildren
......@@ -333,7 +334,7 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
, ngramsTable
, path
, tabNgramType
, syncResetButton
, syncResetButton: [ syncResetButton ]
}
, params: params /\ setParams -- TODO-LENS
, rows: filteredConvertedRows
......@@ -343,13 +344,14 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
, ngramsSelection
}
}
] <> syncResetButton
, syncResetButton ]
where
afterSync = chartsAfterSync path' asyncTasksRef nodeId treeReloadRef
syncResetButton = syncResetBtns (chartsAfterSync path' asyncTasksRef nodeId treeReloadRef)
ngramsLocalPatch
performAction
syncResetButton = syncResetButtons { afterSync
, ngramsLocalPatch
, performAction: performAction <<< CoreAction }
autoUpdate :: Array R.Element
......@@ -359,12 +361,7 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
{ duration: 5000
, effect: performAction
$ CoreAction
$ Synchronize { afterSync: chartsAfterSync
path'
asyncTasksRef
nodeId
treeReloadRef
}
$ Synchronize { afterSync }
}
]
else []
......
......@@ -70,9 +70,7 @@ module Gargantext.Components.NgramsTable.Core
-- Reset Button TODO put elsewhere this file is too big
, SyncResetButtonsProps
, syncResetButtons
, syncResetButtonsCpt
, chartsAfterSync
, syncResetBtns
)
where
......@@ -136,8 +134,9 @@ import Gargantext.Components.Table.Types as T
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get, post, put)
import Gargantext.Types (AsyncTaskType(..), AsyncTaskWithType(..), CTabNgramType(..), ListId, OrderBy(..), ScoreType(..), TabSubType(..), TabType(..), TermList(..), TermSize(..), ReloadS)
import Gargantext.Types (AsyncTaskType(..), AsyncTaskWithType(..), CTabNgramType(..), ListId, OrderBy(..), ScoreType(..), TabSubType(..), TabType(..), TermList(..), TermSize(..))
import Gargantext.Utils.KarpRabin (indicesOfAny)
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.NgramsTable.Core"
......@@ -1099,10 +1098,10 @@ type SyncResetButtonsProps =
syncResetButtons :: Record SyncResetButtonsProps -> R.Element
syncResetButtons p = R.createElement syncResetButtonsCpt p []
syncResetButtonsCpt :: R.Component SyncResetButtonsProps
syncResetButtonsCpt = R.hooksComponentWithModule thisModule "syncResetButtons" cpt
where
syncResetButtonsCpt :: R.Component SyncResetButtonsProps
syncResetButtonsCpt = R.hooksComponentWithModule thisModule "syncResetButtons" cpt
cpt { afterSync, ngramsLocalPatch, performAction } _ = do
synchronizing@(s /\ setSynchronizing) <- R.useState' false
......@@ -1121,13 +1120,17 @@ syncResetButtonsCpt = R.hooksComponentWithModule thisModule "syncResetButtons" c
afterSync x
liftEffect $ setSynchronizing $ const false
pure $ H.div {} [
H.button { className: "btn btn-danger " <> hasChangesClass
, on: { click: resetClick }
} [ H.text "Reset" ]
, H.button { className: "btn btn-primary " <> hasChangesClass
pure $ H.div { className: "btn-toolbar" }
[ H.div { className: "btn-group mr-2" }
[ H.button { className: "btn btn-danger " <> hasChangesClass
, on: { click: resetClick }
} [ H.text "Reset" ]
]
, H.div { className: "btn-group mr-2" }
[ H.button { className: "btn btn-primary " <> hasChangesClass
, on: { click: synchronizeClick }
} [ H.text "Sync" ]
]
]
......@@ -1136,14 +1139,6 @@ type ResetButton = (Unit -> Aff Unit)
-> (Action -> Effect Unit)
-> Array R.Element
syncResetBtns :: ResetButton
syncResetBtns chartsAfterSync' ngramsLocalPatch performAction = [ syncResetButtons
{ afterSync: chartsAfterSync'
, ngramsLocalPatch
, performAction: performAction <<< CoreAction
}
]
chartsAfterSync :: forall props discard.
{ listIds :: Array Int
, nodeId :: Int
......@@ -1153,7 +1148,7 @@ chartsAfterSync :: forall props discard.
}
-> R.Ref (Maybe GAT.Reductor)
-> Int
-> R.Ref (Maybe ReloadS)
-> GUR.ReloadWithInitializeRef
-> discard
-> Aff Unit
chartsAfterSync path' asyncTasksRef nodeId treeReloadRef _ = do
......@@ -1164,11 +1159,7 @@ chartsAfterSync path' asyncTasksRef nodeId treeReloadRef _ = do
Nothing -> log "[chartsAfterSync] asyncTasksRef is Nothing"
Just asyncTasks -> do
snd asyncTasks $ GAT.Insert nodeId task
case R.readRef treeReloadRef of
Nothing -> log "[chartsAfterSync] can't reload tree: ref empty"
Just treeReload -> do
snd treeReload $ (_ + 1)
-- snd appReload $ (_ + 1)
GUR.bumpI treeReloadRef
postNgramsChartsAsync :: forall s. CoreParams s -> Aff AsyncTaskWithType
postNgramsChartsAsync { listIds, nodeId, session, tabType } = do
......
......@@ -25,8 +25,9 @@ import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Unit, bind, const, discard, pure, show, unit, ($), (+), (<$>), (<<<), (<>), (==))
import Gargantext.Routes as Routes
import Gargantext.Sessions (Session, get, put, sessionId)
import Gargantext.Types (NodeType(..), ReloadS)
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.Nodes.Annuaire.User.Contacts"
......@@ -150,12 +151,12 @@ listElement :: Array R.Element -> R.Element
listElement = H.li { className: "list-group-item justify-content-between" }
type LayoutProps = (
appReload :: ReloadS
appReload :: GUR.ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, frontends :: Frontends
, nodeId :: Int
, session :: Session
, treeReloadRef :: R.Ref (Maybe ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
)
type KeyLayoutProps = (
......@@ -189,13 +190,13 @@ userLayoutWithKeyCpt :: R.Component KeyLayoutProps
userLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "userLayoutWithKey" cpt
where
cpt { appReload, asyncTasksRef, frontends, nodeId, session, treeReloadRef } _ = do
reload <- R.useState' 0
reload <- GUR.new
cacheState <- R.useState' LT.CacheOn
sidePanelTriggers <- LT.emptySidePanelTriggers
useLoader {nodeId, reload: fst reload, session} getContactWithReload $
useLoader {nodeId, reload: GUR.value reload, session} getContactWithReload $
\contactData@{contactNode: Contact {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" } [
display { title: fromMaybe "no name" name } (contactInfos hyperdata (onUpdateHyperdata reload))
......@@ -212,11 +213,11 @@ userLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "userLayoutWithKey"
}
]
where
onUpdateHyperdata :: ReloadS -> HyperdataUser -> Effect Unit
onUpdateHyperdata (_ /\ setReload) hd = do
onUpdateHyperdata :: GUR.ReloadS -> HyperdataUser -> Effect Unit
onUpdateHyperdata reload hd = do
launchAff_ $ do
_ <- saveContactHyperdata session nodeId hd
liftEffect $ setReload $ (+) 1
liftEffect $ GUR.bump reload
-- | toUrl to get data
getContact :: Session -> Int -> Aff ContactData
......@@ -231,7 +232,7 @@ getContact session id = do
-- throwError $ error "Missing default list"
pure {contactNode, defaultListId: 424242}
getContactWithReload :: {nodeId :: Int, reload :: Int, session :: Session} -> Aff ContactData
getContactWithReload :: {nodeId :: Int, reload :: GUR.Reload, session :: Session} -> Aff ContactData
getContactWithReload {nodeId, session} = getContact session nodeId
saveContactHyperdata :: Session -> Int -> HyperdataUser -> Aff Int
......
......@@ -20,7 +20,8 @@ import Gargantext.Components.Nodes.Lists.Types as LTypes
import Gargantext.Components.Nodes.Texts.Types as TTypes
import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType(..), NodeID, PTabNgramType(..), ReloadS, TabType(..), TabSubType(..))
import Gargantext.Types (CTabNgramType(..), NodeID, PTabNgramType(..), TabType(..), TabSubType(..))
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs"
......@@ -47,7 +48,7 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors
type TabsProps = (
appReload :: ReloadS
appReload :: GUR.ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State LTypes.CacheState
, contactData :: ContactData
......@@ -55,7 +56,7 @@ type TabsProps = (
, nodeId :: Int
, session :: Session
, sidePanelTriggers :: Record LTypes.SidePanelTriggers
, treeReloadRef :: R.Ref (Maybe ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
)
tabs :: Record TabsProps -> R.Element
......@@ -129,7 +130,7 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
type NgramsViewTabsProps = (
appReload :: ReloadS
appReload :: GUR.ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State LTypes.CacheState
, defaultListId :: Int
......@@ -137,7 +138,7 @@ type NgramsViewTabsProps = (
, nodeId :: Int
, session :: Session
, sidePanelTriggers :: Record LTypes.SidePanelTriggers
, treeReloadRef :: R.Ref (Maybe ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
)
ngramsView :: Record NgramsViewTabsProps -> R.Element
......
......@@ -26,9 +26,10 @@ import Gargantext.Data.Array as GDA
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(NodeAPI, Children))
import Gargantext.Sessions (Session, get, put, sessionId)
import Gargantext.Types (NodeType(..), AffTableResult, ReloadS)
import Gargantext.Types (NodeType(..), AffTableResult)
import Gargantext.Utils.Crypto as Crypto
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.Nodes.Corpus"
......@@ -62,14 +63,14 @@ corpusLayoutWithKeyCpt :: R.Component KeyProps
corpusLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "corpusLayoutWithKey" cpt
where
cpt { nodeId, session } _ = do
reload <- R.useState' 0
reload <- GUR.new
useLoader {nodeId, reload: fst reload, session} loadCorpusWithReload $
useLoader {nodeId, reload: GUR.value reload, session} loadCorpusWithReload $
\corpus -> corpusLayoutView {corpus, nodeId, reload, session}
type ViewProps =
( corpus :: NodePoly Hyperdata
, reload :: ReloadS
, reload :: GUR.ReloadS
| Props
)
......@@ -123,15 +124,15 @@ corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" c
onClickSave :: forall e. { fields :: R.State FTFieldsWithIndex
, nodeId :: Int
, reload :: ReloadS
, reload :: GUR.ReloadS
, session :: Session } -> e -> Effect Unit
onClickSave {fields: (fieldsS /\ _), nodeId, reload: (_ /\ setReload), session} _ = do
onClickSave {fields: (fieldsS /\ _), nodeId, reload, session} _ = do
log2 "[corpusLayoutViewCpt] onClickSave fieldsS" fieldsS
launchAff_ do
saveCorpus $ { hyperdata: Hyperdata {fields: (\(Tuple _ f) -> f) <$> fieldsS}
, nodeId
, session }
liftEffect $ setReload $ (+) 1
liftEffect $ GUR.bump reload
onClickAdd :: forall e. R.State FTFieldsWithIndex -> e -> Effect Unit
onClickAdd (_ /\ setFieldsS) _ = do
......@@ -173,12 +174,12 @@ fieldsCodeEditorCpt = R.hooksComponentWithModule thisModule "fieldsCodeEditorCpt
fromMaybe fields $
List.modifyAt idx (\(Tuple _ (Field f)) -> Tuple idx (Field $ f { typ = typ })) fields
onMoveDown :: ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveDown :: GUR.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveDown (_ /\ setMasterKey) (fs /\ setFields) idx _ = do
setMasterKey $ (+) 1
setFields $ recomputeIndices <<< (GDA.swapList idx (idx + 1))
onMoveUp :: ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveUp :: GUR.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveUp (_ /\ setMasterKey) (_ /\ setFields) idx _ = do
setMasterKey $ (+) 1
setFields $ recomputeIndices <<< (GDA.swapList idx (idx - 1))
......@@ -401,7 +402,7 @@ loadCorpus' :: Record LoadProps -> Aff (NodePoly Hyperdata)
loadCorpus' {nodeId, session} = get session $ NodeAPI Corpus (Just nodeId) ""
-- Just to make reloading effective
loadCorpusWithReload :: {reload :: Int | LoadProps} -> Aff (NodePoly Hyperdata)
loadCorpusWithReload :: {reload :: GUR.Reload | LoadProps} -> Aff (NodePoly Hyperdata)
loadCorpusWithReload {nodeId, session} = loadCorpus' {nodeId, session}
type SaveProps = (
......@@ -452,7 +453,7 @@ loadCorpusWithChild { nodeId: childId, session } = do
type LoadWithReloadProps =
(
reload :: Int
reload :: GUR.Reload
| LoadProps
)
......
......@@ -8,7 +8,7 @@ import Reactix as R
import Gargantext.Prelude
import Gargantext.Components.Nodes.Corpus.Chart.Types (Reload, Path, Props, MetricsProps, ReloadPath)
import Gargantext.Components.Nodes.Corpus.Chart.Types (Path, Props, MetricsProps, ReloadPath)
import Gargantext.Hooks.Loader (HashedResponse, useLoader, useLoaderWithCacheAPI)
import Gargantext.Utils.Crypto (Hash)
import Gargantext.Sessions (Session)
......
......@@ -64,7 +64,7 @@ chartOptions (HistoMetrics { dates: dates', count: count'}) = Options
, series : [seriesBarD1 {name: "Number of publication / year"} $
map (\n -> dataSerie {value: n, itemStyle : itemStyle {color:grey}}) count'] }
getMetricsHash :: Session -> Tuple Reload (Record Path) -> Aff String
getMetricsHash :: Session -> ReloadPath -> Aff String
getMetricsHash session (_ /\ { corpusId, limit, listId, tabType }) = do
get session $ ChartHash { chartType: Histo, listId: mListId, tabType } (Just corpusId)
where
......
......@@ -101,7 +101,7 @@ scatterOptions metrics' = Options
}
--}
getMetricsHash :: Session -> Tuple Reload (Record Path) -> Aff String
getMetricsHash :: Session -> ReloadPath -> Aff String
getMetricsHash session (_ /\ { corpusId, listId, tabType }) =
get session $ CorpusMetricsHash { listId, tabType } (Just corpusId)
......
......@@ -84,7 +84,7 @@ chartOptionsPie (HistoMetrics { dates: dates', count: count'}) = Options
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
}
getMetricsHash :: Session -> Tuple Reload (Record Path) -> Aff String
getMetricsHash :: Session -> ReloadPath -> Aff String
getMetricsHash session (_ /\ { corpusId, limit, listId, tabType }) = do
get session $ ChartHash { chartType: ChartPie, listId: mListId, tabType } (Just corpusId)
where
......
......@@ -56,7 +56,7 @@ scatterOptions nodes = Options
}
getMetricsHash :: Session -> Tuple Reload (Record Path) -> Aff String
getMetricsHash :: Session -> ReloadPath -> Aff String
getMetricsHash session (_ /\ { corpusId, limit, listId, tabType }) = do
get session $ ChartHash { chartType: ChartTree, listId: mListId, tabType } (Just corpusId)
where
......
......@@ -5,9 +5,8 @@ import Data.Tuple (Tuple)
import Reactix as R
import Gargantext.Sessions (Session)
import Gargantext.Types (ReloadS, TabType)
type Reload = Int
import Gargantext.Types (TabType)
import Gargantext.Utils.Reload as GUR
type Path = (
corpusId :: Int
......@@ -22,8 +21,8 @@ type Props = (
)
type MetricsProps = (
reload :: ReloadS
reload :: GUR.ReloadS
| Props
)
type ReloadPath = Tuple Reload (Record Path)
type ReloadPath = Tuple GUR.Reload (Record Path)
......@@ -15,22 +15,23 @@ import Gargantext.Components.Nodes.Corpus.Chart.Types (Path)
import Gargantext.Sessions (Session)
import Gargantext.Types as T
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule = "Gargantext.Components.Nodes.Corpus.Chart.Utils"
reloadButtonWrap :: T.ReloadS -> R.Element -> R.Element
reloadButtonWrap :: GUR.ReloadS -> R.Element -> R.Element
reloadButtonWrap setReload el = H.div {} [
reloadButton setReload
, el
]
reloadButton :: T.ReloadS -> R.Element
reloadButton (_ /\ setReload) = H.a { className
, on: { click: onClick }
, title: "Reload" } []
reloadButton :: GUR.ReloadS -> R.Element
reloadButton reloadS = H.a { className
, on: { click: onClick }
, title: "Reload" } []
where
className = "reload-btn fa fa-refresh"
onClick _ = setReload $ (_ + 1)
onClick _ = GUR.bump reloadS
mNgramsTypeFromTabType :: T.TabType -> Maybe T.CTabNgramType
......@@ -44,7 +45,7 @@ mNgramsTypeFromTabType (T.TabPairing _) = Nothing
type ChartUpdateButtonProps = (
chartType :: T.ChartType
, path :: Record Path
, reload :: T.ReloadS
, reload :: GUR.ReloadS
, session :: Session
)
......@@ -56,7 +57,8 @@ chartUpdateButtonCpt = R.hooksComponentWithModule thisModule "chartUpdateButton"
where
cpt { chartType
, path: { corpusId, listId, tabType }
, reload: (_ /\ setReload), session } _ = do
, reload
, session } _ = do
pure $ H.a { className: "chart-update-button fa fa-database"
, on: { click: onClick }
......@@ -68,5 +70,5 @@ chartUpdateButtonCpt = R.hooksComponentWithModule thisModule "chartUpdateButton"
case mNgramsTypeFromTabType tabType of
Just ngramsType -> do
_ <- recomputeChart session chartType ngramsType corpusId listId
liftEffect $ setReload $ (_ + 1)
liftEffect $ GUR.bump reload
Nothing -> pure unit
......@@ -16,8 +16,9 @@ import Gargantext.Components.Nodes.Dashboard.Types as DT
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude
import Gargantext.Sessions (Session, sessionId)
import Gargantext.Types (NodeID, ReloadS)
import Gargantext.Types (NodeID)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule = "Gargantext.Components.Nodes.Corpus.Dashboard"
......@@ -49,27 +50,27 @@ dashboardLayoutWithKeyCpt :: R.Component KeyProps
dashboardLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "dashboardLayoutWithKey" cpt
where
cpt { nodeId, session } _ = do
reload <- R.useState' 0
reload <- GUR.new
useLoader {nodeId, reload: fst reload, session} DT.loadDashboardWithReload $
useLoader {nodeId, reload: GUR.value reload, session} DT.loadDashboardWithReload $
\dashboardData@{hyperdata: DT.Hyperdata h, parentId} -> do
let { charts } = h
dashboardLayoutLoaded { charts
, corpusId: parentId
, defaultListId: 0
, key: show $ fst reload
, key: show $ GUR.value reload
, nodeId
, onChange: onChange nodeId reload (DT.Hyperdata h)
, session }
where
onChange :: NodeID -> ReloadS -> DT.Hyperdata -> Array P.PredefinedChart -> Effect Unit
onChange nodeId' (_ /\ setReload) (DT.Hyperdata h) charts = do
onChange :: NodeID -> GUR.ReloadS -> DT.Hyperdata -> Array P.PredefinedChart -> Effect Unit
onChange nodeId' reload (DT.Hyperdata h) charts = do
launchAff_ do
DT.saveDashboard { hyperdata: DT.Hyperdata $ h { charts = charts }
, nodeId:nodeId'
, session }
liftEffect $ setReload $ (+) 1
liftEffect $ GUR.bump reload
type LoadedProps =
( charts :: Array P.PredefinedChart
......
......@@ -54,10 +54,10 @@ type DocViewProps = (
docView :: R2.Component DocViewProps
docView = R.createElement docViewCpt
docViewCpt :: R.Component DocViewProps
docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt
where
docViewCpt :: R.Component DocViewProps
docViewCpt = R.hooksComponentWithModule thisModule "docView" cpt
cpt { path
, loaded: loaded@{ ngramsTable: Versioned { data: initTable }, document }
, state: state@({ ngramsVersion: version, ngramsLocalPatch } /\ _)
......
......@@ -16,9 +16,10 @@ import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, get, sessionId)
import Gargantext.Types (NodeType(..), ReloadS)
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Argonaut (genericSumEncodeJson)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule = "Gargantext.Components.Nodes.Frame"
......@@ -77,14 +78,14 @@ frameLayoutWithKeyCpt :: R.Component KeyProps
frameLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "frameLayoutWithKey" cpt
where
cpt { nodeId, session, nodeType} _ = do
reload <- R.useState' 0
reload <- GUR.new
useLoader {nodeId, reload: fst reload, session} loadframeWithReload $
useLoader {nodeId, reload: GUR.value reload, session} loadframeWithReload $
\frame -> frameLayoutView {frame, nodeId, reload, session, nodeType}
type ViewProps =
( frame :: NodePoly Hyperdata
, reload :: ReloadS
, reload :: GUR.ReloadS
| Props
)
......@@ -120,6 +121,6 @@ loadframe' :: Record LoadProps -> Aff (NodePoly Hyperdata)
loadframe' {nodeId, session} = get session $ NodeAPI Node (Just nodeId) ""
-- Just to make reloading effective
loadframeWithReload :: {reload :: Int | LoadProps} -> Aff (NodePoly Hyperdata)
loadframeWithReload :: {reload :: GUR.Reload | LoadProps} -> Aff (NodePoly Hyperdata)
loadframeWithReload {nodeId, session} = loadframe' {nodeId, session}
......@@ -23,6 +23,7 @@ import Gargantext.Prelude
import Gargantext.Sessions (Session, sessionId, getCacheState, setCacheState)
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.Nodes.Lists"
......@@ -72,12 +73,12 @@ topBarCpt = R.hooksComponentWithModule thisModule "topBar" cpt
--------------------------------------------------------
type CommonProps = (
appReload :: GT.ReloadS
appReload :: GUR.ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, nodeId :: Int
, session :: Session
, sessionUpdate :: Session -> Effect Unit
, treeReloadRef :: R.Ref (Maybe GT.ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
)
type Props = (
......
......@@ -23,21 +23,22 @@ import Gargantext.Components.Nodes.Corpus.Chart.Utils (mNgramsTypeFromTabType)
import Gargantext.Components.Nodes.Lists.Types
import Gargantext.Components.Tab as Tab
import Gargantext.Sessions (Session)
import Gargantext.Types (ChartType(..), CTabNgramType(..), Mode(..), ReloadS, TabSubType(..), TabType(..), chartTypeFromString, modeTabType)
import Gargantext.Types (ChartType(..), CTabNgramType(..), Mode(..), TabSubType(..), TabType(..), chartTypeFromString, modeTabType)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
thisModule :: String
thisModule = "Gargantext.Components.Nodes.Lists.Tabs"
type Props = (
appReload :: ReloadS
appReload :: GUR.ReloadS
, asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
, cacheState :: R.State CacheState
, corpusData :: CorpusData
, corpusId :: Int
, session :: Session
, sidePanelTriggers :: Record SidePanelTriggers
, treeReloadRef :: R.Ref (Maybe ReloadS)
, treeReloadRef :: GUR.ReloadWithInitializeRef
)
type PropsWithKey = (
......@@ -98,7 +99,7 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
} _ = do
chartType <- R.useState' Histo
chartsReload <- R.useState' 0
chartsReload <- GUR.new
pathS <- R.useState' $ NTC.initialPageParams session initialPath.corpusId [initialPath.listId] initialPath.tabType
let listId' = fromMaybe defaultListId $ A.head (fst pathS).listIds
let path = {
......@@ -133,14 +134,14 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
]
)
where
afterSync (_ /\ setChartsReload) _ = do
afterSync chartsReload _ = do
case mNgramsType of
Just ngramsType -> do
-- NOTE: No need to recompute chart, after ngrams are sync this
-- should be recomputed already
-- We just refresh it
-- _ <- recomputeChart session chartType ngramsType corpusId listId
liftEffect $ setChartsReload $ (+) 1
liftEffect $ GUR.bump chartsReload
Nothing -> pure unit
tabNgramType = modeTabType mode
......
......@@ -30,7 +30,7 @@ import Gargantext.Components.Tab as Tab
import Gargantext.Components.Table as Table
import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session, Sessions, sessionId, getCacheState, setCacheState)
import Gargantext.Types (CTabNgramType(..), Handed(..), ListId, NodeID, ReloadS, TabSubType(..), TabType(..))
import Gargantext.Types (CTabNgramType(..), Handed(..), ListId, NodeID, TabSubType(..), TabType(..))
import Gargantext.Utils.Reactix as R2
thisModule :: String
......
......@@ -13,11 +13,12 @@ import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Gargantext.Prelude
import Prim.Row (class Union)
import Reactix as R
import URI.Query (Query)
import Gargantext.Prelude
-------------------------------------------------------------------------
data Handed = LeftHanded | RightHanded
......@@ -28,8 +29,6 @@ instance eqHanded :: Eq Handed where
-------------------------------------------------------------------------
type ID = Int
type Name = String
type Reload = Int
type ReloadS = R.State Reload
newtype SessionId = SessionId String
type NodeID = Int
......
module Gargantext.Utils.Reload where
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple.Nested((/\))
import Effect (Effect)
import Reactix as R
import Gargantext.Prelude
type Reload = Int
type ReloadS = R.State Reload
type ReloadSRef = R.Ref
new :: R.Hooks ReloadS
new = R.useState' 0
bump :: ReloadS -> Effect Unit
bump (_ /\ setReload) = setReload (_ + 1)
value :: ReloadS -> Reload
value (val /\ _) = val
-- a ReloadS ref that can be initialized later
data ReloadWithInitialize = Initialize | Ready ReloadS
type ReloadWithInitializeRef = R.Ref ReloadWithInitialize
newI :: R.Hooks ReloadWithInitializeRef
newI = R.useRef Initialize
newIInitialized :: ReloadS -> R.Hooks ReloadWithInitializeRef
newIInitialized reload = R.useRef $ Ready reload
initializeI :: ReloadWithInitializeRef -> ReloadS -> Effect Unit
initializeI ref reloadS = case R.readRef ref of
Initialize -> R.setRef ref $ Ready reloadS
Ready _ -> pure unit
bumpI :: ReloadWithInitializeRef -> Effect Unit
bumpI ref = case R.readRef ref of
Initialize -> pure unit
Ready reload -> bump reload
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