Search.purs 1.98 KB
Newer Older
Alexandre Delanoë's avatar
Alexandre Delanoë committed
1 2
module Gargantext.Components.Forest.Tree.Node.Action.Search where

3 4
import Gargantext.Prelude

Alexandre Delanoë's avatar
Alexandre Delanoë committed
5 6 7
import Data.Maybe (Maybe)
import Effect (Effect)
import Effect.Aff (Aff, launchAff)
8
import Gargantext.Components.App.Data (Boxes)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
9 10
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchBar (searchBar)
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField (defaultSearch)
11
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
Alexandre Delanoë's avatar
Alexandre Delanoë committed
12 13
import Gargantext.Components.Lang (allLangs)
import Gargantext.Sessions (Session)
14
import Gargantext.Types (ID)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
15
import Gargantext.Types as GT
16
import Gargantext.Utils.Reactix as R2
17 18 19
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
Alexandre Delanoë's avatar
Alexandre Delanoë committed
20

21 22 23 24 25
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Search"


type Props =
26 27
  ( boxes     :: Boxes
  , dispatch  :: Action -> Aff Unit
28 29
  , id        :: Maybe ID
  , session   :: Session )
Alexandre Delanoë's avatar
Alexandre Delanoë committed
30 31

-- | Action : Search
32 33 34 35 36
actionSearch :: R2.Component Props
actionSearch = R.createElement actionSearchCpt
actionSearchCpt :: R.Component Props
actionSearchCpt = here.component "actionSearch" cpt
  where
37
    cpt { boxes: { errors }, dispatch, id, session } _ = do
38
      search <- T.useBox $ defaultSearch { node_id = id }
39 40 41 42 43 44
      pure $ R.fragment
        [ H.p { className: "action-search" }
          [ H.text $ "Search and create a private "
            <> "corpus with the search query as corpus name." ]
        , searchBar { errors
                    , langs: allLangs
45
                    , onSearch: searchOn dispatch
46 47 48 49
                    , search
                    , session
                    } []
        ]
50 51
        where
          searchOn :: (Action -> Aff Unit)
52 53 54
                   -> GT.AsyncTaskWithType
                   -> Effect Unit
          searchOn dispatch' task = do
55 56 57 58 59 60
            _ <- launchAff $ dispatch' (DoSearch task)
            -- close popup
            _ <- launchAff $ dispatch' ClosePopover
            -- TODO
            --snd p $ const Nothing
            pure unit