Task.purs 932 Bytes
Newer Older
1 2 3 4 5 6 7 8
module Gargantext.Components.Forest.Tree.Node.Tools.Task
  where

import Data.Array as A
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
9 10
import Reactix as R

11 12 13 14 15 16 17 18 19 20 21 22 23
import Gargantext.AsyncTasks as GAT
import Gargantext.Prelude (Unit, discard, identity, ($), (+))
import Gargantext.Types (Reload)
import Gargantext.Types as GT


type Tasks =
  ( onTaskAdd    :: GT.AsyncTaskWithType -> Effect Unit
  , onTaskFinish :: GT.AsyncTaskWithType -> Effect Unit
  , tasks        :: Array GT.AsyncTaskWithType
  )

tasksStruct :: Int
24
            -> GAT.Reductor
25 26
            -> R.State Reload
            -> Record Tasks
27
tasksStruct id ({ storage } /\ dispatch) (_ /\ setReload) =
28 29
  { onTaskAdd, onTaskFinish, tasks }
    where
30
      tasks = maybe [] identity $ Map.lookup id storage
31

32
      onTaskAdd t = dispatch $ GAT.Insert id t
33

34
      onTaskFinish t = dispatch $ GAT.Remove id t