Commit c5c809f0 authored by Abinaya Sudhir's avatar Abinaya Sudhir

Search Page completed

parent e43bf542
......@@ -63,7 +63,7 @@ performAction (SetPassword pwd) _ _ = void do
performAction Login _ (State state) = void do
lift $ setHash "/addCorpus"
lift $ setHash "/search"
modifyState id
-- res <- lift $ loginReq $ LoginReq { username : state.username, password : state.password }
-- case res of
......
......@@ -20,7 +20,7 @@ import React.DOM (a, div, i, img, li, span, text, ul)
import React.DOM.Props (_data, _id, aria, className, href, role, src, style, tabIndex, target, title)
import Thermite (PerformAction, Render, Spec, _render, defaultRender, focus, modifyState, simpleSpec, withState)
import DocView as DV
import SearchForm as S
type E e = (dom :: DOM, ajax :: AJAX, console :: CONSOLE | e)
......@@ -30,6 +30,7 @@ type AppState =
, loginState :: LN.State
, addCorpusState :: AC.State
, docViewState :: DV.State
, searchState :: S.State
}
initAppState :: AppState
......@@ -39,6 +40,7 @@ initAppState =
, loginState : LN.initialState
, addCorpusState : AC.initialState
, docViewState : DV.tdata
, searchState : S.initialState
}
......@@ -49,6 +51,7 @@ data Action
| SetRoute Routes
| AddCorpusA AC.Action
| DocViewA DV.Action
| SearchA S.Action
performAction :: forall eff props. PerformAction (dom :: DOM |eff) AppState props Action
......@@ -108,6 +111,17 @@ _docViewAction = prism DocViewA \action ->
_-> Left action
_searchState:: Lens' AppState S.State
_searchState = lens (\s -> s.searchState) (\s ss -> s{searchState = ss})
_searchAction :: Prism' Action S.Action
_searchAction = prism SearchA \action ->
case action of
SearchA caction -> Right caction
_-> Left action
pagesComponent :: forall props eff. AppState -> Spec (E eff) AppState props Action
pagesComponent s =
......@@ -122,6 +136,7 @@ pagesComponent s =
selectSpec Login = focus _loginState _loginAction LN.renderSpec
selectSpec AddCorpus = wrap $ focus _addCorpusState _addCorpusAction AC.addcorpusviewSpec
selectSpec DocView = wrap $ focus _docViewState _docViewAction DV.spec
selectSpec SearchView = wrap $ focus _searchState _searchAction S.searchSpec
routingSpec :: forall props eff. Spec (dom :: DOM |eff) AppState props Action
routingSpec = simpleSpec performAction defaultRender
......@@ -263,3 +278,9 @@ dispatchAction dispatcher _ DocView = do
_ <- dispatcher $ SetRoute $ DocView
_ <- dispatcher $ DocViewA $ DV.LoadData
pure unit
dispatchAction dispatcher _ SearchView = do
_ <- dispatcher $ SetRoute $ SearchView
_ <- dispatcher $ SearchA $ S.NoOp
pure unit
module PageRouter where
import Prelude
import Control.Alt ((<|>))
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
......@@ -19,12 +20,14 @@ data Routes
| Login
| AddCorpus
| DocView
| SearchView
instance showRoutes :: Show Routes where
show Home = "Home"
show Login = "Login"
show AddCorpus = "AddCorpus"
show DocView = "DocView"
show SearchView = "SearchView"
int :: Match Int
int = floor <$> num
......@@ -32,10 +35,12 @@ int = floor <$> num
routing :: Match Routes
routing =
loginRoute
<|> searchRoute
<|> docviewRoute
<|> addcorpusRoute
<|> home
where
searchRoute = SearchView <$ route "search"
docviewRoute = DocView <$ route "docView"
addcorpusRoute = AddCorpus <$ route "addCorpus"
loginRoute = Login <$ route "login"
......
module SearchForm where
import Control.Monad.Aff.Console (CONSOLE)
import Control.Monad.Cont.Trans (lift)
import DOM (DOM)
import Network.HTTP.Affjax (AJAX)
import Prelude hiding (div)
import React.DOM (br', button, div, h3, input, text)
import React.DOM.Props (_id, _type, className, name, onClick, onInput, placeholder, value)
import Routing.Hash.Aff (setHash)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Unsafe.Coerce (unsafeCoerce)
type State =
{
query :: String
}
initialState :: State
initialState =
{
query : ""
}
data Action
= NoOp
| GO
| SetQuery String
performAction :: forall eff props. PerformAction (console :: CONSOLE, ajax :: AJAX,dom::DOM | eff) State props Action
performAction NoOp _ _ = void do
modifyState id
performAction (SetQuery q) _ _ = void do
modifyState \( state) -> state { query = q }
performAction GO _ _ = void do
lift $ setHash "/addCorpus"
modifyState id
unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
searchSpec :: forall props eff . Spec (console::CONSOLE, ajax::AJAX, dom::DOM | eff) State props Action
searchSpec = simpleSpec performAction render
where
render :: Render State props Action
render dispatch _ state _ =
[
div [className "container"]
[
div [className "jumbotron"]
[
div [className "row"]
[
div [className "col-md-3"]
[ h3 [] [text "Treeview"]
]
, div [className "col-md-9"]
[ br' []
, br' []
, div [className "form-group"]
[
input [className "form-control",
_id "id_password",
name "query",
placeholder "Enter Query",
_type "text",
value state.query,
onInput \e -> dispatch (SetQuery (unsafeEventValue e))
] []
, br'[]
, button [onClick \_ -> dispatch GO] [text "GO"]
]
]
]
]
]
]
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