[refactor] refactoring of logging using HerePrefix

parent 0b6ca78d
Pipeline #5560 failed with stage
in 0 seconds
......@@ -47,6 +47,7 @@ type Store =
, graphVersion :: T2.ReloadS
, handed :: T.Box Handed
, lang :: T.Box Lang.LandingLang
, pinnedTreeId :: T.Box (Map String Int)
, reloadForest :: T2.ReloadS
, reloadMainPage :: T2.ReloadS
, reloadRoot :: T2.ReloadS
......@@ -64,7 +65,6 @@ type Store =
, theme :: T.Box Themes.Theme
, tileAxisXList :: T.Box (Array (Record Tile))
, tileAxisYList :: T.Box (Array (Record Tile))
, pinnedTreeId :: T.Box (Map String Int)
)
type State =
......@@ -75,6 +75,7 @@ type State =
, graphVersion :: T2.Reload
, handed :: Handed
, lang :: Lang.LandingLang
, pinnedTreeId :: Map String Int
, reloadForest :: T2.Reload
, reloadMainPage :: T2.Reload
, reloadRoot :: T2.Reload
......@@ -92,7 +93,6 @@ type State =
, theme :: Themes.Theme
, tileAxisXList :: Array (Record Tile)
, tileAxisYList :: Array (Record Tile)
, pinnedTreeId :: Map String Int
)
options :: Record State
......@@ -104,6 +104,7 @@ options =
, graphVersion : T2.newReload
, handed : RightHanded
, lang : Lang.LL_EN
, pinnedTreeId : Map.empty
, reloadForest : T2.newReload
, reloadMainPage : T2.newReload
, reloadRoot : T2.newReload
......@@ -121,7 +122,6 @@ options =
, theme : Themes.defaultTheme
, tileAxisXList : mempty
, tileAxisYList : mempty
, pinnedTreeId : Map.empty
}
context :: R.Context (Record Store)
......
......@@ -119,7 +119,8 @@ ratingSimpleLoaderCpt = here.component "ratingSimpleLoader" cpt where
, corpusId
, session
} _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[ratingSimpleLoader]"
, loader: loadDocumentContext session
, path: { docId, corpusId }
, render: \{ nc_category } -> do
......@@ -128,12 +129,6 @@ ratingSimpleLoaderCpt = here.component "ratingSimpleLoader" cpt where
, corpusId
, category
, session } [] }
where
errorHandler err = do
here.warn2 "[pageLayout] RESTError" err
case err of
ReadJSONError err' -> here.warn2 "[pageLayout] ReadJSONError" $ show err'
_ -> pure unit
type ContextParams =
( docId :: NodeID
......
......@@ -42,7 +42,7 @@ editionBlockCpt = here.component "main" cpt where
-- | Computed
-- |
let
errorHandler = logRESTError here "[corpusLayout]"
errorHandler = logRESTError (R2.herePrefix here "[corpusLayout]")
-- | Hooks
-- |
......
This diff is collapsed.
......@@ -73,13 +73,12 @@ layoutCpt = here.component "layout" cpt where
case A.head listIds of
Nothing -> pure $ H.div {} [ H.text "No list supplied!" ]
Just listId ->
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[layout]"
, loader: \p -> getContextNgrams session p.contextId p.listId
, path: { contextId: nodeId, listId }
, render: \contextNgrams ->
layoutWithContextNgrams $ Record.merge props { contextNgrams } }
where
errorHandler = logRESTError here "[layout]"
type WithContextNgramsProps =
( contextNgrams :: Array NgramsTerm
......
......@@ -23,8 +23,7 @@ componentCpt = here.component "main" cpt where
cpt _ _ = do
-- | States
-- |
{ errors
} <- AppStore.use
{ errors } <- AppStore.use
errors' <- R2.useLive' errors
......
......@@ -348,15 +348,11 @@ pageLayoutCpt = here.component "pageLayout" cpt
cpt { container, deletions, frontends, path, session, totalRecords } _ = do
path' <- T.useLive T.unequal path
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[pageLayout]"
, loader: loadPage
, path: path'
, render: \rowsLoaded -> page { container, deletions, frontends, path, rowsLoaded, session, totalRecords } [] }
errorHandler err = do
here.warn2 "[pageLayout] RESTError" err
case err of
ReadJSONError err' -> here.warn2 "[pageLayout] ReadJSONError" $ show err'
_ -> pure unit
page :: R2.Component PageProps
page = R.createElement pageCpt
......
......@@ -61,7 +61,8 @@ folderViewCpt = here.component "folderViewCpt" cpt where
cpt { nodeId, session } _ = do
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[folderView]"
, loader: loadFolders
, path: { nodeId, session, reload: reload'}
, render: \folders -> folderViewMain { folders
......@@ -69,8 +70,6 @@ folderViewCpt = here.component "folderViewCpt" cpt where
, reload
, session
} [] }
where
errorHandler = logRESTError here "[folderView]"
type FolderViewProps =
( folders :: TreeFirstLevel
......@@ -264,19 +263,17 @@ backButtonCpt = here.component "backButton" cpt where
backButtonSmart :: R2.Component (nodeId :: Int, session :: Session)
backButtonSmart = R.createElement backButtonSmartCpt
backButtonSmartCpt :: R.Component (nodeId :: Int, session :: Session)
backButtonSmartCpt = here.component "backButtonSmart" cpt where
cpt {nodeId, session} _ = do
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[backButtonSmart]"
, loader: loadNode
, path: { nodeId, session, reload: reload' }
, render: \node -> backButtonSmartMain { node, session } []
}
where
errorHandler = logRESTError here "[folderView]"
backButtonSmartMain :: R2.Component (node :: Node, session :: Session)
backButtonSmartMain = R.createElement backButtonSmartMainCpt
......@@ -380,14 +377,13 @@ performAction = performAction' where
updateNode params { boxes: { errors, tasks }, nodeId: id, session } = do
eTask <- updateRequest params session id
handleRESTError here errors eTask $ \task -> liftEffect $ do
handleRESTError (R2.herePrefix here "[updateNode]") errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks
here.log2 "[performAction] UpdateNode task:" task
sharePublic params p@{ boxes: { errors }, session } = traverse_ f params where
f (SubTreeOut { in: inId, out }) = do
eTask <- Share.shareReq session inId $ Share.SharePublicParams { node_id: out }
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[sharePublic]") errors eTask $ \_task -> pure unit
refreshFolders p
addContact params { nodeId: id, session } =
......@@ -395,40 +391,38 @@ performAction = performAction' where
uploadFile' nodeType fileType fileFormat lang mName contents { boxes: { errors, tasks }, nodeId: id, session } selection = do
eTask <- uploadFile { contents, fileType, fileFormat, lang, id, nodeType, mName, selection, session }
handleRESTError here errors eTask $ \task -> liftEffect $ do
handleRESTError (R2.herePrefix here "[uploadFile']") errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks
here.log2 "[performAction] UploadFile, uploaded, task:" task
uploadArbitraryFile' fileFormat mName blob { boxes: { errors, tasks }, nodeId: id, session } selection = do
eTask <- uploadArbitraryFile session id { blob, fileFormat, mName } selection
handleRESTError here errors eTask $ \task -> liftEffect $ do
handleRESTError (R2.herePrefix here "[uploadArbitraryFile']") errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks
here.log2 "[performAction] UploadArbitraryFile, uploaded, task:" task
moveNode params p@{ boxes: { errors }, session } = traverse_ f params where
f (SubTreeOut { in: in', out }) = do
eTask <- moveNodeReq session in' out
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[moveNode]") errors eTask $ \_task -> pure unit
refreshFolders p
mergeNode params p@{ boxes: { errors }, session } = traverse_ f params where
f (SubTreeOut { in: in', out }) = do
eTask <- mergeNodeReq session in' out
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[mergeNode]") errors eTask $ \_task -> pure unit
refreshFolders p
linkNode nodeType params p@{ boxes: { errors }, session } = traverse_ f params where
f (SubTreeOut { in: in', out }) = do
eTask <- linkNodeReq session nodeType in' out
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[linkNode]") errors eTask $ \_task -> pure unit
refreshFolders p
renameNode name p@{ boxes: { errors }, nodeId: id, session } = do
eTask <- rename session id $ RenameValue { text: name }
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[renameNode]") errors eTask $ \_task -> pure unit
refreshFolders p
addNode' name nodeType p@{ boxes: { errors }, nodeId: id, session } = do
eTask <- addNode session id $ AddNodeValue {name, nodeType}
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[addNode']") errors eTask $ \_task -> pure unit
refreshFolders p
......@@ -9,7 +9,7 @@ import Data.Array as A
import Data.Map (empty)
import Data.Map as Map
import Data.Maybe (Maybe(..), fromMaybe)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), Position(..), TooltipPosition(..), Variant(..))
import Gargantext.Components.Forest.Tree (treeLoader)
......@@ -27,20 +27,16 @@ here = R2.here "Gargantext.Components.Forest"
-- Shared by components here with Tree
type Props =
( boxes :: Boxes
, frontends :: Frontends
( frontends :: Frontends
)
forestLayout :: R2.Leaf Props
forestLayout = R2.leaf forestLayoutCpt
forestLayoutCpt :: R.Component Props
forestLayoutCpt = here.component "forest" cpt where
cpt { boxes: boxes@{ handed
, reloadForest
, sessions
, pinnedTreeId }
, frontends } _ = do
cpt { frontends } _ = do
{ handed, reloadForest, sessions, pinnedTreeId } <- Store.use
-- TODO Fix this. I think tasks shouldn't be a Box but only a Reductor
-- tasks' <- GAT.useTasks reloadRoot reloadForest
-- R.useEffect' $ do
......@@ -58,16 +54,16 @@ forestLayoutCpt = here.component "forest" cpt where
H.div
{ className: "forest-layout bg-light" }
(A.cons (plus { boxes }) (trees handed' pinnedTreeId' sessions'))
(A.cons (plus {}) (trees handed' pinnedTreeId' sessions' reloadForest))
where
trees handed' pinnedTreeId' sessions' = (tree handed' pinnedTreeId') <$> unSessions sessions'
tree handed' pinnedTreeId' s@(Session { treeId }) =
trees handed' pinnedTreeId' sessions' reloadForest =
(tree handed' pinnedTreeId' reloadForest) <$> unSessions sessions'
tree handed' pinnedTreeId' reloadForest s@(Session { treeId }) =
H.div
{ className: "forest-layout__tree" }
[
treeLoader
{ boxes
, frontends
{ frontends
, handed: handed'
, reload: reloadForest
, root: r
......@@ -78,13 +74,15 @@ forestLayoutCpt = here.component "forest" cpt where
where
r = fromMaybe treeId (Map.lookup (show s) pinnedTreeId')
type Plus = ( boxes :: Boxes )
type Plus = ( )
plus :: R2.Leaf Plus
plus = R2.leaf plusCpt
plusCpt :: R.Component Plus
plusCpt = here.component "plus" cpt where
cpt { boxes: { backend, showLogin, showSearch, pinnedTreeId} } _ = do
cpt { } _ = do
{ backend, pinnedTreeId, showLogin, showSearch } <- Store.use
-- Hooks
{ goToRoute } <- useLinkHandler
......
......@@ -172,7 +172,8 @@ breadcrumbViewCpt = here.component "breadcrumbViewCpt" cpt where
case session' of
Nothing -> pure $ H.div {} []
Just (session') -> do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[breadcrumbView]"
, loader: loadBreadcrumbData
, path: { nodeId: nodeId
, session: session'
......@@ -184,8 +185,6 @@ breadcrumbViewCpt = here.component "breadcrumbViewCpt" cpt where
-- , reload: reload
} []
}
where
errorHandler = logRESTError here "[breadcrumbView]"
type BreadcrumbViewProps =
( items :: BreadcrumbInfo
......
......@@ -10,7 +10,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Forest.Tree.Node (blankNodeSpan, nodeSpan)
import Gargantext.Components.Forest.Tree.Node.Action.Add (AddNodeValue(..), addNode)
......@@ -50,8 +50,7 @@ here = R2.here "Gargantext.Components.Forest.Tree"
-- Shared by every component here
type Common =
( boxes :: Boxes
, frontends :: Frontends
( frontends :: Frontends
, handed :: Handed
, reload :: T2.ReloadS
)
......@@ -79,8 +78,7 @@ type ChildrenTreeProps =
--- The properties tree shares in common with performAction
type PACommon =
( boxes :: Boxes
, reloadTree :: T2.ReloadS
( reloadTree :: T2.ReloadS
, session :: Session
, tree :: FTree
)
......@@ -102,7 +100,8 @@ type ChildLoaderProps =
)
type PerformActionProps =
( isBoxVisible :: T.Box Boolean
( boxes :: Store.Boxes
, isBoxVisible :: T.Box Boolean
| PACommon
)
......@@ -145,7 +144,7 @@ treeLoaderCpt = here.component "treeLoader" cpt where
props = Record.merge common extra where
common = RecordE.pick p :: Record Common
extra = { reloadTree: p.reload, root, session, tree: tree' }
errorHandler = logRESTError here "[treeLoader]"
errorHandler = logRESTError (R2.herePrefix here "[treeLoader]")
getNodeTree :: Session -> ID -> AffRESTError FTree
getNodeTree session nodeId = get session $ GR.NodeAPI GT.Tree (Just nodeId) ""
......@@ -157,12 +156,12 @@ tree :: R2.Leaf TreeProps
tree props = R.createElement treeCpt props []
treeCpt :: R.Component TreeProps
treeCpt = here.component "tree" cpt where
cpt p@{ boxes: boxes@{ forestOpen }
, frontends
cpt p@{ frontends
, reload
, root
, session
, tree: NTree (LNode { id, name, nodeType }) children } _ = do
boxes@{ forestOpen } <- Store.use
isBoxVisible <- T.useBox false
folderOpen <- useOpenNodesMemberBox nodeId forestOpen
......@@ -183,18 +182,17 @@ treeCpt = here.component "tree" cpt where
{ className: "maintree__node" }
[
nodeSpan
{ boxes
, dispatch: dispatch' isBoxVisible
{ dispatch: dispatch' boxes isBoxVisible
, folderOpen
, frontends
, id
, isBoxVisible
, isLeaf
, name
, nodeType
, reload
, root
, session
, isBoxVisible
}
<>
R2.when (folderOpen')
......@@ -214,9 +212,9 @@ treeCpt = here.component "tree" cpt where
nodeId = mkNodeId session id
children' = A.sortWith fTreeID pubChildren
pubChildren = if isPublic nodeType then map (map pub) children else children
dispatch' isBoxVisible a = performAction a (Record.merge common' extra) where
dispatch' boxes isBoxVisible a = performAction a (Record.merge common' extra) where
common' = RecordE.pick p :: Record PACommon
extra = { isBoxVisible }
extra = { boxes, isBoxVisible }
pub (LNode n@{ nodeType: t }) = LNode (n { nodeType = publicize t })
......@@ -258,11 +256,11 @@ childLoader :: R2.Component ChildLoaderProps
childLoader = R.createElement childLoaderCpt
childLoaderCpt :: R.Component ChildLoaderProps
childLoaderCpt = here.component "childLoader" cpt where
cpt p@{ boxes: { reloadRoot }
, reloadTree
cpt p@{ reloadTree
, render
, root } _ = do
-- States
{ reloadRoot } <- Store.use
reload <- T.useBox T2.newReload
state /\ stateBox <- R2.useBox' Nothing
let reloads = [ reload, reloadRoot, reloadTree ]
......@@ -289,7 +287,7 @@ childLoaderCpt = here.component "childLoader" cpt where
}
where
errorHandler = logRESTError here "[childLoader]"
errorHandler = logRESTError (R2.herePrefix here "[childLoader]")
fetch _ = getNodeTreeFirstLevel p.session p.id
paint reload tree' = render (Record.merge base extra) where
base = nodeProps { reload = reload }
......@@ -311,78 +309,74 @@ deleteNode' nt p@{ boxes: { forestOpen }, session, tree: (NTree (LNode {id, pare
doSearch task { boxes: { tasks }, tree: NTree (LNode {id}) _ } = liftEffect $ do
GAT.insert id task tasks
here.log2 "[doSearch] DoSearch task:" task
updateNode params p@{ boxes: { errors, tasks }, session, tree: (NTree (LNode {id}) _) } = do
eTask <- updateRequest params session id
handleRESTError here errors eTask $ \task -> liftEffect $ do
handleRESTError (R2.herePrefix here "[updateNode]") errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks
here.log2 "[updateNode] UpdateNode task:" task
closeBox p
renameNode name p@{ boxes: { errors }, session, tree: (NTree (LNode {id}) _) } = do
eTask <- rename session id $ RenameValue { text: name }
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[renameNode]") errors eTask $ \_task -> pure unit
refreshTree p
sharePublic params p@{ boxes: { errors, forestOpen }, session } = traverse_ f params where
f (SubTreeOut { in: inId, out }) = do
eTask <- Share.shareReq session inId $ Share.SharePublicParams { node_id: out }
handleRESTError here errors eTask $ \_task -> do
handleRESTError (R2.herePrefix here "[sharePublic]") errors eTask $ \_task -> do
liftEffect $ T.modify_ (openNodesInsert (mkNodeId p.session out)) forestOpen
refreshTree p
addContact params { boxes: { errors }, session, tree: (NTree (LNode {id}) _) } = do
eTask <- Contact.contactReq session id params
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[addContact]") errors eTask $ \_task -> pure unit
addNode' name nodeType p@{ boxes: { errors, forestOpen }, session, tree: (NTree (LNode { id }) _) } = do
eId <- addNode session id $ AddNodeValue { name, nodeType }
handleRESTError here errors eId $ \_id -> liftEffect $ do
handleRESTError (R2.herePrefix here "[addNode']") errors eId $ \_id -> liftEffect $ do
liftEffect $ T.modify_ (openNodesInsert (mkNodeId session id)) forestOpen
refreshTree p
uploadFile' nodeType fileType fileFormat lang mName contents p@{ boxes: { errors, tasks }, session, tree: (NTree (LNode { id }) _) } selection = do
eTask <- uploadFile { contents, fileFormat, fileType, id, lang, mName, nodeType, selection, session }
handleRESTError here errors eTask $ \task -> liftEffect $ do
handleRESTError (R2.herePrefix here "[uploadFile']") errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks
here.log2 "[uploadFile'] UploadFile, uploaded, task:" task
closeBox p
uploadArbitraryFile' fileFormat mName blob p@{ boxes: { errors, tasks }, session, tree: (NTree (LNode { id }) _) } selection = do
eTask <- uploadArbitraryFile session id { blob, fileFormat, mName } selection
handleRESTError here errors eTask $ \task -> liftEffect $ do
handleRESTError (R2.herePrefix here "[uploadArbitraryFile']") errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks
here.log2 "[uploadArbitraryFile'] UploadArbitraryFile, uploaded, task:" task
uploadFrameCalc' lang p@{ boxes: { errors, tasks }, session, tree: (NTree (LNode { id }) _) } selection = do
eTask <- uploadFrameCalc session id lang selection
handleRESTError here errors eTask $ \task -> liftEffect $ do
handleRESTError (R2.herePrefix here "[uploadFrameCalc']") errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks
here.log2 "[performAction] UploadFrameCalc, uploaded, task:" task
moveNode params p@{ boxes: { errors, forestOpen }, session } = traverse_ f params where
f (SubTreeOut { in: in', out }) = do
eTask <- moveNodeReq session in' out
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[moveNode]") errors eTask $ \_task -> pure unit
liftEffect $ T.modify_ (openNodesInsert (mkNodeId session out)) forestOpen
refreshTree p
mergeNode params p@{ boxes: { errors }, session } = traverse_ f params where
f (SubTreeOut { in: in', out }) = do
eTask <- mergeNodeReq session in' out
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[mergeNode]") errors eTask $ \_task -> pure unit
refreshTree p
linkNode nodeType params p@{ boxes: { errors }, session } = traverse_ f params where
f (SubTreeOut { in: in', out }) = do
eTask <- linkNodeReq session nodeType in' out
handleRESTError here errors eTask $ \_task -> pure unit
handleRESTError (R2.herePrefix here "[linkNode]") errors eTask $ \_task -> pure unit
refreshTree p
documentsFromWriteNodes params p@{ boxes: { errors, tasks }, session, tree: NTree (LNode { id }) _ } = do
eTask <- documentsFromWriteNodesReq session params
handleRESTError here errors eTask $ \task -> liftEffect $ do
handleRESTError (R2.herePrefix here "[documentsFromWriteNodes]") errors eTask $ \task -> liftEffect $ do
GAT.insert id task tasks
pure unit
refreshTree p
......
......@@ -29,10 +29,11 @@ import Gargantext.Components.Forest.Tree.Node.Settings (SettingsBox(..), setting
import Gargantext.Components.Forest.Tree.Node.Tools.Sync (nodeActionsGraph, nodeActionsNodeList)
import Gargantext.Components.GraphExplorer.API as GraphAPI
import Gargantext.Components.Lang (Lang(EN))
import Gargantext.Components.Nodes.Corpus.Types (CorpusData)
import Gargantext.Config.REST (logRESTError)
import Gargantext.Context.Progress (asyncContext, asyncProgress)
import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoaderEffect)
import Gargantext.Hooks.Loader (useLoader, useLoaderEffect)
import Gargantext.Hooks.Version (Version, useVersion)
import Gargantext.Routes as Routes
import Gargantext.Sessions (Session, sessionId)
......@@ -56,18 +57,17 @@ here = R2.here "Gargantext.Components.Forest.Tree.Node"
-- Main Node
type NodeSpanProps =
( boxes :: Boxes
, dispatch :: Action -> Aff Unit
( dispatch :: Action -> Aff Unit
, folderOpen :: T.Box Boolean
, frontends :: Frontends
, id :: ID
, isBoxVisible :: T.Box Boolean
, isLeaf :: IsLeaf
, name :: Name
, nodeType :: GT.NodeType
, reload :: T2.ReloadS
, root :: ID
, session :: Session
, isBoxVisible :: T.Box Boolean
)
type IsLeaf = Boolean
......@@ -78,8 +78,7 @@ nodeSpan = R2.leaf nodeSpanCpt
nodeSpanCpt :: R.Component NodeSpanProps
nodeSpanCpt = here.component "nodeSpan" cpt
where
cpt props@{ boxes
, dispatch
cpt props@{ dispatch
, folderOpen
, frontends
, id
......@@ -90,6 +89,7 @@ nodeSpanCpt = here.component "nodeSpan" cpt
, isBoxVisible
} _ = do
-- States
boxes <- AppStore.use
route' <- T.useLive T.unequal boxes.route
-- only 1 popup at a time is allowed to be opened
......@@ -331,7 +331,6 @@ nodeSpanCpt = here.component "nodeSpan" cpt
asyncProgress
{ asyncTask: task
, errors: boxes.errors
, nodeId: id
, onFinish: onTaskFinish id task
, session
......@@ -606,58 +605,65 @@ graphNodeActions :: R2.Leaf NodeActionsCommon
graphNodeActions = R2.leaf graphNodeActionsCpt
graphNodeActionsCpt :: R.Component NodeActionsCommon
graphNodeActionsCpt = here.component "graphNodeActions" cpt where
cpt { id, session, refresh } _ = do
-- States
state /\ stateBox <- R2.useBox' Nothing
cpt { id, refresh, session } _ = do
-- Hooks
useLoaderEffect
{ errorHandler
useLoader
{ errorHandler: Nothing
, herePrefix: R2.herePrefix here "[graphNodeActions]"
, loader: graphVersions session
, path: id
, state: stateBox
, render: \gv -> graphNodeActionsLoaded { gv, id, refresh, session }
}
where
graphVersions session graphId = GraphAPI.graphVersions { graphId, session }
-- Render
pure $ R2.fromMaybe state \gv ->
nodeActionsGraph
{ graphVersions: gv, session, id, refresh }
[]
type NodeActionsGraphLoaded =
( gv :: Record GraphAPI.GraphVersions
| NodeActionsCommon )
graphVersions session graphId = GraphAPI.graphVersions { graphId, session }
errorHandler = logRESTError here "[graphNodeActions]"
graphNodeActionsLoaded :: R2.Leaf NodeActionsGraphLoaded
graphNodeActionsLoaded = R2.leaf graphNodeActionsLoadedCpt
graphNodeActionsLoadedCpt :: R.Component NodeActionsGraphLoaded
graphNodeActionsLoadedCpt = here.component "graphNodeActionsLoaded" cpt where
cpt { gv, id, refresh, session } _ = do
-- Render
pure $ nodeActionsGraph { graphVersions: gv
, id
, refresh
, session } []
listNodeActions :: R2.Leaf NodeActionsCommon
listNodeActions = R2.leaf listNodeActionsCpt
listNodeActionsCpt :: R.Component NodeActionsCommon
listNodeActionsCpt = here.component "listNodeActions" cpt where
cpt { id, session, refresh } _ = do
-- States
state /\ stateBox <- R2.useBox' Nothing
cpt { id, refresh, session } _ = do
-- Hooks
useLoaderEffect
{ errorHandler
useLoader
{ errorHandler: Nothing
, herePrefix: R2.herePrefix here "[listNodeActions]"
, loader: loadCorpusWithChild
, path: { nodeId: id, session }
, state: stateBox
, render: \corpusData -> listNodeActionsLoaded { corpusData, id, refresh, session }
}
-- Render
pure $ R2.fromMaybe state \{ corpusId } ->
nodeActionsNodeList
{ listId: id
, nodeId: corpusId
, session
, refresh: refresh
, nodeType: GT.TabNgramType GT.CTabTerms
}
type NodeActionsListLoaded =
( corpusData :: CorpusData
| NodeActionsCommon )
where
errorHandler = logRESTError here "[listNodeActions]"
listNodeActionsLoaded :: R2.Leaf NodeActionsListLoaded
listNodeActionsLoaded = R2.leaf listNodeActionsLoadedCpt
listNodeActionsLoadedCpt :: R.Component NodeActionsListLoaded
listNodeActionsLoadedCpt = here.component "listNodeActionsLoaded" cpt where
cpt { corpusData: { corpusId }, id, refresh, session } _ = do
-- Render
pure $ nodeActionsNodeList { listId: id
, nodeId: corpusId
, nodeType: GT.TabNgramType GT.CTabTerms
, refresh
, session
}
-----------------------------------------------
......
......@@ -37,12 +37,11 @@ linkNode = R.createElement linkNodeCpt
linkNodeCpt :: R.Component SubTreeParamsIn
linkNodeCpt = here.component "linkNode" cpt
where
cpt { boxes, dispatch, id, nodeType, session, subTreeParams } _ = do
cpt { dispatch, id, nodeType, session, subTreeParams } _ = do
action <- T.useBox (LinkNode { nodeType: Nothing, params: Nothing})
pure $
linkNode' { action
, boxes
, dispatch
, id
, nodeType
......@@ -61,7 +60,7 @@ linkNode' = R.createElement linkNodeCpt'
linkNodeCpt' :: R.Component Props
linkNodeCpt' = here.component "__clone__" cpt
where
cpt { boxes, dispatch, id, nodeType, session, subTreeParams, action } _ = do
cpt { dispatch, id, nodeType, session, subTreeParams, action } _ = do
action' <- T.useLive T.unequal action
......@@ -78,7 +77,6 @@ linkNodeCpt' = here.component "__clone__" cpt
pure $
Tools.panel { mError: Nothing }
[ subTreeView { action
, boxes
, dispatch
, id
, nodeType
......
......@@ -7,11 +7,10 @@ import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Effect.Aff (runAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Forest.Tree.Node.Tools as Tools
import Gargantext.Components.GraphQL.Endpoints (deleteTeamMembership, getTeam)
import Gargantext.Components.GraphQL.Team (Team, TeamMember)
import Gargantext.Config.REST (AffRESTError, logRESTError, FrontendError(EC_403__user_not_authorized))
import Gargantext.Config.REST (AffRESTError, FrontendError(EC_403__user_not_authorized))
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session)
import Gargantext.Types (ID, FrontendError(FRESTError), NodeType)
......@@ -24,8 +23,7 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.ManageTeam"
type ActionManageTeam = (
boxes :: Boxes
, id :: ID
id :: ID
, nodeType :: NodeType
, session :: Session
)
......@@ -34,8 +32,9 @@ actionManageTeam :: R2.Component ActionManageTeam
actionManageTeam = R.createElement actionManageTeamCpt
actionManageTeamCpt :: R.Component ActionManageTeam
actionManageTeamCpt = here.component "actionManageTeam" cpt where
cpt { boxes: { errors }, id, session } _ = do
useLoader { errorHandler: errorHandler errors
cpt { id, session } _ = do
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[actionManageTeam]"
, loader: loadTeam
, path: { nodeId: id, session }
, render: \team -> teamLayoutWrapper { team
......@@ -43,12 +42,6 @@ actionManageTeamCpt = here.component "actionManageTeam" cpt where
, session
} []
}
where
errorHandler errors error = do
logRESTError here "teamLayout" error
T.modify_ (cons $ FRESTError { error }) errors
-- T.write_ (Just $ show error) errorS
type TeamProps =
( nodeId :: ID
......
......@@ -28,7 +28,7 @@ mergeNode = R.createElement mergeNodeCpt
mergeNodeCpt :: R.Component SubTreeParamsIn
mergeNodeCpt = here.component "mergeNode" cpt
where
cpt { boxes, dispatch, id, nodeType, session, subTreeParams } _ = do
cpt { dispatch, id, nodeType, session, subTreeParams } _ = do
action <- T.useBox (MergeNode { params: Nothing })
action' <- T.useLive T.unequal action
......@@ -44,7 +44,6 @@ mergeNodeCpt = here.component "mergeNode" cpt
pure $ Tools.panel { mError: Nothing }
[ subTreeView { action
, boxes
, dispatch
, id
, nodeType
......
......@@ -30,19 +30,18 @@ moveNode = R.createElement moveNodeCpt
moveNodeCpt :: R.Component SubTreeParamsIn
moveNodeCpt = here.component "moveNode" cpt
where
cpt { boxes, dispatch, id, nodeType, session, subTreeParams } _ = do
cpt { dispatch, id, nodeType, session, subTreeParams } _ = do
action :: T.Box Action <- T.useBox (MoveNode {params: Nothing})
pure $
moveNode' { action
, boxes
, dispatch
, id
, nodeType
, session
, subTreeParams
} []
, dispatch
, id
, nodeType
, session
, subTreeParams
} []
type Props =
( action :: T.Box Action
......@@ -54,7 +53,7 @@ moveNode' :: R2.Component Props
moveNode' = R.createElement moveNodeCpt'
moveNodeCpt' :: R.Component Props
moveNodeCpt' = here.component "__clone__" cpt where
cpt { boxes, dispatch, id, nodeType, session, subTreeParams, action } _ = do
cpt { dispatch, id, nodeType, session, subTreeParams, action } _ = do
action' <- T.useLive T.unequal action
......@@ -69,7 +68,6 @@ moveNodeCpt' = here.component "__clone__" cpt where
Tools.panel { mError: Nothing }
[ subTreeView { action
, boxes
, dispatch
, id
, nodeType
......
......@@ -3,10 +3,11 @@ module Gargantext.Components.Forest.Tree.Node.Action.Search where
import Gargantext.Prelude
import Data.Array as A
import Data.Maybe (Maybe)
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Aff (Aff, launchAff)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchBar (searchBar)
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField (defaultSearch)
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
......@@ -28,8 +29,7 @@ here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Search"
type Props =
( boxes :: Boxes
, dispatch :: Action -> Aff Unit
( dispatch :: Action -> Aff Unit
, id :: Maybe ID
, session :: Session )
......@@ -38,18 +38,14 @@ actionSearch :: R2.Component Props
actionSearch = R.createElement actionSearchCpt
actionSearchCpt :: R.Component Props
actionSearchCpt = here.component "actionSearch" cpt where
cpt props@({ boxes: { errors }, session }) _ = do
useLoader { errorHandler: errorHandler errors
cpt props@({ session }) _ = do
{ errors } <- Store.use
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[actionSearch]"
, loader: loadLanguages
, path: { session }
, render: \langs ->
actionSearchWithLangs (Record.merge props { langs }) [] }
where
errorHandler errors error = do
T.modify_ (A.cons $ GT.FRESTError { error }) errors
case error of
ReadJSONError err' -> here.warn2 "[actionSearch] ReadJSONError" $ show err'
_ -> here.warn2 "[actionSearch] RESTError" error
type PropsWithLangs =
( langs :: Array Lang
......@@ -61,7 +57,8 @@ actionSearchWithLangs = R.createElement actionSearchWithLangsCpt
actionSearchWithLangsCpt :: R.Component PropsWithLangs
actionSearchWithLangsCpt = here.component "actionSearchWithLangs" cpt
where
cpt { boxes: { errors }, dispatch, id, langs, session } _ = do
cpt { dispatch, id, langs, session } _ = do
{ errors } <- Store.use
search <- T.useBox $ defaultSearch { node_id = id }
pure $ R.fragment
[ H.p { className: "action-search mx-2" }
......
......@@ -24,7 +24,6 @@ import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Lang (Lang(..))
import Gargantext.Components.ListSelection as ListSelection
import Gargantext.Components.ListSelection.Types as ListSelection
import Gargantext.Config.REST (logRESTError)
import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session(..))
......@@ -131,12 +130,11 @@ componentIMT = R.createElement componentIMTCpt
componentIMTCpt :: R.Component ComponentIMTProps
componentIMTCpt = here.component "componentIMT" cpt where
cpt { search, session } _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[componentIMT]"
, loader: \_ -> getIMTSchools session
, path: unit
, render: \schools -> componentWithIMTOrgs { schools, search } [] }
where
errorHandler = logRESTError here "[componentIMT]"
type ComponentWithIMTOrgsProps =
( schools :: Array GQLIMT.School
......@@ -396,13 +394,12 @@ pubmedInput = R.createElement pubmedInputCpt
pubmedInputCpt :: R.Component PubmedInputProps
pubmedInputCpt = here.component "pubmedInput" cpt where
cpt { search, session: session@(Session { treeId }) } _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[pubmedInput]"
, loader: \_ -> getUser session treeId
, path: unit
, render: \user -> pubmedInputLoaded { pubmedAPIKey: user.u_hyperdata.pubmed_api_key
, search } [] }
where
errorHandler = logRESTError here "[pubmedInput]"
type PubmedInputLoadedProps = (
......@@ -449,14 +446,13 @@ epoInput = R.createElement epoInputCpt
epoInputCpt :: R.Component EPOInputProps
epoInputCpt = here.component "epoInput" cpt where
cpt { search, session: session@(Session { treeId }) } _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[epoInput]"
, loader: \_ -> getUser session treeId
, path: unit
, render: \user -> epoInputLoaded { epoAPIUser: user.u_hyperdata.epo_api_user
, epoAPIToken: user.u_hyperdata.epo_api_token
, search } [] }
where
errorHandler = logRESTError here "[epoInput]"
type EPOInputLoadedProps = (
......@@ -713,9 +709,10 @@ triggerSearch { onSearch, errors, session, selection, search } =
Just id -> do
-- liftEffect $ here.log2 "[triggerSearch] searchQuery" $ searchQuery selection search
eTask <- performSearch session id $ searchQuery selection search
handleRESTError here errors eTask $ \task -> liftEffect $ do
-- here.log2 "[triggerSearch] task" task
onSearch task
handleRESTError (R2.herePrefix here "[triggerSearch]") errors eTask $
\task -> liftEffect $ do
-- here.log2 "[triggerSearch] task" task
onSearch task
--liftEffect $ do
-- log2 "Return:" r
......
......@@ -18,7 +18,7 @@ import Gargantext.Components.Forest.Tree.Node.Action.Types as Action
import Gargantext.Components.Forest.Tree.Node.Tools as Tools
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTreeParamsIn)
import Gargantext.Components.InputWithAutocomplete (inputWithAutocomplete)
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as GR
import Gargantext.Sessions (Session, get, post)
......@@ -68,14 +68,12 @@ shareNodeCpt :: R.Component ShareNode
shareNodeCpt = here.component "shareNode" cpt
where
cpt { id, session } _ = do
useLoader {
loader: getCompletionsReq
, path: { session }
, render: \completions -> shareNodeInner { completions, id, session } []
, errorHandler
}
where
errorHandler = logRESTError here "[shareNode]"
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[shareNode]"
, loader: getCompletionsReq
, path: { session }
, render: \completions -> shareNodeInner { completions, id, session } []
}
type ShareNodeInner =
( completions :: Array String
......@@ -129,7 +127,7 @@ publishNode = R.createElement publishNodeCpt
publishNodeCpt :: R.Component SubTreeParamsIn
publishNodeCpt = here.component "publishNode" cpt
where
cpt { boxes, dispatch, id, nodeType, session, subTreeParams } _ = do
cpt { dispatch, id, nodeType, session, subTreeParams } _ = do
action <- T.useBox (Action.SharePublic { params: Nothing })
action' <- T.useLive T.unequal action
......@@ -142,7 +140,6 @@ publishNodeCpt = here.component "publishNode" cpt
pure $ Tools.panel { mError: Nothing }
[ subTreeView { action
, boxes
, dispatch
, id
, nodeType
......
......@@ -108,15 +108,12 @@ uploadFileView = R2.leaf uploadFileViewCpt
uploadFileViewCpt :: R.Component Props
uploadFileViewCpt = here.component "uploadFileView" cpt where
cpt props@({ session }) _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[uploadFileView]"
, loader: loadLanguages
, path: { session }
, render: \langs ->
uploadFileViewWithLangs (Record.merge props { langs }) }
where
errorHandler err = case err of
ReadJSONError err' -> here.warn2 "[uploadFileView] ReadJSONError" $ show err'
_ -> here.warn2 "[uploadFileView] RESTError" err
type PropsWithLangs =
( langs :: Array Lang
......@@ -736,15 +733,12 @@ uploadFrameCalcView = R.createElement uploadFrameCalcViewCpt
uploadFrameCalcViewCpt :: R.Component Props
uploadFrameCalcViewCpt = here.component "uploadFrameCalcView" cpt where
cpt props@({ session }) _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[uploadFrameCalcView]"
, loader: loadLanguages
, path: { session }
, render: \langs ->
uploadFileViewWithLangs (Record.merge props { langs }) }
where
errorHandler err = case err of
ReadJSONError err' -> here.warn2 "[uploadFileView] ReadJSONError" $ show err'
_ -> here.warn2 "[uploadFileView] RESTError" err
uploadFrameCalcViewWithLangs :: R2.Component PropsWithLangs
uploadFrameCalcViewWithLangs = R.createElement uploadFrameCalcViewWithLangsCpt
......
......@@ -7,7 +7,7 @@ import Data.Either (Either)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Utils (loadLanguages)
......@@ -32,8 +32,7 @@ here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.WriteNodesDocument
-- | Action : WriteNodesDocuments
type ActionWriteNodesDocuments =
( boxes :: Boxes
, dispatch :: Action -> Aff Unit
( dispatch :: Action -> Aff Unit
, id :: GT.ID
, session :: Session )
......@@ -41,18 +40,14 @@ actionWriteNodesDocuments :: R2.Component ActionWriteNodesDocuments
actionWriteNodesDocuments = R.createElement actionWriteNodesDocumentsCpt
actionWriteNodesDocumentsCpt :: R.Component ActionWriteNodesDocuments
actionWriteNodesDocumentsCpt = here.component "actionWriteNodesDocuments" cpt where
cpt props@({ boxes: { errors }, session }) _ = do
useLoader { errorHandler: errorHandler errors
cpt props@({ session }) _ = do
{ errors } <- Store.use
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[actionWriteNodesDocuments]"
, loader: loadLanguages
, path: { session }
, render: \langs ->
actionWriteNodesDocumentsWithLangs (Record.merge props { langs }) [] }
where
errorHandler errors error = do
T.modify_ (A.cons $ GT.FRESTError { error }) errors
case error of
ReadJSONError err' -> here.warn2 "[actionWriteNodesDocuments] ReadJSONError" $ show err'
_ -> here.warn2 "[actionWriteNodesDocuments] RESTError" error
type ActionWriteNodesDocumentsWithLangs =
( langs :: Array Lang
......
......@@ -344,27 +344,27 @@ panelActionCpt = here.component "panelAction" cpt
pure $ actionDoc { nodeType } []
cpt { action: Download, id, nodeType, session} _ =
pure $ actionDownload { id, nodeType, session } []
cpt { action: Link {subTreeParams}, boxes, dispatch, id, nodeType, session } _ =
pure $ linkNode { boxes, dispatch, id, nodeType, session, subTreeParams } []
cpt { action: ManageTeam, boxes, nodeType, id, session} _ =
pure $ actionManageTeam { boxes, id, nodeType, session } []
cpt { action: Merge {subTreeParams}, boxes, dispatch, id, nodeType, session } _ =
pure $ mergeNode { boxes, dispatch, id, nodeType, session, subTreeParams } []
cpt { action: Link {subTreeParams}, dispatch, id, nodeType, session } _ =
pure $ linkNode { dispatch, id, nodeType, session, subTreeParams } []
cpt { action: ManageTeam, nodeType, id, session} _ =
pure $ actionManageTeam { id, nodeType, session } []
cpt { action: Merge {subTreeParams}, dispatch, id, nodeType, session } _ =
pure $ mergeNode { dispatch, id, nodeType, session, subTreeParams } []
cpt { action: Move {subTreeParams}, boxes, dispatch, id, nodeType, session } _ =
pure $ moveNode { boxes, dispatch, id, nodeType, session, subTreeParams } []
cpt { action : Publish {subTreeParams}, boxes, dispatch, id, nodeType, session } _ =
pure $ Share.publishNode { boxes, dispatch, id, nodeType, session, subTreeParams } []
pure $ moveNode { dispatch, id, nodeType, session, subTreeParams } []
cpt { action : Publish {subTreeParams}, dispatch, id, nodeType, session } _ =
pure $ Share.publishNode { dispatch, id, nodeType, session, subTreeParams } []
cpt { action: Reconstruct , dispatch, nodeType } _ =
pure $ update { dispatch, nodeType } []
cpt { action: Refresh , dispatch, nodeType } _ =
pure $ update { dispatch, nodeType } []
cpt { action: ReloadWithSettings , dispatch, nodeType } _ =
pure $ update { dispatch, nodeType } []
cpt { action: SearchBox, boxes, dispatch, id, session } _ =
pure $ actionSearch { boxes, dispatch, id: Just id, session } []
cpt { action: SearchBox, dispatch, id, session } _ =
pure $ actionSearch { dispatch, id: Just id, session } []
cpt { action : Share, id, session } _ = pure $ Share.shareNode { id, session } []
cpt { action: Upload, dispatch, id, nodeType, session} _ =
pure $ actionUpload { dispatch, id, nodeType, session } []
cpt { action: WriteNodesDocuments, boxes, dispatch, id, session } _ =
pure $ actionWriteNodesDocuments { boxes, dispatch, id, session } []
cpt { action: WriteNodesDocuments, dispatch, id, session } _ =
pure $ actionWriteNodesDocuments { dispatch, id, session } []
cpt _ _ = pure $ H.div {} []
......@@ -8,6 +8,7 @@ import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Effect.Timer (clearInterval, setInterval)
import Gargantext.Components.App.Store as AppStore
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Config.Utils (handleErrorInAsyncProgress, handleRESTError)
import Gargantext.Routes (SessionRoute(..))
......@@ -29,7 +30,6 @@ data BarType = Bar | Pie
type Props = (
asyncTask :: GT.AsyncTaskWithType
, barType :: BarType
, errors :: T.Box (Array FrontendError)
, nodeId :: GT.ID
, onFinish :: Unit -> Effect Unit
, session :: Session
......@@ -43,9 +43,10 @@ asyncProgressBarCpt = here.component "asyncProgressBar" cpt
where
cpt props@{ asyncTask: (GT.AsyncTaskWithType {task: GT.AsyncTask {id}})
, barType
, errors
, onFinish
} _ = do
{ errors } <- AppStore.use
progress <- T.useBox 0.0
intervalIdRef <- R.useRef Nothing
......@@ -54,17 +55,18 @@ asyncProgressBarCpt = here.component "asyncProgressBar" cpt
launchAff_ $ do
let rdata = (RX.pick props :: Record QueryProgressData)
eAsyncProgress <- queryProgress rdata
handleRESTError here errors eAsyncProgress $ \asyncProgress -> liftEffect $ do
let GT.AsyncProgress { status } = asyncProgress
T.write_ (min 100.0 $ GT.progressPercent asyncProgress) progress
if (status == GT.IsFinished) || (status == GT.IsKilled) || (status == GT.IsFailure) then do
_ <- case R.readRef intervalIdRef of
Nothing -> pure unit
Just iid -> clearInterval iid
handleErrorInAsyncProgress errors asyncProgress
onFinish unit
else
pure unit
handleRESTError (R2.herePrefix here "[asyncProgressBar]") errors eAsyncProgress $
\asyncProgress -> liftEffect $ do
let GT.AsyncProgress { status } = asyncProgress
T.write_ (min 100.0 $ GT.progressPercent asyncProgress) progress
if (status == GT.IsFinished) || (status == GT.IsKilled) || (status == GT.IsFailure) then do
_ <- case R.readRef intervalIdRef of
Nothing -> pure unit
Just iid -> clearInterval iid
handleErrorInAsyncProgress errors asyncProgress
onFinish unit
else
pure unit
R.setRef intervalIdRef $ Just intervalId
......
......@@ -7,12 +7,12 @@ import Data.Array as A
import Data.Foldable (intercalate)
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Forest.Tree.Node.Action (Props, subTreeOut, setTreeOut)
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action)
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeParams(..), SubTreeOut(..))
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as GR
import Gargantext.Sessions (Session(..), get)
......@@ -28,8 +28,7 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Tools.SubTree"
type SubTreeParamsIn =
( boxes :: Boxes
, subTreeParams :: SubTreeParams
( subTreeParams :: SubTreeParams
| Props
)
......@@ -45,7 +44,6 @@ subTreeViewCpt :: R.Component SubTreeParamsProps
subTreeViewCpt = here.component "subTreeView" cpt
where
cpt { action
, boxes
, dispatch
, id
, nodeType
......@@ -57,12 +55,12 @@ subTreeViewCpt = here.component "subTreeView" cpt
-- (valAction /\ setAction) = action
-- _ <- pure $ setAction (const $ setTreeOut valAction Nothing)
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[subTreeView]"
, loader: loadSubTree showtypes
, path: session
, render: \tree ->
subTreeViewLoaded { action
, boxes
, dispatch
, id
, nodeType
......@@ -70,8 +68,6 @@ subTreeViewCpt = here.component "subTreeView" cpt
, subTreeParams
, tree
} [] }
where
errorHandler = logRESTError here "[subTreeView]"
loadSubTree :: Array GT.NodeType -> Session -> AffRESTError FTree
loadSubTree nodetypes session = getSubTree session treeId nodetypes
......
......@@ -3,7 +3,7 @@ module Gargantext.Components.ForgotPassword where
import Gargantext.Prelude
import Data.Maybe (Maybe(..))
import Gargantext.Config.REST (AffRESTError, logRESTError, get)
import Gargantext.Config.REST (AffRESTError, get)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Utils.Reactix as R2
import Reactix as R
......@@ -16,11 +16,11 @@ type ForgotPasswordProps = ( server :: String, uuid :: String )
forgotPasswordLayout :: R2.Component ForgotPasswordProps
forgotPasswordLayout = R.createElement forgotPasswordLayoutCpt
forgotPasswordLayoutCpt :: R.Component ForgotPasswordProps
forgotPasswordLayoutCpt = here.component "forgotPasswordLayout" cpt where
cpt { server, uuid } _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[forgotPasswordLayout]"
, loader: loadPassword
, path: { server, uuid }
, render: \{ password } ->
......@@ -28,8 +28,6 @@ forgotPasswordLayoutCpt = here.component "forgotPasswordLayout" cpt where
H.div {className: "row"} [ H.div {className: "mx-auto"} [ H.img { src: "images/logo.png" } ] ]
, H.div {className: "row"} [ H.div {className: "col"} [ H.text ("Your new password is: " <> password) ] ]
]}
where
errorHandler = logRESTError here "[forgotPasswordLayout]"
------------------------------------
......
......@@ -64,7 +64,7 @@ docFocusCpt = here.component "main" cpt where
-- | Hooks
-- |
useLoaderEffect
{ errorHandler: logRESTError here "[docFocus]"
{ errorHandler: logRESTError (R2.herePrefix here "[docFocus]")
, loader: loadData
, path
, state
......
......@@ -62,8 +62,7 @@ layoutCpt = here.component "layout" cpt where
} _ = do
-- | States
-- |
{ reloadForest
} <- AppStore.use
{ reloadForest } <- AppStore.use
{ showSidebar
, showDoc
......
......@@ -63,7 +63,7 @@ drawGraphCpt = here.component "drawGraph" cpt where
, forceAtlas2Settings: fa2Settings
} _ = do
boxes <- AppStore.use
{ theme } <- AppStore.use
{ edgeConfluence
, edgeWeight
......@@ -116,12 +116,12 @@ drawGraphCpt = here.component "drawGraph" cpt where
case Sigmax.readSigma rSigma of
Nothing -> do
theme <- T.read boxes.theme
theme' <- T.read theme
eSigma <- case R.readNullableRef elRef of
Nothing -> do
_ <- ECC.error "elRef is empty"
pure $ Left "elRef is empty"
Just el -> Sigma.sigma el { settings: sigmaSettings theme }
Just el -> Sigma.sigma el { settings: sigmaSettings theme' }
case eSigma of
Left err -> here.warn2 "[drawGraph] error creating sigma" err
Right sig -> do
......
......@@ -637,7 +637,6 @@ type UpdateTermButtonProps =
updateTermButton :: R2.Component UpdateTermButtonProps
updateTermButton = R2.component updateTermButtonCpt
updateTermButtonCpt :: R.Component UpdateTermButtonProps
updateTermButtonCpt = here.component "updateTermButton" cpt where
cpt { variant
......
......@@ -119,7 +119,8 @@ listTreeChildren = R.createElement listTreeChildrenCpt
listTreeChildrenCpt :: R.Component ListTreeChildrenProps
listTreeChildrenCpt = here.component "listTreeChildren" cpt where
cpt { render, root, selection, session } _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[listTreeChildren]"
, loader: loadTreeChildren
, path: { root, session }
, render: \loaded ->
......@@ -128,10 +129,6 @@ listTreeChildrenCpt = here.component "listTreeChildren" cpt where
, root
, selection
, session } [] }
where
errorHandler err = case err of
ReadJSONError err' -> here.warn2 "[listTreeChildren] ReadJSONError" $ show err'
_ -> here.warn2 "[listTreeChildren] RESTError" err
type ListTreeChildrenLoadedProps =
( loaded :: Array NodeSimple
......
......@@ -33,7 +33,7 @@ import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), Sizing(..), Variant(..))
import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI)
......@@ -407,7 +407,6 @@ tableContainerCpt { addCallback
type CommonProps =
( afterSync :: Unit -> Aff Unit
, boxes :: Boxes
, tabNgramType :: CTabNgramType
, withAutoUpdate :: Boolean -- (?) not used
)
......@@ -417,7 +416,6 @@ type PropsNoReload =
, mTotalRows :: Maybe Int
, path :: T.Box PageParams
, session :: Session
, sidePanel :: T.Box (Maybe (Record SidePanel))
, state :: T.Box State
, treeEdit :: Record NgramsTreeEditProps
, versioned :: VersionedNgramsTable
......@@ -489,18 +487,17 @@ loadedNgramsTableBody = R.createElement loadedNgramsTableBodyCpt
loadedNgramsTableBodyCpt :: R.Component PropsNoReload
loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
cpt { afterSync
, boxes: boxes@{ errors
, tasks }
, cacheState
, mTotalRows
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit: treeEdit@{ getNgramsChildrenAff, getNgramsChildren }
, versioned: Versioned { data: initTable }
} _ = do
{ errors, tasks } <- Store.use
treeEdit'@{ ngramsParent } <- T.useLive T.unequal treeEdit.box
state'@{ ngramsLocalPatch, ngramsSelection } <- T.useLive T.unequal state
path'@{ scoreType, termListFilter, termSizeFilter } <- T.useLive T.unequal path
......@@ -562,8 +559,7 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
filteredConvertedRows = convertRow <$> filteredRows
convertRow ngramsElement =
{ row: renderNgramsItem { boxes
, corpusId: path'.nodeId
{ row: renderNgramsItem { corpusId: path'.nodeId
, dispatch: performAction
, getNgramsChildrenAff
, getNgramsChildren
......@@ -574,8 +570,7 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
, ngramsLocalPatch
, ngramsSelection
, ngramsTable
, session: path'.session
, sidePanel } []
, session: path'.session } []
, delete: false
}
......@@ -787,7 +782,6 @@ type MainNgramsTableProps = (
-- ^ This node can be a corpus or contact.
, path :: T.Box PageParams
, session :: Session
, sidePanel :: T.Box (Maybe (Record SidePanel))
, tabType :: TabType
, treeEdit :: Record NgramsTreeEditProps
| CommonProps
......@@ -1029,11 +1023,9 @@ mainNgramsTableCacheOn = R2.leaf mainNgramsTableCacheOnCpt
mainNgramsTableCacheOnCpt :: R.Component MainNgramsTableCacheProps
mainNgramsTableCacheOnCpt = here.component "mainNgramsTableCacheOn" cpt where
cpt { afterSync
, boxes
, defaultListId
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit
......@@ -1043,11 +1035,9 @@ mainNgramsTableCacheOnCpt = here.component "mainNgramsTableCacheOn" cpt where
path' <- T.useLive T.unequal path
let render versioned = mainNgramsTablePaint { afterSync
, boxes
, cacheState: NT.CacheOn
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit
......@@ -1063,7 +1053,7 @@ mainNgramsTableCacheOnCpt = here.component "mainNgramsTableCacheOn" cpt where
, spinnerClass: Nothing
}
versionEndpoint { defaultListId, path: { nodeId, tabType, session } } _ = get session $ Routes.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId)
errorHandler = logRESTError here "[mainNgramsTableCacheOn]"
errorHandler = logRESTError (R2.herePrefix here "[mainNgramsTableCacheOn]")
mkRequest :: PageParams -> GUC.Request
mkRequest path@{ session } = GUC.makeGetRequest session $ url path
where
......@@ -1080,32 +1070,27 @@ mainNgramsTableCacheOff = R2.leaf mainNgramsTableCacheOffCpt
mainNgramsTableCacheOffCpt :: R.Component MainNgramsTableCacheProps
mainNgramsTableCacheOffCpt = here.component "mainNgramsTableCacheOff" cpt where
cpt { afterSync
, boxes
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit
, withAutoUpdate } _ = do
let render versionedWithCount = mainNgramsTablePaintNoCache { afterSync
, boxes
, cacheState: NT.CacheOff
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit
, versionedWithCount
, withAutoUpdate } []
useLoaderBox { errorHandler
useLoaderBox { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[mainNgramsTableCacheOff]"
, loader
, path
, render }
errorHandler = logRESTError here "[mainNgramsTableCacheOff]"
-- NOTE With cache off
loader :: PageParams -> AffRESTError VersionedWithCountNgramsTable
loader { listIds
......@@ -1133,7 +1118,6 @@ type MainNgramsTablePaintProps = (
cacheState :: NT.CacheState
, path :: T.Box PageParams
, session :: Session
, sidePanel :: T.Box (Maybe (Record SidePanel))
, state :: T.Box State
, treeEdit :: Record NgramsTreeEditProps
, versioned :: VersionedNgramsTable
......@@ -1146,11 +1130,9 @@ mainNgramsTablePaintCpt :: R.Component MainNgramsTablePaintProps
mainNgramsTablePaintCpt = here.component "mainNgramsTablePaint" cpt
where
cpt { afterSync
, boxes
, cacheState
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit
......@@ -1163,12 +1145,10 @@ mainNgramsTablePaintCpt = here.component "mainNgramsTablePaint" cpt
pure $
loadedNgramsTableBody
{ afterSync
, boxes
, cacheState
, mTotalRows: Nothing
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit
......@@ -1180,7 +1160,6 @@ type MainNgramsTablePaintNoCacheProps = (
cacheState :: NT.CacheState
, path :: T.Box PageParams
, session :: Session
, sidePanel :: T.Box (Maybe (Record SidePanel))
, state :: T.Box State
, treeEdit :: Record NgramsTreeEditProps
, versionedWithCount :: VersionedWithCountNgramsTable
......@@ -1193,11 +1172,9 @@ mainNgramsTablePaintNoCacheCpt :: R.Component MainNgramsTablePaintNoCacheProps
mainNgramsTablePaintNoCacheCpt = here.component "mainNgramsTablePaintNoCache" cpt
where
cpt { afterSync
, boxes
, cacheState
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit
......@@ -1213,12 +1190,10 @@ mainNgramsTablePaintNoCacheCpt = here.component "mainNgramsTablePaintNoCache" cp
pure $
loadedNgramsTableBody
{ afterSync
, boxes
, cacheState
, mTotalRows: Just count
, path
, session
, sidePanel
, state
, tabNgramType
, treeEdit
......
......@@ -17,10 +17,9 @@ import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Variant(..))
import Gargantext.Components.Nodes.Lists.SidePanel (SidePanel)
import Gargantext.Components.Table as Tbl
import Gargantext.Core.NgramsTable.Functions (applyNgramsPatches, setTermListA, tablePatchHasNgrams)
import Gargantext.Core.NgramsTable.Types (Action(..), CoreAction, NgramsClick, NgramsDepth, NgramsElement, NgramsTable, NgramsTablePatch, NgramsTerm, _NgramsElement, _NgramsRepoElement, _children, _list, _ngrams, _occurrences, ngramsTermText, replace)
......@@ -229,8 +228,7 @@ treeLoadedCpt = here.component "treeLoaded" cpt where
H.ul {} <<< map (\ngrams -> tree ((Record.delete (Proxy :: Proxy "ngramsChildren") params) { ngramsDepth = {depth, ngrams, parent: Just ngramsDepth.ngrams} })) <<< L.toUnfoldable
type RenderNgramsItem =
( boxes :: Boxes
, corpusId :: GT.CorpusId
( corpusId :: GT.CorpusId
, dispatch :: Action -> Effect Unit
, getNgramsChildrenAff :: Maybe (NgramsTerm -> Aff (Array NgramsTerm))
, getNgramsChildren :: Maybe (NgramsTerm -> Array NgramsTerm)
......@@ -242,7 +240,6 @@ type RenderNgramsItem =
, ngramsSelection :: Set NgramsTerm
, ngramsTable :: NgramsTable
, session :: Session
, sidePanel :: T.Box (Maybe (Record SidePanel))
)
renderNgramsItem :: R2.Component RenderNgramsItem
......@@ -250,8 +247,7 @@ renderNgramsItem = R.createElement renderNgramsItemCpt
renderNgramsItemCpt :: R.Component RenderNgramsItem
renderNgramsItemCpt = here.component "renderNgramsItem" cpt
where
cpt { boxes
, corpusId
cpt { corpusId
, dispatch
--, getNgramsChildren
, isEditing
......@@ -262,14 +258,14 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt
, ngramsSelection
, ngramsTable
, session
, sidePanel
} _ = do
{ sidePanelLists } <- Store.use
isEditing' <- T.useLive T.unequal isEditing
mCurrentNgrams <-
T.useFocused
(maybe Nothing _.mCurrentNgrams)
(\val -> maybe Nothing (\sp -> Just $ sp { mCurrentNgrams = val })) sidePanel
(\val -> maybe Nothing (\sp -> Just $ sp { mCurrentNgrams = val })) sidePanelLists
mCurrentNgrams' <- T.useLive T.unequal mCurrentNgrams
let currentRowSelected = mCurrentNgrams' == Just ngrams
......@@ -278,12 +274,10 @@ renderNgramsItemCpt = here.component "renderNgramsItem" cpt
pure $ Tbl.makeRow' { className }
[ selected
,
ngramsContext { boxes
, corpusId
ngramsContext { corpusId
, mListId
, ngrams
, session
, sidePanel } []
, session } []
,
B.wad'
[ "col-score" ] $
......@@ -450,27 +444,25 @@ nextTermList GT.CandidateTerm = GT.MapTerm
type NgramsContextProps =
( boxes :: Boxes
, corpusId :: GT.CorpusId
( corpusId :: GT.CorpusId
, mListId :: Maybe GT.ListId
, ngrams :: NgramsTerm
, session :: Session
, sidePanel :: T.Box (Maybe (Record SidePanel)))
)
ngramsContext :: R2.Component NgramsContextProps
ngramsContext = R.createElement ngramsContextCpt
ngramsContextCpt :: R.Component NgramsContextProps
ngramsContextCpt = here.component "ngramsContext" cpt where
cpt { ngrams
, boxes: { sidePanelState }
, corpusId
, mListId
, session
, sidePanel } _ = do
, session } _ = do
{ sidePanelLists, sidePanelState } <- Store.use
mCurrentNgrams <-
T.useFocused
(maybe Nothing _.mCurrentNgrams)
(\val -> maybe Nothing (\sp -> Just $ sp { mCurrentNgrams = val })) sidePanel
(\val -> maybe Nothing (\sp -> Just $ sp { mCurrentNgrams = val })) sidePanelLists
mCurrentNgrams' <- T.useLive T.unequal mCurrentNgrams
let selected = mCurrentNgrams' == Just ngrams
......@@ -484,12 +476,12 @@ ngramsContextCpt = here.component "ngramsContext" cpt where
-- R2.callTrigger triggerAnnotatedDocIdChange { corpusId, listId, nodeId }
-- T2.reload tableReload
if selected then do
T.write_ Nothing sidePanel
T.write_ Nothing sidePanelLists
T.write_ GT.Closed sidePanelState
else do
T.write_ (Just { mCorpusId: Just corpusId
, mListId
, mCurrentNgrams: Just ngrams }) sidePanel
, mCurrentNgrams: Just ngrams }) sidePanelLists
T.write_ GT.Opened sidePanelState
pure $ H.div { className: "doc-chooser text-center" }
......
......@@ -16,7 +16,7 @@ import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types as CT
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table (defaultContainer, initialParams, makeRow, table, tableHeaderLayout) as TT
import Gargantext.Components.Table.Types (ColumnName(..), Params) as TT
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Ends (url, Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(..))
......@@ -69,19 +69,17 @@ type KeyLayoutProps =
annuaireLayoutWithKey :: R2.Leaf KeyLayoutProps
annuaireLayoutWithKey = R2.leaf annuaireLayoutWithKeyCpt
annuaireLayoutWithKeyCpt :: R.Component KeyLayoutProps
annuaireLayoutWithKeyCpt = here.component "annuaireLayoutWithKey" cpt where
cpt { frontends, nodeId, session } _ = do
path <- T.useBox nodeId
path' <- T.useLive T.unequal path
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[annuaireLayoutWithKey]"
, loader: getAnnuaireInfo session
, path: path'
, render: \info -> annuaire { frontends, info, path, session } }
where
errorHandler = logRESTError here "[annuaireLayoutWithKey]"
type AnnuaireProps =
( session :: Session
......@@ -136,19 +134,17 @@ type PageLayoutProps =
pageLayout :: Record PageLayoutProps -> R.Element
pageLayout props = R.createElement pageLayoutCpt props []
pageLayoutCpt :: R.Component PageLayoutProps
pageLayoutCpt = here.component "pageLayout" cpt
where
cpt { frontends, pagePath, session } _ = do
pagePath' <- T.useLive T.unequal pagePath
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[pageLayout]"
, loader: loadPage session
, path: pagePath'
, render: \table -> page { session, table, frontends, pagePath } }
where
errorHandler = logRESTError here "[pageLayout]"
type PageProps =
( frontends :: Frontends
......
......@@ -8,7 +8,7 @@ import Data.Maybe (Maybe(..))
import Data.Show.Generic (genericShow)
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.DocsTable.Types (Year)
import Gargantext.Components.NgramsTable as NT
......@@ -51,14 +51,11 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors
type TabsProps =
( boxes :: Boxes
, cacheState :: T.Box LTypes.CacheState
( cacheState :: T.Box LTypes.CacheState
, defaultListId :: Int
, frontends :: Frontends
, nodeId :: Int
, session :: Session
, sidePanel :: T.Box (Maybe (Record TextsT.SidePanel))
, sidePanelList :: T.Box (Maybe (Record LSidePanel.SidePanel))
)
tabs :: R2.Leaf TabsProps
......@@ -76,24 +73,21 @@ tabsCpt = here.component "tabs" cpt where
, tabs: tabs' yearFilter chartReload props
, className: "nodes-annuaire-layout-tabs"
}
tabs' yearFilter chartReload props@{ boxes, defaultListId, sidePanel } =
tabs' yearFilter chartReload props@{ defaultListId } =
[ "Documents" /\ docs
, "Patents" /\ ngramsView (viewProps Patents)
, "Books" /\ ngramsView (viewProps Books)
, "Communication" /\ ngramsView (viewProps Communication)
, "Trash" /\ docs -- TODO pass-in trash mode
] where
viewProps mode = { boxes : props.boxes
, cacheState : props.cacheState
viewProps mode = { cacheState : props.cacheState
, defaultListId : props.defaultListId
, frontends : props.frontends
, mode
, nodeId : props.nodeId
, session : props.session
, sidePanel : props.sidePanel
, sidePanelList : props.sidePanelList }
, session : props.session }
totalRecords = 4736 -- TODO lol
docs = DT.docViewLayout (Record.merge { boxes, chartReload, sidePanel } $ Record.merge dtCommon dtExtra)
docs = DT.docViewLayout (Record.merge { chartReload } $ Record.merge dtCommon dtExtra)
dtCommon = RX.pick props :: Record DTCommon
dtExtra =
{ chart: mempty
......@@ -125,8 +119,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where
cpt props@{ defaultListId
, mode
, nodeId
, session
, sidePanelList } _ = do
, session } _ = do
path <- T.useBox $
NTC.initialPageParams session nodeId
[ defaultListId ] (TabDocument TabDocs)
......@@ -141,7 +134,6 @@ ngramsViewCpt = here.component "ngramsView" cpt where
(Record.merge most
{ afterSync
, path
, sidePanel: sidePanelList
, tabType: TabPairing (TabNgramType $ modeTabType mode)
, tabNgramType: modeTabType' mode
, treeEdit: { box: treeEditBox
......@@ -158,8 +150,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where
pure $ NT.mainNgramsTable props' []
type NTCommon =
( boxes :: Boxes
, cacheState :: T.Box LTypes.CacheState
( cacheState :: T.Box LTypes.CacheState
, defaultListId :: Int
, session :: Session
)
......@@ -6,11 +6,11 @@ module Gargantext.Components.Nodes.Annuaire.User.Contact
import Gargantext.Prelude
import Data.Lens (view)
import Data.Maybe (Maybe(..))
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ComponentStatus(..))
import Gargantext.Components.GraphQL.Endpoints (getAnnuaireContact)
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (ContactData', HyperdataContact(..))
import Gargantext.Config.REST (logRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Session (useSession)
import Gargantext.Types (NodeID)
......@@ -30,12 +30,8 @@ type Props =
contactLayout :: R2.Leaf ( key :: String | Props )
contactLayout = R2.leaf contactLayoutCpt
contactLayoutCpt :: R.Component ( key :: String | Props )
contactLayoutCpt = here.component "layout" cpt where
-- Helpers
errorHandler = logRESTError here "[contactLayoutWithKey]"
-- Component
cpt { nodeId
} _ = do
......@@ -45,7 +41,8 @@ contactLayoutCpt = here.component "layout" cpt where
-- _ /\ reload <- R2.useBox' T2.newReload
useLoader
{ errorHandler
{ errorHandler: Nothing
, herePrefix: R2.herePrefix here "[contactLayout]"
, loader: getAnnuaireContact session
, path: nodeId
, render:
......
......@@ -7,7 +7,7 @@ import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Data.Show.Generic (genericShow)
import Data.Tuple.Nested ((/\))
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.DocsTable.Types (Year)
import Gargantext.Components.NgramsTable as NT
......@@ -49,14 +49,12 @@ modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors
type TabsProps =
( boxes :: Boxes
, cacheState :: T.Box LTypes.CacheState
( cacheState :: T.Box LTypes.CacheState
, defaultListId :: Int
, frontends :: Frontends
, nodeId :: Int
, session :: Session
, sidePanel :: T.Box (Maybe (Record TTypes.SidePanel))
, sidePanelList :: T.Box (Maybe (Record LSidePanel.SidePanel))
)
tabs :: R2.Leaf TabsProps
......@@ -64,14 +62,12 @@ tabs = R2.leaf tabsCpt
tabsCpt :: R.Component TabsProps
tabsCpt = here.component "tabs" cpt
where
cpt { boxes
, cacheState
cpt { cacheState
, defaultListId
, frontends
, nodeId
, session
, sidePanel
, sidePanelList
} _ = do
activeTab <- T.useBox 0
yearFilter <- T.useBox (Nothing :: Maybe Year)
......@@ -87,35 +83,28 @@ tabsCpt = here.component "tabs" cpt
, "Trash" /\ docs -- TODO pass-in trash mode
]
where
patentsView = { boxes
, cacheState
patentsView = { cacheState
, defaultListId
, mode: Patents
, nodeId
, session
, sidePanel: sidePanelList
}
booksView = { boxes
, cacheState
booksView = { cacheState
, defaultListId
, mode: Books
, nodeId
, session
, sidePanel: sidePanelList
}
commView = { boxes
, cacheState
commView = { cacheState
, defaultListId
, mode: Communication
, nodeId
, session
, sidePanel: sidePanelList
}
chart = mempty
totalRecords = 4736 -- TODO
docs = DT.docViewLayout
{ boxes
, cacheState
{ cacheState
, chart
, chartReload
, frontends
......@@ -124,7 +113,6 @@ tabsCpt = here.component "tabs" cpt
, nodeId
, session
, showSearch: true
, sidePanel
, tabType: TabPairing TabDocs
, totalRecords
, yearFilter
......@@ -132,13 +120,11 @@ tabsCpt = here.component "tabs" cpt
type NgramsViewTabsProps = (
boxes :: Boxes
, cacheState :: T.Box LTypes.CacheState
cacheState :: T.Box LTypes.CacheState
, defaultListId :: Int
, mode :: Mode
, nodeId :: Int
, session :: Session
, sidePanel :: T.Box (Maybe (Record LSidePanel.SidePanel))
)
ngramsView :: R2.Component NgramsViewTabsProps
......@@ -146,13 +132,11 @@ ngramsView = R.createElement ngramsViewCpt
ngramsViewCpt :: R.Component NgramsViewTabsProps
ngramsViewCpt = here.component "ngramsView" cpt
where
cpt { boxes
, cacheState
cpt { cacheState
, defaultListId
, mode
, nodeId
, session
, sidePanel } _ = do
, session } _ = do
path <- T.useBox $ NTC.initialPageParams session nodeId [defaultListId] (TabDocument TabDocs)
onCancelRef <- R.useRef Nothing
onNgramsClickRef <- R.useRef Nothing
......@@ -161,12 +145,10 @@ ngramsViewCpt = here.component "ngramsView" cpt
pure $ NT.mainNgramsTable {
afterSync: \_ -> pure unit
, boxes
, cacheState
, defaultListId
, path
, session
, sidePanel
, tabNgramType
, tabType
, treeEdit: { box: treeEditBox
......
......@@ -35,7 +35,7 @@ nodeCpt = here.component "node" cpt where
-- | Computed
-- |
let
errorHandler = logRESTError here "[corpusLayout]"
errorHandler = logRESTError (R2.herePrefix here "[corpusLayout]")
loader { nodeId: nodeId_, session: session_ } = getNode session_ nodeId_
......
......@@ -5,6 +5,7 @@ import Gargantext.Prelude
import Data.Array as A
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Nodes.Corpus.Chart.Types (MetricsProps, ReloadPath)
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Hooks.Loader (HashedResponse, useLoader, useLoaderWithCacheAPI)
......@@ -34,24 +35,21 @@ metricsLoadView p = R.createElement metricsLoadViewCpt p []
metricsLoadViewCpt :: forall a. Eq a => R.Component (MetricsLoadViewProps a)
metricsLoadViewCpt = here.component "metricsLoadView" cpt
where
cpt { boxes: boxes@{ errors }
, getMetrics
cpt { getMetrics
, loaded
, onClick
, onInit
, path
, reload
, session } _ = do
{ errors } <- Store.use
reload' <- T.useLive T.unequal reload
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[metricsLoadView]"
, loader: getMetrics session
, path: reload' /\ path
, render: \l -> loaded { boxes, path, reload, session, onClick, onInit } l }
where
errorHandler error = do
T.modify_ (A.cons $ FRESTError { error }) errors
here.warn2 "RESTError" error
, render: \l -> loaded { path, reload, session, onClick, onInit } l }
type MetricsWithCacheLoadViewProps res ret =
( getMetricsHash :: Session -> ReloadPath -> AffRESTError Hash
......@@ -71,8 +69,7 @@ metricsWithCacheLoadViewCpt :: forall res ret.
R.Component (MetricsWithCacheLoadViewProps res ret)
metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt
where
cpt { boxes
, getMetricsHash
cpt { getMetricsHash
, handleResponse
, loaded
, mkRequest
......@@ -83,10 +80,9 @@ metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt
, onInit } _ = do
reload' <- T.useLive T.unequal reload
useLoaderWithCacheAPI { boxes
, cacheEndpoint: (getMetricsHash session)
useLoaderWithCacheAPI { cacheEndpoint: (getMetricsHash session)
, handleResponse
, mkRequest
, path: (reload' /\ path)
, renderer: \metrics -> loaded { boxes, path, reload, session, onClick, onInit, metrics }
, renderer: \metrics -> loaded { path, reload, session, onClick, onInit, metrics }
, spinnerClass: Just "echarts-for-react-spinner" }
......@@ -103,12 +103,11 @@ histo props = R.createElement histoCpt props []
histoCpt :: R.Component Props
histoCpt = here.component "histo" cpt
where
cpt { boxes, path, session, onClick, onInit } _ = do
cpt { path, session, onClick, onInit } _ = do
reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView
{ boxes
, getMetricsHash
{ getMetricsHash
, handleResponse
, loaded
, mkRequest: mkRequest session
......
......@@ -112,12 +112,11 @@ metrics props = R.createElement metricsCpt props []
metricsCpt :: R.Component Props
metricsCpt = here.component "etrics" cpt
where
cpt { boxes, onClick, onInit, path, session } _ = do
cpt { onClick, onInit, path, session } _ = do
reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView {
boxes
, getMetricsHash
getMetricsHash
, handleResponse
, loaded
, mkRequest: mkRequest session
......
......@@ -109,12 +109,11 @@ pie = R2.leaf pieCpt
pieCpt :: R.Component Props
pieCpt = here.component "pie" cpt
where
cpt { boxes, path, session, onClick, onInit } _ = do
cpt { path, session, onClick, onInit } _ = do
reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView
{ boxes
, getMetricsHash
{ getMetricsHash
, handleResponse
, loaded: loadedPie
, mkRequest: mkRequest session
......@@ -144,12 +143,11 @@ bar props = R.createElement barCpt props []
barCpt :: R.Component Props
barCpt = here.component "bar" cpt
where
cpt { boxes, path, session, onClick, onInit} _ = do
cpt { path, session, onClick, onInit} _ = do
reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView {
boxes
, getMetricsHash
getMetricsHash
, handleResponse
, loaded: loadedBar
, mkRequest: mkRequest session
......
......@@ -7,7 +7,6 @@ import Data.Maybe (Maybe(..), fromMaybe)
import Data.Ord.Generic (genericCompare)
import Data.Show.Generic (genericShow)
import Effect (Effect)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Charts.Options.Type (EChartsInstance, MouseEvent)
import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics)
......@@ -55,8 +54,7 @@ allPredefinedCharts =
type Params =
( boxes :: Boxes
, corpusId :: NodeID
( corpusId :: NodeID
-- optinal params
, limit :: Maybe Int
, listId :: Maybe Int
......@@ -66,40 +64,40 @@ type Params =
)
render :: PredefinedChart -> Record Params -> R.Element
render CDocsHistogram { boxes, corpusId, listId, session, onClick, onInit } =
histo { boxes, path, session, onClick, onInit }
render CDocsHistogram { corpusId, listId, session, onClick, onInit } =
histo { path, session, onClick, onInit }
where
path = { corpusId
, listId: fromMaybe 0 listId
, limit: Nothing
, tabType: TabCorpus TabDocs
}
render CAuthorsPie { boxes, corpusId, listId, session, onClick, onInit } =
pie { boxes, path, session, onClick, onInit }
render CAuthorsPie { corpusId, listId, session, onClick, onInit } =
pie { path, session, onClick, onInit }
where
path = { corpusId
, listId: fromMaybe 0 listId
, limit: Nothing
, tabType: TabCorpus (TabNgramType $ modeTabType Authors)
}
render CInstitutesTree { boxes, corpusId, limit, listId, session, onClick, onInit } =
tree { boxes, path, session, onClick, onInit }
render CInstitutesTree { corpusId, limit, listId, session, onClick, onInit } =
tree { path, session, onClick, onInit }
where
path = { corpusId
, limit
, listId: fromMaybe 0 listId
, tabType: TabCorpus (TabNgramType $ modeTabType Institutes)
}
render CTermsMetrics { boxes, corpusId, limit, listId, session, onClick, onInit } =
metrics { boxes, path, session, onClick, onInit }
render CTermsMetrics { corpusId, limit, listId, session, onClick, onInit } =
metrics { path, session, onClick, onInit }
where
path = { corpusId
, limit
, listId: fromMaybe 0 listId
, tabType: TabCorpus (TabNgramType $ modeTabType Terms)
}
render CSourcesBar { boxes, corpusId, limit, listId, session, onClick, onInit } =
bar { boxes, path, session, onClick, onInit }
render CSourcesBar { corpusId, limit, listId, session, onClick, onInit } =
bar { path, session, onClick, onInit }
where
path = { corpusId
, limit
......
......@@ -79,12 +79,11 @@ tree props = R.createElement treeCpt props []
treeCpt :: R.Component Props
treeCpt = here.component "tree" cpt
where
cpt { boxes, path, session, onClick, onInit } _ = do
cpt { path, session, onClick, onInit } _ = do
reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView
{ boxes
, getMetricsHash
{ getMetricsHash
, handleResponse
, loaded
, mkRequest: mkRequest session
......@@ -107,3 +106,4 @@ loadedCpt = here.component "loaded" cpt where
, U.chartUpdateButton { chartType: ChartTree, path, reload, session }
, -} chart $ scatterOptions p
]
......@@ -18,8 +18,7 @@ type Path = (
)
type Props = (
boxes :: Boxes
, path :: Record Path
path :: Record Path
, session :: Session
, onClick :: Maybe (MouseEvent -> Effect Unit)
, onInit :: Maybe (EChartsInstance -> Effect Unit)
......
......@@ -17,7 +17,6 @@ import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Nodes.Corpus.Types (Hyperdata(..))
import Gargantext.Components.Nodes.Types (FTFieldList(..), FTFieldsWithIndex(..), defaultField)
import Gargantext.Components.TileMenu (tileMenu)
import Gargantext.Config.REST (logRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as GR
import Gargantext.Sessions (Session, sessionId)
......@@ -52,12 +51,11 @@ corpusCodeLayoutCpt = here.component "corpusCodeLayout" cpt where
cpt { nodeId, session, boxes } _ = do
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[corpusCodeLayout]"
, loader: loadCorpusWithReload
, path: { nodeId, reload: reload', session }
, render: \corpus -> corpusCodeView { corpus, nodeId, reload, session, boxes } }
where
errorHandler = logRESTError here "[corpusLayoutWithKey]"
corpusCodeView :: Record ViewProps -> R.Element
corpusCodeView props = R.createElement corpusCodeViewCpt props []
......
......@@ -8,12 +8,10 @@ import Data.Maybe (Maybe(..), fromMaybe)
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Corpus.CodeSection (fieldsCodeEditor)
import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P
import Gargantext.Components.Nodes.Dashboard.Types as DT
import Gargantext.Components.Nodes.Types (FTFieldList(..), FTFieldsWithIndex(..), defaultField)
import Gargantext.Config.REST (logRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Unit, bind, discard, pure, read, show, unit, ($), (<$>), (<>), (==))
import Gargantext.Sessions (Session, sessionId)
......@@ -29,8 +27,7 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Dashboard"
type Props =
( boxes :: Boxes
, nodeId :: NodeID
( nodeId :: NodeID
, session :: Session )
dashboardLayout :: R2.Component Props
......@@ -52,17 +49,17 @@ dashboardLayoutWithKey = R.createElement dashboardLayoutWithKeyCpt
dashboardLayoutWithKeyCpt :: R.Component KeyProps
dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt
where
cpt { boxes, nodeId, session } _ = do
cpt { nodeId, session } _ = do
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[dashboardLayoutWithKey]"
, loader: DT.loadDashboardWithReload
, path: { nodeId, reload: reload', session }
, render: \(DT.DashboardData { hyperdata: DT.Hyperdata h, parentId }) -> do
let { charts, fields } = h
dashboardLayoutLoaded { boxes
, charts
dashboardLayoutLoaded { charts
, corpusId: parentId
, defaultListId: 0
, fields
......@@ -70,7 +67,6 @@ dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt
, onChange: onChange nodeId reload (DT.Hyperdata h)
, session } [] }
where
errorHandler = logRESTError here "[dashboardLayoutWithKey]"
onChange :: NodeID -> T2.ReloadS -> DT.Hyperdata -> { charts :: Array P.PredefinedChart
, fields :: FTFieldList } -> Effect Unit
onChange nodeId' reload (DT.Hyperdata h) { charts, fields } = do
......@@ -85,8 +81,7 @@ dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt
T2.reload reload
type LoadedProps =
( boxes :: Boxes
, charts :: Array P.PredefinedChart
( charts :: Array P.PredefinedChart
, corpusId :: NodeID
, defaultListId :: Int
, fields :: FTFieldList
......@@ -101,8 +96,7 @@ dashboardLayoutLoaded = R.createElement dashboardLayoutLoadedCpt
dashboardLayoutLoadedCpt :: R.Component LoadedProps
dashboardLayoutLoadedCpt = here.component "dashboardLayoutLoaded" cpt
where
cpt { boxes
, charts
cpt { charts
, corpusId
, defaultListId
, fields
......@@ -132,8 +126,7 @@ dashboardLayoutLoadedCpt = here.component "dashboardLayoutLoaded" cpt
, fields }
chartsEls = mapWithIndex chartIdx charts
chartIdx idx chart =
renderChart { boxes
, chart
renderChart { chart
, corpusId
, defaultListId
, onChange: onChangeChart
......@@ -209,8 +202,7 @@ dashboardCodeEditorCpt = here.component "dashboardCodeEditor" cpt
List.snoc fs $ { idx: List.length fs, ftField: defaultField }) fieldsS
type PredefinedChartProps =
( boxes :: Boxes
, chart :: P.PredefinedChart
( chart :: P.PredefinedChart
, corpusId :: NodeID
, defaultListId :: Int
, onChange :: P.PredefinedChart -> Effect Unit
......@@ -223,8 +215,7 @@ renderChart = R.createElement renderChartCpt
renderChartCpt :: R.Component PredefinedChartProps
renderChartCpt = here.component "renderChart" cpt
where
cpt { boxes
, chart
cpt { chart
, corpusId
, defaultListId
, onChange
......@@ -259,8 +250,7 @@ renderChartCpt = here.component "renderChart" cpt
where
value = R.unsafeEventValue e
onRemoveClick _ = onRemove unit
params = { boxes
, corpusId
params = { corpusId
, limit: Just 1000
, listId: Just defaultListId
, onClick: Nothing
......
......@@ -55,7 +55,7 @@ nodeCpt = here.component "node" cpt where
-- | Hooks
-- |
useLoaderEffect
{ errorHandler: logRESTError here "[documentLayoutWithKey]"
{ errorHandler: logRESTError (R2.herePrefix here "[documentLayoutWithKey]")
, loader: loadData
, path
, state
......
......@@ -45,7 +45,7 @@ nodeCpt = here.component "node" cpt where
-- | Computed
-- |
let errorHandler = logRESTError here "[phylo]"
let errorHandler = logRESTError (R2.herePrefix here "[phylo]")
-- | Hooks
-- |
......
......@@ -6,7 +6,7 @@ import Data.Eq.Generic (genericEq)
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Ends (toUrl)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(..))
......@@ -52,12 +52,12 @@ fileLayout = R2.leaf fileLayoutCpt
fileLayoutCpt :: R.Component FileLayoutProps
fileLayoutCpt = here.component "fileLayout" cpt where
cpt { nodeId, session } _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[fileLayout]"
, loader: loadFile session
, path: nodeId
, render: onLoad }
where
errorHandler = logRESTError here "[fileLayout]"
onLoad loaded = fileLayoutLoaded { loaded, nodeId, session }
loadFile :: Session -> NodeID -> AffRESTError File
......
......@@ -46,7 +46,7 @@ nodeCpt = here.component "node" cpt where
-- | Hooks
-- |
useLoaderEffect
{ errorHandler: logRESTError here "[frameLayout]"
{ errorHandler: logRESTError (R2.herePrefix here "[frameLayout]")
, loader: loadframeWithReload
, path:
{ nodeId
......
......@@ -56,7 +56,7 @@ nodeCpt = here.component "node" cpt where
-- | Computed
-- |
let errorHandler = logRESTError here "[node]"
let errorHandler = logRESTError (R2.herePrefix here "[node]")
-- | Hooks
-- |
......
......@@ -70,13 +70,13 @@ renderPublic = R2.leaf renderPublicCpt
renderPublicCpt :: R.Component ()
renderPublicCpt = here.component "renderPublic" cpt where
cpt _ _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[renderPublic]"
, loader: loadPublicData
, path: { reload: 0 }
, render: loaded }
where
loaded publicData = publicLayout { publicData }
errorHandler = logRESTError here "[renderPublic]"
publicLayout :: Record PublicDataProps -> R.Element
publicLayout props = R.createElement publicLayoutCpt props []
......
......@@ -17,7 +17,7 @@ import Gargantext.Components.Nodes.Lists.Tabs as Tabs
import Gargantext.Components.Nodes.Lists.Types (CacheState(..))
import Gargantext.Components.Table as Table
import Gargantext.Config (defaultFrontends)
import Gargantext.Config.REST (logRESTError, AffRESTError)
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Core.NgramsTable.Types (NgramsTerm(..))
import Gargantext.Ends (url)
import Gargantext.Hooks.Loader (useLoader)
......@@ -74,7 +74,8 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
R.useEffectOnce' $ do
T.listen (\{ new } -> afterCacheStateChange new) cacheState
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[listsLayoutWithKey]"
, path
, loader: loadCorpusWithChild
, render: \corpusData@{ corpusId, corpusNode: NodePoly poly } ->
......@@ -92,17 +93,14 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
}
, Tabs.tabs {
activeTab
, boxes
, cacheState
, corpusData
, corpusId
, key: "listsLayoutWithKey-tabs-" <> (show cacheState')
, session
, sidePanel
}
] }
where
errorHandler = logRESTError here "[listsLayoutWithKey]"
afterCacheStateChange cacheState = do
launchAff_ $ clearCache unit
sessionUpdate $ setCacheState session nodeId cacheState
......@@ -204,7 +202,8 @@ ngramsDocListCpt = here.component "ngramsDocList" cpt where
, mListId: Just listId
, mNgrams: Just ngrams
, session } _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[ngramsDocList]"
, path: { corpusId, ngrams, session }
, loader: loaderNgramsDocList
, render: \ctx -> ngramsDocListLoaded { contexts: ctx
......@@ -213,8 +212,6 @@ ngramsDocListCpt = here.component "ngramsDocList" cpt where
, ngrams
, session } []
}
where
errorHandler = logRESTError here "[ngramsDocList]"
type NgramsDocLoadProps =
( corpusId :: GT.CorpusId
......
......@@ -6,7 +6,7 @@ import Data.Array as A
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple.Nested ((/\))
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.NgramsTable as NT
import Gargantext.Core.NgramsTable.Functions as NTC
import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics)
......@@ -33,12 +33,10 @@ here = R2.here "Gargantext.Components.Nodes.Lists.Tabs"
type Props = (
activeTab :: T.Box Int
, boxes :: Boxes
, cacheState :: T.Box CacheState
, corpusData :: CorpusData
, corpusId :: Int
, session :: Session
, sidePanel :: T.Box (Maybe (Record SidePanel))
)
tabs :: Record ( key :: String | Props ) -> R.Element
......@@ -87,13 +85,11 @@ ngramsView :: R2.Component NgramsViewProps
ngramsView = R.createElement ngramsViewCpt
ngramsViewCpt :: R.Component NgramsViewProps
ngramsViewCpt = here.component "ngramsView" cpt where
cpt props@{ boxes
, cacheState
cpt props@{ cacheState
, corpusData: { defaultListId }
, mode
, session
, path
, sidePanel } _ = do
, path } _ = do
chartsReload <- T.useBox T2.newReload
onCancelRef <- R.useRef Nothing
onNgramsClickRef <- R.useRef Nothing
......@@ -106,8 +102,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where
R.fragment
[
ngramsView'
{ boxes
, corpusData: props.corpusData
{ corpusData: props.corpusData
, listIds
, mode
, nodeId
......@@ -117,12 +112,10 @@ ngramsViewCpt = here.component "ngramsView" cpt where
,
NT.mainNgramsTable
{ afterSync: afterSync chartsReload
, boxes
, cacheState
, defaultListId
, path
, session
, sidePanel
, tabNgramType
, tabType
, treeEdit: { box: treeEditBox
......@@ -156,8 +149,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where
-- @XXX re-render issue -> clone component
type NgramsViewProps' =
( boxes :: Boxes
, corpusData :: CorpusData
( corpusData :: CorpusData
, listIds :: Array Int
, mode :: Mode
, nodeId :: Int
......@@ -171,8 +163,7 @@ ngramsView' = R.createElement ngramsViewCpt'
--ngramsViewCpt' = R.memo' $ here.component "ngramsView_clone" cpt where
ngramsViewCpt' :: R.Component NgramsViewProps'
ngramsViewCpt' = here.component "ngramsView_clone" cpt where
cpt { boxes
, corpusData: { defaultListId }
cpt { corpusData: { defaultListId }
, listIds
, mode
, nodeId
......@@ -232,10 +223,10 @@ ngramsViewCpt' = here.component "ngramsView_clone" cpt where
]
charts params' _ = [ chart params' mode ]
chart path Authors = pie { boxes, path, session, onClick: Nothing, onInit: Nothing }
chart path Institutes = tree { boxes, path, session, onClick: Nothing, onInit: Nothing }
chart path Sources = bar { boxes, path, session, onClick: Nothing, onInit: Nothing }
chart path Terms = metrics { boxes, path, session, onClick: Nothing, onInit: Nothing }
chart path Authors = pie { path, session, onClick: Nothing, onInit: Nothing }
chart path Institutes = tree { path, session, onClick: Nothing, onInit: Nothing }
chart path Sources = bar { path, session, onClick: Nothing, onInit: Nothing }
chart path Terms = metrics { path, session, onClick: Nothing, onInit: Nothing }
tabType = TabCorpus (TabNgramType tabNgramType)
......
......@@ -7,7 +7,6 @@ import Data.Maybe (Maybe(..), isJust)
import Data.Show.Generic (genericShow)
import Data.Tuple.Nested ((/\))
import Effect.Aff (launchAff_)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as AppStore
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Elevation(..))
......@@ -75,7 +74,6 @@ textsLayoutCpt = here.component "textsLayout" cpt where
textsLayoutWithKey :: R2.Leaf ( key :: String | Props )
textsLayoutWithKey = R2.leaf textsLayoutWithKeyCpt
textsLayoutWithKeyCpt :: R.Component ( key :: String | Props )
textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt where
cpt { frontends
......@@ -83,8 +81,6 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt where
} _ = do
session <- useSession
boxes@{ sidePanelTexts } <- AppStore.use
cacheState <- T.useBox $ getCacheState LT.CacheOff session nodeId
cacheState' <- T.useLive T.unequal cacheState
......@@ -95,7 +91,8 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt where
R.useEffectOnce' $ do
T.listen (\{ new } -> afterCacheStateChange new) cacheState
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[textsLayoutWithKey]"
, loader: loadCorpusWithChild
, path: { nodeId, session }
, render: \corpusData@{ corpusId, corpusNode } ->
......@@ -117,20 +114,17 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt where
}
,
tabs
{ boxes
, cacheState
{ cacheState
, corpusData
, corpusId
, eChartsInstance
, frontends
, session
, sidePanel: sidePanelTexts
, yearFilter
}
]
}
where
errorHandler = logRESTError here "[textsLayoutWithKey]"
afterCacheStateChange _cacheState = do
launchAff_ $ clearCache unit
-- TODO
......@@ -153,14 +147,12 @@ modeTabType MoreLikeFav = CTabAuthors -- TODO
modeTabType MoreLikeTrash = CTabSources -- TODO
type TabsProps =
( boxes :: Boxes
, cacheState :: T.Box LT.CacheState
( cacheState :: T.Box LT.CacheState
, corpusData :: CorpusData
, corpusId :: NodeID
, eChartsInstance :: T.Box (Maybe EChartsInstance)
, frontends :: Frontends
, session :: Session
, sidePanel :: T.Box (Maybe (Record TT.SidePanel))
, yearFilter :: T.Box (Maybe Year)
)
......@@ -169,14 +161,12 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component TabsProps
tabsCpt = here.component "tabs" cpt
where
cpt { boxes
, cacheState
cpt { cacheState
, corpusId
, corpusData
, eChartsInstance
, frontends
, session
, sidePanel
, yearFilter } _ = do
let
......@@ -215,7 +205,7 @@ tabsCpt = here.component "tabs" cpt
, activeTab
, tabs: [
"Documents" /\ R.fragment [
histoRender { boxes, path, onClick, onInit, reload: chartReload, session } []
histoRender { path, onClick, onInit, reload: chartReload, session } []
, docView' path chartReload TabDocs
]
, "Trash" /\ docView' path chartReload TabTrash
......@@ -229,8 +219,7 @@ tabsCpt = here.component "tabs" cpt
, listId: corpusData.defaultListId
, limit: Nothing
, tabType: TabCorpus TabDocs }
docView' path chartReload tabType = docView { boxes
, cacheState
docView' path chartReload tabType = docView { cacheState
, chartReload
, corpusData
, corpusId
......@@ -239,7 +228,6 @@ tabsCpt = here.component "tabs" cpt
-- , path
, session
, tabType
, sidePanel
, yearFilter
} []
......@@ -252,14 +240,13 @@ histoRender :: R2.Component HistoProps
histoRender = R.createElement histoRenderCpt
histoRenderCpt :: R.Component HistoProps
histoRenderCpt = here.component "histoRender" cpt where
cpt { boxes, path, onClick, onInit, reload, session } _ = do
cpt { path, onClick, onInit, reload, session } _ = do
_ <- T.useLive T.unequal reload
pure $ histo { boxes, path, onClick, onInit, session }
pure $ histo { path, onClick, onInit, session }
type DocViewProps a =
( boxes :: Boxes
, cacheState :: T.Box LT.CacheState
( cacheState :: T.Box LT.CacheState
, chartReload :: T2.ReloadS
, corpusData :: CorpusData
, corpusId :: NodeID
......@@ -268,7 +255,6 @@ type DocViewProps a =
-- , path :: Record DT.Path
, session :: Session
, tabType :: TabSubType a
, sidePanel :: T.Box (Maybe (Record TT.SidePanel))
, yearFilter :: T.Box (Maybe Year)
)
......@@ -281,19 +267,16 @@ docViewCpt = here.component "docView" cpt
pure $ DT.docViewLayout $ docViewLayoutRec props
-- docViewLayoutRec :: forall a. DocViewProps a -> Record DT.LayoutProps
docViewLayoutRec { boxes
, cacheState
docViewLayoutRec { cacheState
, chartReload
, corpusId
, frontends
, listId
, session
, tabType: TabDocs
, sidePanel
, yearFilter
} =
{ boxes
, cacheState
{ cacheState
, chart : H.div {} []
, chartReload
, frontends
......@@ -303,24 +286,20 @@ docViewLayoutRec { boxes
-- ^ TODO merge nodeId and corpusId in DT
, session
, showSearch: true
, sidePanel
, tabType: TabCorpus TabDocs
, totalRecords: 4737
, yearFilter
}
docViewLayoutRec { boxes
, cacheState
docViewLayoutRec { cacheState
, chartReload
, corpusId
, frontends
, listId
, session
, tabType: TabMoreLikeFav
, sidePanel
, yearFilter
} =
{ boxes
, cacheState
{ cacheState
, chart : H.div {} []
, chartReload
, frontends
......@@ -330,24 +309,20 @@ docViewLayoutRec { boxes
-- ^ TODO merge nodeId and corpusId in DT
, session
, showSearch: false
, sidePanel
, tabType: TabCorpus TabMoreLikeFav
, totalRecords: 4737
, yearFilter
}
docViewLayoutRec { boxes
, cacheState
docViewLayoutRec { cacheState
, chartReload
, corpusId
, frontends
, listId
, session
, tabType: TabMoreLikeTrash
, sidePanel
, yearFilter
} =
{ boxes
, cacheState
{ cacheState
, chart : H.div {} []
, chartReload
, frontends
......@@ -357,24 +332,20 @@ docViewLayoutRec { boxes
-- ^ TODO merge nodeId and corpusId in DT
, session
, showSearch: false
, sidePanel
, tabType: TabCorpus TabMoreLikeTrash
, totalRecords: 4737
, yearFilter
}
docViewLayoutRec { boxes
, cacheState
docViewLayoutRec { cacheState
, chartReload
, corpusId
, frontends
, listId
, session
, tabType: TabTrash
, sidePanel
, yearFilter
} =
{ boxes
, cacheState
{ cacheState
, chart : H.div {} []
, chartReload
, frontends
......@@ -384,25 +355,21 @@ docViewLayoutRec { boxes
-- ^ TODO merge nodeId and corpusId in DT
, session
, showSearch: true
, sidePanel
, tabType: TabCorpus TabTrash
, totalRecords: 4737
, yearFilter
}
-- DUMMY
docViewLayoutRec { boxes
, cacheState
docViewLayoutRec { cacheState
, chartReload
, corpusId
, frontends
, listId
, session
, sidePanel
, tabType
, yearFilter
} =
{ boxes
, cacheState
{ cacheState
, chart : H.div {} []
, chartReload
, frontends
......@@ -412,7 +379,6 @@ docViewLayoutRec { boxes
-- ^ TODO merge nodeId and corpusId in DT
, session
, showSearch: true
, sidePanel
, tabType: TabCorpus TabTrash
, totalRecords: 4737
, yearFilter
......@@ -423,9 +389,8 @@ docViewLayoutRec { boxes
textsSidePanel :: R2.Leaf ()
textsSidePanel = R2.leaf textsSidePanelCpt
textsSidePanelCpt :: R.Component ()
textsSidePanelCpt = here.component "sidePanel" cpt where
textsSidePanelCpt = here.component "textsSidePanel" cpt where
cpt _ _ = do
{ sidePanelState
......@@ -581,7 +546,8 @@ sideTextCpt = here.component "sideText" cpt where
-- , state
-- }
useLoader { errorHandler: logRESTError here "[sidePanelText]"
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[sideText]"
, loader: \{ path } -> loadData path
, path: { path }
, render: \loaded -> loadedSideText { loaded
......
......@@ -64,7 +64,7 @@ docFocusCpt = here.component "main" cpt where
-- | Hooks
-- |
useLoaderEffect
{ errorHandler: logRESTError here "[docFocus]"
{ errorHandler: logRESTError (R2.herePrefix here "[docFocus]")
, loader: loadData
, path
, state
......
......@@ -279,8 +279,7 @@ forestCpt = R.memo' $ here.component "forest" cpt where
{ className: "router__aside__inner" }
[
forestLayout
{ boxes
, frontends: defaultFrontends
{ frontends: defaultFrontends
}
]
,
......@@ -518,7 +517,7 @@ dashboardCpt = here.component "dashboard" cpt
cpt props@{ boxes, nodeId } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed (Record.merge { content: \session ->
dashboardLayout { boxes, nodeId, session } [] } sessionProps) []
dashboardLayout { nodeId, session } [] } sessionProps) []
--------------------------------------------------------------
......@@ -730,12 +729,10 @@ user :: R2.Component SessionNodeProps
user = R.createElement userCpt
userCpt :: R.Component SessionNodeProps
userCpt = here.component "user" cpt where
cpt props@{ boxes
, nodeId } _ = do
cpt props@{ nodeId } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed (Record.merge { content: \session ->
userLayout { boxes
, frontends: defaultFrontends
userLayout { frontends: defaultFrontends
, nodeId
, session } [] } sessionProps) []
......
......@@ -104,7 +104,6 @@ tableHeaderWithRenameLayoutCpt = here.component "tableHeaderWithRenameLayoutCpt"
tableHeaderWithRenameBoxedLayout :: R2.Component TableHeaderWithRenameBoxedLayoutProps
tableHeaderWithRenameBoxedLayout = R.createElement tableHeaderWithRenameBoxedLayoutCpt
tableHeaderWithRenameBoxedLayoutCpt :: R.Component TableHeaderWithRenameBoxedLayoutProps
tableHeaderWithRenameBoxedLayoutCpt = here.component "tableHeaderWithRenameBoxedLayoutCpt" cpt
where
......@@ -120,8 +119,7 @@ tableHeaderWithRenameBoxedLayoutCpt = here.component "tableHeaderWithRenameBoxed
cacheState' <- T.useLive T.unequal cacheState
CorpusInfo {title, desc, query, authors} <- T.read corpusInfoS
{ expandTableEdition
} <- AppStore.use
{ expandTableEdition } <- AppStore.use
expandTableEdition' <- R2.useLive' expandTableEdition
......
......@@ -333,8 +333,7 @@ handedChooserCpt = here.component "handedChooser" cpt where
cpt _ _ = do
-- | States
-- |
{ handed
} <- AppStore.use
{ handed } <- AppStore.use
handed' <- R2.useLive' handed
......
......@@ -145,13 +145,12 @@ treeSearchContainerCpt :: R.Component ContainerProps
treeSearchContainerCpt = here.component "treeSearchContainerCpt" cpt where
cpt {query, visible, session } _ = do
useLoader { errorHandler
useLoader { errorHandler: Nothing
, herePrefix: R2.herePrefix here "[treeSearchContainer]"
, path: { session, query }
, loader: loadSearch
, render: \searchData -> treeSearchRenderContainer { visible, session, searchData }
}
where
errorHandler = logRESTError here "[treeSearchContainer]"
treeSearchRenderContainer :: R2.Leaf RenderContainerProps
treeSearchRenderContainer = R2.leaf treeSearchRenderContainerCpt
......
......@@ -16,6 +16,7 @@ import Data.Maybe (Maybe(..))
import Data.MediaType.Common (applicationFormURLEncoded, applicationJSON, multipartFormData)
import Data.Show.Generic (genericShow)
import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
......@@ -174,8 +175,9 @@ instance JSON.ReadForeign FrontendError where
_ -> do
Foreign.fail $ Foreign.ForeignError $ "deserialization for '" <> type_ <> "' not implemented"
logRESTError :: R2.Here -> String -> RESTError -> Effect Unit
logRESTError here' prefix e = here'.warn2 (prefix <> " " <> show e) e
logRESTError :: R2.HerePrefix -> RESTError -> Effect Unit
logRESTError (R2.HerePrefix { here: here', prefix }) e = here'.warn2 (prefix <> " " <> show e) e
-- logRESTError here prefix (SendResponseError e) = here.warn2 (prefix <> " SendResponseError ") e -- TODO: No show
-- logRESTError here prefix (ReadJSONError e) = here.warn2 (prefix <> " ReadJSONError ") $ show e
-- logRESTError here prefix (CustomError e) = here.warn2 (prefix <> " CustomError ") $ e
......
......@@ -18,14 +18,14 @@ here :: R2.Here
here = R2.here "Gargantext.Config.Utils"
handleRESTError :: forall a.
R2.Here
R2.HerePrefix
-> T.Box (Array FrontendError)
-> Either RESTError a
-> (a -> Aff Unit)
-> Aff Unit
handleRESTError here' errors (Left error) _ = liftEffect $ do
handleRESTError herePrefix errors (Left error) _ = liftEffect $ do
T.modify_ (A.cons $ FRESTError { error }) errors
logRESTError here' "[handleTaskError]" error
logRESTError herePrefix error
-- here.warn2 "[handleTaskError] RESTError" error
handleRESTError _ _ (Right task) handler = handler task
......
......@@ -13,6 +13,7 @@ import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Effect.Timer (IntervalId, clearInterval, setInterval)
import Gargantext.Components.App.Store as AppStore
import Gargantext.Components.Forest.Tree.Node.Tools.ProgressBar (QueryProgressData, queryProgress)
import Gargantext.Config.Utils (handleErrorInAsyncProgress, handleRESTError)
import Gargantext.Hooks.FirstEffect (useFirstEffect')
......@@ -26,7 +27,6 @@ import Toestand as T
type AsyncProps =
( asyncTask :: GT.AsyncTaskWithType
, errors :: T.Box (Array FrontendError)
, nodeId :: GT.ID
, onFinish :: Unit -> Effect Unit
, session :: Session
......@@ -39,9 +39,10 @@ asyncProgress :: R2.Component AsyncProps
asyncProgress = R2.component asyncProgressCpt
asyncProgressCpt :: R.Component AsyncProps
asyncProgressCpt = R.hooksComponent "asyncProgress" cpt where
cpt props@{ errors
, onFinish
cpt props@{ onFinish
} children = do
{ errors } <- AppStore.use
-- States
progress /\ progressBox <- R2.useBox' 0.0
intervalIdRef <- R.useRef (Nothing :: Maybe IntervalId)
......@@ -62,7 +63,7 @@ asyncProgressCpt = R.hooksComponent "asyncProgress" cpt where
Right _ -> T.write_ 1000 interval
interval' <- T.read interval
resetInterval intervalIdRef (Just interval') exec
handleRESTError here errors eAsyncProgress onProgress
handleRESTError (R2.herePrefix here "[asyncProgress]") errors eAsyncProgress onProgress
onProgress :: AsyncProgress -> Aff Unit
onProgress value = liftEffect do
......
......@@ -450,7 +450,7 @@ syncPatches props state callback = do
launchAff_ $ do
ePatches <- putNgramsPatches props pt
case ePatches of
Left err -> liftEffect $ logRESTError here "[syncPatches]" err
Left err -> liftEffect $ logRESTError (R2.herePrefix here "[syncPatches]") err
Right (Versioned { data: newPatch, version: newVersion }) -> do
callback unit
liftEffect $ do
......@@ -585,8 +585,7 @@ chartsAfterSync :: forall props discard.
-> Aff Unit
chartsAfterSync path'@{ nodeId } errors tasks _ = do
eTask <- postNgramsChartsAsync path'
handleRESTError here errors eTask $ \task -> liftEffect $ do
here.log2 "[chartsAfterSync] Synchronize task" task
handleRESTError (R2.herePrefix here "[chartsAfterSync]") errors eTask $ \task -> liftEffect $ do
GAT.insert nodeId task tasks
postNgramsChartsAsync :: forall s. CoreParams s -> AffRESTError AsyncTaskWithType
......
......@@ -11,9 +11,9 @@ import Effect (Effect)
import Effect.Aff (Aff, launchAff_, throwError)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.LoadingSpinner (loadingSpinner)
import Gargantext.Config.REST (RESTError, AffRESTError)
import Gargantext.Config.REST (RESTError, AffRESTError, logRESTError)
import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Types (FrontendError(..))
import Gargantext.Utils.CacheAPI as GUC
......@@ -33,7 +33,8 @@ clearCache :: Unit -> Aff Unit
clearCache _ = GUC.delete $ GUC.CacheName cacheName
type UseLoader path state =
( errorHandler :: RESTError -> Effect Unit
( errorHandler :: Maybe (RESTError -> Effect Unit)
, herePrefix :: R2.HerePrefix
, loader :: path -> AffRESTError state
, path :: path
, render :: state -> R.Element
......@@ -42,7 +43,39 @@ type UseLoader path state =
useLoader :: forall path st. Eq path => Eq st
=> Record (UseLoader path st)
-> R.Hooks R.Element
useLoader { errorHandler, loader: loader', path, render } = do
useLoader props@{ errorHandler
, herePrefix
, loader
, path
, render } = do
{ errors } <- Store.use
state <- T.useBox Nothing
useLoader' { errorHandler: errorHandler' errors
, loader
, path
, render }
where
errorHandler' errors error = do
T.modify_ (A.cons $ FRESTError { error }) errors
-- default error handler
case errorHandler of
Nothing -> logRESTError herePrefix error
Just eh -> eh error
-- | Version that doesn't use boxes for errors, prefer unticked one
type UseLoader' path state =
( errorHandler :: RESTError -> Effect Unit
, loader :: path -> AffRESTError state
, path :: path
, render :: state -> R.Element
)
useLoader' :: forall path st. Eq path => Eq st
=> Record (UseLoader' path st)
-> R.Hooks R.Element
useLoader' { errorHandler, loader: loader', path, render } = do
state <- T.useBox Nothing
useLoaderEffect { errorHandler, loader: loader', path, state: state }
......@@ -93,7 +126,8 @@ useLoaderEffect { errorHandler, loader: loader', path, state } = do
type UseLoaderBox path state =
( errorHandler :: RESTError -> Effect Unit
( errorHandler :: Maybe (RESTError -> Effect Unit)
, herePrefix :: R2.HerePrefix
, loader :: path -> AffRESTError state
, path :: T.Box path
, render :: state -> R.Element
......@@ -102,10 +136,14 @@ type UseLoaderBox path state =
useLoaderBox :: forall path st. Eq path => Eq st
=> Record (UseLoaderBox path st)
-> R.Hooks R.Element
useLoaderBox { errorHandler, loader: loader', path, render } = do
useLoaderBox { errorHandler, herePrefix, loader: loader', path, render } = do
path' <- T.useLive T.unequal path
useLoader { errorHandler, loader: loader', path: path', render }
useLoader { errorHandler
, herePrefix
, loader: loader'
, path: path'
, render }
newtype HashedResponse a = HashedResponse { hash :: Hash, value :: a }
......@@ -115,8 +153,7 @@ derive newtype instance JSON.ReadForeign a => JSON.ReadForeign (HashedResponse a
derive newtype instance JSON.WriteForeign a => JSON.WriteForeign (HashedResponse a)
type LoaderWithCacheAPIProps path res ret =
( boxes :: Boxes
, cacheEndpoint :: path -> AffRESTError Hash
( cacheEndpoint :: path -> AffRESTError Hash
, handleResponse :: HashedResponse res -> ret
, mkRequest :: path -> GUC.Request
, path :: path
......@@ -128,8 +165,7 @@ useLoaderWithCacheAPI :: forall path res ret.
Eq ret => Eq path => JSON.ReadForeign res =>
Record (LoaderWithCacheAPIProps path res ret)
-> R.Hooks R.Element
useLoaderWithCacheAPI { boxes
, cacheEndpoint
useLoaderWithCacheAPI { cacheEndpoint
, handleResponse
, mkRequest
, path
......@@ -138,8 +174,7 @@ useLoaderWithCacheAPI { boxes
state <- T.useBox Nothing
state' <- T.useLive T.unequal state
useCachedAPILoaderEffect { boxes
, cacheEndpoint
useCachedAPILoaderEffect { cacheEndpoint
, handleResponse
, mkRequest
, path
......@@ -147,8 +182,7 @@ useLoaderWithCacheAPI { boxes
pure $ maybe (loadingSpinner { additionalClass: spinnerClass }) renderer state'
type LoaderWithCacheAPIEffectProps path res ret = (
boxes :: Boxes
, cacheEndpoint :: path -> AffRESTError Hash
cacheEndpoint :: path -> AffRESTError Hash
, handleResponse :: HashedResponse res -> ret
, mkRequest :: path -> GUC.Request
, path :: path
......@@ -159,12 +193,12 @@ useCachedAPILoaderEffect :: forall path res ret.
Eq ret => Eq path => JSON.ReadForeign res =>
Record (LoaderWithCacheAPIEffectProps path res ret)
-> R.Hooks Unit
useCachedAPILoaderEffect { boxes: { errors }
, cacheEndpoint
useCachedAPILoaderEffect { cacheEndpoint
, handleResponse
, mkRequest
, path
, state } = do
{ errors } <- Store.use
state' <- T.useLive T.unequal state
oPath <- R.useRef path
......@@ -181,7 +215,7 @@ useCachedAPILoaderEffect { boxes: { errors }
-- TODO Parallelize?
hr@(HashedResponse { hash }) <- GUC.cachedJson cache req
eCacheReal <- cacheEndpoint path
handleRESTError here errors eCacheReal $ \cacheReal -> do
handleRESTError (R2.herePrefix here "[useCachedAPILoaderEffect]") errors eCacheReal $ \cacheReal -> do
val <- if hash == cacheReal then
pure hr
else do
......
......@@ -111,6 +111,13 @@ here mod =
, info3 : Console.print3 Console.Main mod Console.Info
}
type Prefix = String
newtype HerePrefix = HerePrefix { here :: Here
, prefix :: Prefix }
herePrefix :: Here -> Prefix -> HerePrefix
herePrefix here prefix = HerePrefix { here, prefix }
-- newtypes
type NTHooksComponent props = props -> Array R.Element -> R.Hooks R.Element
newtype NTComponent p = NTComponent (EffectFn1 p R.Element)
......
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