Commit 02e4f5f2 authored by Abinaya Sudhir's avatar Abinaya Sudhir

Debugging data loading

parent 1886255b
...@@ -27,7 +27,7 @@ import Prelude hiding (div) ...@@ -27,7 +27,7 @@ import Prelude hiding (div)
import React (ReactElement) import React (ReactElement)
import React as R import React as R
import React.DOM (a, b, b', br', div, dt, input, option, select, span, table, tbody, td, text, thead, tr) import React.DOM (a, b, b', br', div, dt, input, option, select, span, table, tbody, td, text, thead, tr)
import React.DOM.Props (_type, href, onChange, onClick, selected, value) import React.DOM.Props (_type, className, href, onChange, onClick, selected, value)
import ReactDOM as RDOM import ReactDOM as RDOM
import Thermite (PerformAction, Render, Spec, cotransform, createReactSpec, defaultPerformAction, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, cotransform, createReactSpec, defaultPerformAction, modifyState, simpleSpec)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
...@@ -91,7 +91,7 @@ instance decodeResponse :: DecodeJson Response where ...@@ -91,7 +91,7 @@ instance decodeResponse :: DecodeJson Response where
favorite <- obj .? "favorite" favorite <- obj .? "favorite"
ngramCount <- obj .? "ngramCount" ngramCount <- obj .? "ngramCount"
hyperdata <- obj .? "hyperdata" hyperdata <- obj .? "hyperdata"
pure $ Response { cid,created,favorite,ngramCount,hyperdata } pure $ Response { cid, created, favorite, ngramCount, hyperdata }
spec :: Spec _ State _ Action spec :: Spec _ State _ Action
...@@ -99,8 +99,13 @@ spec = simpleSpec performAction render ...@@ -99,8 +99,13 @@ spec = simpleSpec performAction render
where where
render :: Render State _ Action render :: Render State _ Action
render dispatch _ state@(TableData d) _ = render dispatch _ state@(TableData d) _ =
[ div [] [ div [className "container"]
[ div [] [b [] [text d.title]] [
div [className "jumbotron"]
[
div [className "row"]
[
div [] [b [] [text d.title]]
, div [] [ text "Search " , div [] [ text "Search "
, input [] [] , input [] []
] ]
...@@ -125,17 +130,47 @@ spec = simpleSpec performAction render ...@@ -125,17 +130,47 @@ spec = simpleSpec performAction render
] ]
] ]
] ]
]
]
performAction :: PerformAction _ State _ Action performAction :: PerformAction _ State _ Action
performAction (ChangePageSize ps) _ _ = void (cotransform (\state -> changePageSize ps state )) performAction (ChangePageSize ps) _ _ = void (cotransform (\state -> changePageSize ps state ))
performAction (ChangePage p) _ _ = void (cotransform (\(TableData td) -> TableData $ td { currentPage = p} )) performAction (ChangePage p) _ _ = void (cotransform (\(TableData td) -> TableData $ td { currentPage = p} ))
performAction _ _ _ = void (cotransform id)
performAction LoadData _ _ = void do performAction LoadData _ _ = void do
res <- lift $ loadData res <- lift $ loadData
case res of case res of
Left err -> cotransform $ \(state) -> state Left err -> cotransform $ \(state) -> state
Right resData -> do Right resData -> do
cotransform id -- \(state) -> state {response = resData} modifyState (\s -> tdata' $ data' (res2corpus <$> resData))
where
res2corpus (Response res) =
Corpus { _id : res.cid
, url : ""
, date : res.created
, title : (\(Hyperdata r) -> r.title) res.hyperdata
, source : (\(Hyperdata r) -> r.abstract)res.hyperdata
, fav : res.favorite
}
-- Corpus {_id : 1, url : "", date : "date", title : "title", source : "source", fav : false}
-- newtype Response = Response
-- { cid :: Int
-- , created :: String
-- , favorite :: Boolean
-- , ngramCount :: Int
-- , hyperdata :: Hyperdata
-- }
-- newtype Hyperdata = Hyperdata
-- {
-- title :: String
-- , abstract :: String
-- }
...@@ -286,6 +321,7 @@ newtype Corpus ...@@ -286,6 +321,7 @@ newtype Corpus
, source :: String , source :: String
, fav :: Boolean , fav :: Boolean
} }
type CorpusTableData = TableData Corpus type CorpusTableData = TableData Corpus
sampleData' :: Corpus sampleData' :: Corpus
...@@ -310,6 +346,15 @@ tdata = TableData ...@@ -310,6 +346,15 @@ tdata = TableData
, title : "Publications by title" , title : "Publications by title"
} }
tdata' d = TableData
{ rows : d
, totalPages : 10
, currentPage : 1
, pageSize : PS10
, totalRecords : 100
, title : "Publications by title"
}
showRow :: {row :: Corpus, delete :: Boolean} -> ReactElement showRow :: {row :: Corpus, delete :: Boolean} -> ReactElement
showRow {row : (Corpus c), delete} = showRow {row : (Corpus c), delete} =
...@@ -324,7 +369,7 @@ showRow {row : (Corpus c), delete} = ...@@ -324,7 +369,7 @@ showRow {row : (Corpus c), delete} =
loadData :: forall eff. Aff ( console :: CONSOLE, ajax :: AJAX| eff) (Either String Response) loadData :: forall eff. Aff ( console :: CONSOLE, ajax :: AJAX| eff) (Either String (Array Response))
loadData = do loadData = do
-- liftEff $ log $ "GET /api response: " -- liftEff $ log $ "GET /api response: "
affResp <- liftAff $ attempt $ affjax defaultRequest affResp <- liftAff $ attempt $ affjax defaultRequest
......
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