Commit 67d2f108 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Tree] async progress bar endpoint

parent ba5d64c2
...@@ -44,7 +44,7 @@ appCpt = R.hooksComponent "G.C.App.app" cpt where ...@@ -44,7 +44,7 @@ appCpt = R.hooksComponent "G.C.App.app" cpt where
cpt _ _ = do cpt _ _ = do
sessions <- useSessions sessions <- useSessions
route <- useHashRouter router Home route <- useHashRouter router Home
showLogin <- R.useState' false showLogin <- R.useState' false
showCorpus <- R.useState' false showCorpus <- R.useState' false
......
...@@ -56,7 +56,7 @@ loadedTreeView reload p = R.createElement el p [] ...@@ -56,7 +56,7 @@ loadedTreeView reload p = R.createElement el p []
where where
el = R.hooksComponent "LoadedTreeView" cpt el = R.hooksComponent "LoadedTreeView" cpt
cpt {tree, mCurrentRoute, session, frontends} _ = do cpt {tree, mCurrentRoute, session, frontends} _ = do
treeState <- R.useState' {tree, asyncTasks: [AsyncTask {id: "1hello", status: "pending"}]} treeState <- R.useState' {tree, asyncTasks: []}
pure $ H.div {className: "tree"} pure $ H.div {className: "tree"}
[ toHtml reload treeState session frontends mCurrentRoute ] [ toHtml reload treeState session frontends mCurrentRoute ]
......
module Gargantext.Components.Forest.Tree.Node.Action.Upload where module Gargantext.Components.Forest.Tree.Node.Action.Upload where
import Prelude (class Show, Unit, const, discard, map, pure, show, ($), (<>), bind, void) import Prelude (class Show, Unit, bind, const, discard, map, pure, show, void, ($))
import Data.Maybe (Maybe(..), fromJust) import Data.Maybe (Maybe(..), fromJust)
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
...@@ -12,13 +12,12 @@ import React.SyntheticEvent as E ...@@ -12,13 +12,12 @@ import React.SyntheticEvent as E
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import URI.Extra.QueryPairs as QP import URI.Extra.QueryPairs as QP
import URI.Query as Q
import Web.File.FileReader.Aff (readAsText) import Web.File.FileReader.Aff (readAsText)
import Gargantext.Components.Forest.Tree.Node.Action import Gargantext.Components.Forest.Tree.Node.Action
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, postWwwUrlencoded, postMultipartFormData) import Gargantext.Sessions (Session, postWwwUrlencoded)
import Gargantext.Types (class ToQuery, toQuery, NodeType(..), AsyncTask(..)) import Gargantext.Types (class ToQuery, AsyncTask, NodeType(..))
import Gargantext.Utils (id) import Gargantext.Utils (id)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
......
...@@ -67,7 +67,7 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p [] ...@@ -67,7 +67,7 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
, popOverIcon showBox popupOpen popupPosition , popOverIcon showBox popupOpen popupPosition
, mNodePopupView props showBox popupOpen popupPosition , mNodePopupView props showBox popupOpen popupPosition
, fileTypeView d {id, nodeType} droppedFile isDragOver , fileTypeView d {id, nodeType} droppedFile isDragOver
, H.div {} (map (\t -> asyncProgressBar {corpusId: id, asyncTask: t}) asyncTasks) , H.div {} (map (\t -> asyncProgressBar {asyncTask: t, corpusId: id, session}) asyncTasks)
] ]
where where
SettingsBox {show: showBox} = settingsBox nodeType SettingsBox {show: showBox} = settingsBox nodeType
......
module Gargantext.Components.Forest.Tree.Node.ProgressBar where module Gargantext.Components.Forest.Tree.Node.ProgressBar where
import Gargantext.Prelude
import Data.Int (fromNumber) import Data.Int (fromNumber)
import Data.Maybe (fromJust) import Data.Maybe (Maybe(..), fromJust)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff_)
import Effect.Timer (setTimeout) import Effect.Timer (setTimeout)
import Math (min) import Gargantext.Components.Forest.Tree.Node.Action (ID)
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get)
import Gargantext.Types (AsyncTask(..), NodeType(..))
import Partial.Unsafe (unsafePartial) import Partial.Unsafe (unsafePartial)
import Prelude ((+), ($), (<>), (<<<), pure, bind, discard, unit, show)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Gargantext.Components.Forest.Tree.Node.Action (ID)
import Gargantext.Types (AsyncTask(..))
type Props = type Props =
( (
asyncTask :: AsyncTask asyncTask :: AsyncTask
, corpusId :: ID , corpusId :: ID
, session :: Session
) )
...@@ -27,11 +30,13 @@ asyncProgressBar p = R.createElement asyncProgressBarCpt p [] ...@@ -27,11 +30,13 @@ asyncProgressBar p = R.createElement asyncProgressBarCpt p []
asyncProgressBarCpt :: R.Component Props asyncProgressBarCpt :: R.Component Props
asyncProgressBarCpt = R.hooksComponent "G.C.F.T.N.asyncProgressBar" cpt asyncProgressBarCpt = R.hooksComponent "G.C.F.T.N.asyncProgressBar" cpt
where where
cpt {asyncTask: (AsyncTask {id}), corpusId} _ = do cpt props@{asyncTask: (AsyncTask {id}), corpusId} _ = do
(progress /\ setProgress) <- R.useState' 0.0 (progress /\ setProgress) <- R.useState' 0.0
R.useEffect' $ do R.useEffect' $ do
_ <- setTimeout 1000 $ do _ <- setTimeout 1000 $ do
launchAff_ $ do
queryProgress props
setProgress \p -> min 100.0 (p + 10.0) setProgress \p -> min 100.0 (p + 10.0)
pure unit pure unit
...@@ -46,3 +51,8 @@ asyncProgressBarCpt = R.hooksComponent "G.C.F.T.N.asyncProgressBar" cpt ...@@ -46,3 +51,8 @@ asyncProgressBarCpt = R.hooksComponent "G.C.F.T.N.asyncProgressBar" cpt
toInt :: Number -> Int toInt :: Number -> Int
toInt n = unsafePartial $ fromJust $ fromNumber n toInt n = unsafePartial $ fromJust $ fromNumber n
queryProgress :: Record Props -> Aff Unit
queryProgress {asyncTask: AsyncTask {id}, corpusId, session} = get session p
where
p = NodeAPI Corpus (Just corpusId) $ "add/form/async/" <> id <> "/poll"
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