Add search results top-level action type, not used
- it's not yet handled - it's not yet emitted
This commit is contained in:
parent
b42510f72c
commit
cd01e255b3
|
@ -34,4 +34,5 @@ data Action
|
||||||
| SearchAction Search.Action
|
| SearchAction Search.Action
|
||||||
| GoToTime UTCTime
|
| GoToTime UTCTime
|
||||||
| ChangeURI URI
|
| ChangeURI URI
|
||||||
|
| SearchResults [ CatalogPost ]
|
||||||
| NoAction
|
| NoAction
|
||||||
|
|
|
@ -33,22 +33,28 @@ import Component.Search.SearchTypes
|
||||||
|
|
||||||
update :: Interface a -> Action -> Model -> Effect a Model
|
update :: Interface a -> Action -> Model -> Effect a Model
|
||||||
update iface (SearchChange q) model = model { searchTerm = q } <# do
|
update iface (SearchChange q) model = model { searchTerm = q } <# do
|
||||||
consoleLog q
|
consoleLog q
|
||||||
return $ (passAction iface) NoAction
|
return $ (passAction iface) NoAction
|
||||||
|
|
||||||
update iface OnSubmit model = model <# do
|
update iface OnSubmit model = model <# do
|
||||||
consoleLog $ "Submit! " <> searchTerm model
|
consoleLog $ "Submit! " <> searchTerm model
|
||||||
Client.search (clientModel model) (searchTerm model) (clientIface iface)
|
Client.search (clientModel model) (searchTerm model) (clientIface iface)
|
||||||
|
|
||||||
update iface (SearchResult result) model = model <# do
|
update iface (SearchResult result) model = model <# do
|
||||||
consoleLog $ "Search result"
|
consoleLog $ "Received search results!"
|
||||||
case result of
|
|
||||||
Error -> consoleLog $ "Error!"
|
|
||||||
HttpResponse {..} -> do
|
|
||||||
consoleLog $ (pack $ show $ status_code) <> " " <> (pack $ status_text)
|
|
||||||
consoleLog $ (pack $ show $ body)
|
|
||||||
|
|
||||||
return $ (passAction iface) NoAction
|
case result of
|
||||||
|
Error -> do
|
||||||
|
consoleLog $ "Error!"
|
||||||
|
return $ (passAction iface) NoAction
|
||||||
|
|
||||||
|
HttpResponse {..} -> do
|
||||||
|
consoleLog $ (pack $ show $ status_code) <> " " <> (pack $ status_text)
|
||||||
|
consoleLog $ (pack $ show $ body)
|
||||||
|
|
||||||
|
case body of
|
||||||
|
Just b -> return $ (searchResults iface) b
|
||||||
|
Nothing -> return $ (searchResults iface) []
|
||||||
|
|
||||||
update _ NoAction m = noEff m
|
update _ NoAction m = noEff m
|
||||||
|
|
||||||
|
|
|
@ -7,19 +7,19 @@ import qualified Network.ClientTypes as Client
|
||||||
import Network.CatalogPostType (CatalogPost)
|
import Network.CatalogPostType (CatalogPost)
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
= SearchChange JSString
|
= SearchChange JSString
|
||||||
| OnSubmit
|
| OnSubmit
|
||||||
| SearchResult (HttpResult [ CatalogPost ])
|
| SearchResult (HttpResult [ CatalogPost ])
|
||||||
| NoAction
|
| DisplayResults [ CatalogPost ]
|
||||||
|
| NoAction
|
||||||
|
|
||||||
data Model = Model
|
data Model = Model
|
||||||
{ searchTerm :: JSString
|
{ searchTerm :: JSString
|
||||||
, clientModel :: Client.Model
|
, clientModel :: Client.Model
|
||||||
} deriving Eq
|
} deriving Eq
|
||||||
|
|
||||||
data Interface a = Interface
|
data Interface a = Interface
|
||||||
{ passAction :: Action -> a
|
{ passAction :: Action -> a
|
||||||
, clientIface :: Client.Interface a [ CatalogPost ]
|
, clientIface :: Client.Interface a [ CatalogPost ]
|
||||||
}
|
, searchResults :: [ CatalogPost ] -> a
|
||||||
|
}
|
||||||
|
|
||||||
|
|
14
src/Main.hs
14
src/Main.hs
|
@ -62,6 +62,15 @@ data Model = Model
|
||||||
, current_time :: UTCTime
|
, current_time :: UTCTime
|
||||||
, tc_model :: TC.Model
|
, tc_model :: TC.Model
|
||||||
, search_model :: Search.Model
|
, search_model :: Search.Model
|
||||||
|
{-
|
||||||
|
- Goal:
|
||||||
|
- handle search results
|
||||||
|
- - which means displaying them in a catalog
|
||||||
|
- - which means having STATE that says we should be displaying
|
||||||
|
- search results.
|
||||||
|
- - so we need the results somewhere
|
||||||
|
- - also need to change the url to show results
|
||||||
|
-}
|
||||||
} deriving Eq
|
} deriving Eq
|
||||||
|
|
||||||
|
|
||||||
|
@ -221,8 +230,6 @@ mainUpdate (HaveThread (Client.HttpResponse {..})) m = new_model <# do
|
||||||
mainUpdate (GoToTime t) m = m { current_time = t } <# do
|
mainUpdate (GoToTime t) m = m { current_time = t } <# do
|
||||||
Client.fetchLatest (client_model m) t (iClient HaveLatest)
|
Client.fetchLatest (client_model m) t (iClient HaveLatest)
|
||||||
|
|
||||||
-- mainUpdate GetThread {..} m = noEff m
|
|
||||||
|
|
||||||
mainUpdate (GetThread GetThreadArgs {..}) m = m <# do
|
mainUpdate (GetThread GetThreadArgs {..}) m = m <# do
|
||||||
consoleLog $ "Thread " `append` (pack $ show $ board_thread_id)
|
consoleLog $ "Thread " `append` (pack $ show $ board_thread_id)
|
||||||
pushURI new_current_uri
|
pushURI new_current_uri
|
||||||
|
@ -263,6 +270,8 @@ mainUpdate (SearchAction sa) m =
|
||||||
Search.update iSearch sa (search_model m)
|
Search.update iSearch sa (search_model m)
|
||||||
>>= \sm -> noEff m { search_model = sm }
|
>>= \sm -> noEff m { search_model = sm }
|
||||||
|
|
||||||
|
-- mainUpdate (SearchResults result_posts) m = -- TODO
|
||||||
|
|
||||||
iGrid :: Grid.Interface Action
|
iGrid :: Grid.Interface Action
|
||||||
iGrid = Grid.Interface
|
iGrid = Grid.Interface
|
||||||
{ Grid.passAction = GridAction
|
{ Grid.passAction = GridAction
|
||||||
|
@ -297,4 +306,5 @@ iSearch =
|
||||||
Search.Interface
|
Search.Interface
|
||||||
{ passAction = SearchAction
|
{ passAction = SearchAction
|
||||||
, clientIface = iClient (SearchAction . Search.SearchResult)
|
, clientIface = iClient (SearchAction . Search.SearchResult)
|
||||||
|
, searchResults = SearchResults
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue