Search.purs 2.03 KB
Newer Older
1
module Gargantext.Pages.Layout.Specs.Search where
Abinaya Sudhir's avatar
Abinaya Sudhir committed
2 3

import Prelude hiding (div)
Sudhir Kumar's avatar
Sudhir Kumar committed
4 5 6 7 8

import Effect.Class (liftEffect)
import React.DOM (br', button, div, input, text)
import React.DOM.Props (_id, _type, className, name, onClick, onInput, placeholder, value)
import Routing.Hash (setHash)
Abinaya Sudhir's avatar
Abinaya Sudhir committed
9 10 11 12 13 14 15 16 17 18 19 20
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Unsafe.Coerce (unsafeCoerce)

type State =
  {
    query :: String
  }


initialState :: State
initialState =
  {
21
    query : "empty query"
Abinaya Sudhir's avatar
Abinaya Sudhir committed
22 23 24 25
  }


data Action
Nicolas Pouillard's avatar
Nicolas Pouillard committed
26
  = GO
Abinaya Sudhir's avatar
Abinaya Sudhir committed
27 28 29 30 31
  | SetQuery String


unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
32

33
searchSpec :: Spec State {} Action
Abinaya Sudhir's avatar
Abinaya Sudhir committed
34 35
searchSpec = simpleSpec performAction render
  where
36 37 38 39 40 41 42
    performAction :: PerformAction State {} Action
    performAction (SetQuery q) _ _ = void do
      modifyState $ _ { query = q }

    performAction GO _ _ = void do
      liftEffect $ setHash "/addCorpus"

43
    render :: Render State {} Action
Abinaya Sudhir's avatar
Abinaya Sudhir committed
44
    render dispatch _ state _ =
Abinaya Sudhir's avatar
Abinaya Sudhir committed
45 46
      [ div [className "container1"] []
      , div [className "container1"]
47 48 49
       [ div [className "jumbotron" ]
         [ div [className "row"       ]
           [ div [className "col-md-10" ]
Sudhir Kumar's avatar
Sudhir Kumar committed
50 51
             [ br'
             , br'
Alexandre Delanoë's avatar
Alexandre Delanoë committed
52 53
             , div [ className "form-group"][]
                   {-[ input [ className "form-control"
54 55
                           , _id "id_password"
                           , name "query"
56
                           , placeholder "Query, URL or FILE (works best with Firefox or Chromium browsers)"
57 58 59
                           , _type "text"
                           , value state.query
                           , onInput \e -> dispatch (SetQuery (unsafeEventValue e))
Sudhir Kumar's avatar
Sudhir Kumar committed
60 61
                           ]
                    , br'
62
                    ]
Alexandre Delanoë's avatar
Alexandre Delanoë committed
63
                    -}
64
              ]
65
            , div [ className "col-md-2"]
Sudhir Kumar's avatar
Sudhir Kumar committed
66 67
                  [ br'
                  , br'
68
                  , button [onClick \_ -> dispatch GO] [text "GO"]
69
                  ]
Sudhir Kumar's avatar
Sudhir Kumar committed
70
            , br'
71 72 73
            ]
          ]
        ]
Abinaya Sudhir's avatar
Abinaya Sudhir committed
74
      ]