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

import Data.Maybe (Maybe)
import Effect (Effect)
import Effect.Aff (Aff, launchAff)
6 7 8 9 10 11
import Effect.Class (liftEffect)
import Reactix as R
import Reactix.DOM.HTML as H

import Gargantext.Prelude

Alexandre Delanoë's avatar
Alexandre Delanoë committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Add (NodePopup)
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchBar (searchBar)
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField (defaultSearch)
import Gargantext.Components.Lang (allLangs)
import Gargantext.Sessions (Session)
import Gargantext.Types (ID)
import Gargantext.Types as GT


-- | Action : Search
actionSearch :: Session
            -> Maybe ID
            -> (Action -> Aff Unit)
            -> Maybe NodePopup
            -> R.Hooks R.Element
actionSearch session id dispatch nodePopup = do
29
  search <- R.useState' $ defaultSearch { node_id = id }
30
  pure $ R.fragment [ H.p { className: "action-search" }
Alexandre Delanoë's avatar
Alexandre Delanoë committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
                          [ H.text $ "Search and create a private "
                                  <> "corpus with the search query as corpus name." ]
                    , searchBar { langs: allLangs
                                , onSearch: searchOn dispatch nodePopup
                                , search
                                , session
                                }
                    ]
    where
      searchOn :: (Action -> Aff Unit)
               -> Maybe NodePopup
               -> GT.AsyncTaskWithType
               -> Effect Unit
      searchOn dispatch' p task = do
        _ <- launchAff $ dispatch' (DoSearch task)
        -- close popup
47
        _ <- launchAff $ dispatch' ClosePopover
Alexandre Delanoë's avatar
Alexandre Delanoë committed
48 49 50
        -- TODO
        --snd p $ const Nothing
        pure unit