Commit 0249aa29 authored by Karen Konou's avatar Karen Konou

[home] refactor performAction

parent 419ef08b
Pipeline #7980 passed with stages
in 35 minutes and 23 seconds
......@@ -60,6 +60,7 @@ import Gargantext.Sessions.Types (Session(..), cleanBackendUrl)
import Gargantext.Types (NodeType(..), ID)
import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Routing.Hash (setHash)
......@@ -795,23 +796,35 @@ type PerformActionProps =
)
performAction :: NodeAction.Action -> Record PerformActionProps -> Aff Unit
performAction (NodeAction.DoSearch task) { boxes: { tasks }, id, visible } = liftEffect $ do
case head id of
Just i -> do
GAT.insert i task tasks
T.write_ false visible
Nothing -> pure unit
performAction (NodeAction.UploadFile nodeType fileType fileFormat lang mName contents selection) { boxes: { errors }, session, id, visible } = do
case head id of
Just i -> do
eTask <- uploadFile { contents, fileFormat, fileType, id: i, lang, mName, nodeType, selection, session }
handleRESTError (R2.herePrefix here "[uploadFile']") errors eTask $ \task -> liftEffect $ do
here.log2 "[uploadFile'] UploadFile, uploaded, task:" task
T.write_ false visible
Nothing -> pure unit
performAction = performAction'
where
performAction' (NodeAction.DoSearch task) { boxes: { tasks, reloadForest }, id, visible } = do
doSearch task tasks id visible
refreshTree reloadForest
performAction' (NodeAction.UploadFile nodeType fileType fileFormat lang mName contents selection) { boxes: { errors, reloadForest }, session, id, visible } = do
doUpload nodeType fileType fileFormat lang mName contents selection errors session id visible
refreshTree reloadForest
performAction _ _ = pure unit
performAction' _ _ = pure unit
doSearch task tasks id visible = liftEffect $ do
case head id of
Just i -> do
GAT.insert i task tasks
T.write_ false visible
Nothing -> pure unit
doUpload nodeType fileType fileFormat lang mName contents selection errors session id visible = do
case head id of
Just i -> do
eTask <- uploadFile { contents, fileFormat, fileType, id: i, lang, mName, nodeType, selection, session }
handleRESTError (R2.herePrefix here "[uploadFile']") errors eTask $ \task -> liftEffect $ do
here.log2 "[uploadFile'] UploadFile, uploaded, task:" task
T.write_ false visible
Nothing -> pure unit
refreshTree reloadForest = liftEffect $ T2.reload reloadForest
type FormData =
{ corpusName :: String
......
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