Add search results top-level action type, not used

- it's not yet handled
- it's not yet emitted
This commit is contained in:
towards-a-new-leftypol 2024-03-01 20:05:37 -05:00
parent b42510f72c
commit cd01e255b3
4 changed files with 42 additions and 25 deletions

View File

@ -34,4 +34,5 @@ data Action
| SearchAction Search.Action
| GoToTime UTCTime
| ChangeURI URI
| SearchResults [ CatalogPost ]
| NoAction

View File

@ -41,14 +41,20 @@ update iface OnSubmit model = model <# do
Client.search (clientModel model) (searchTerm model) (clientIface iface)
update iface (SearchResult result) model = model <# do
consoleLog $ "Search result"
consoleLog $ "Received search results!"
case result of
Error -> consoleLog $ "Error!"
Error -> do
consoleLog $ "Error!"
return $ (passAction iface) NoAction
HttpResponse {..} -> do
consoleLog $ (pack $ show $ status_code) <> " " <> (pack $ status_text)
consoleLog $ (pack $ show $ body)
return $ (passAction iface) NoAction
case body of
Just b -> return $ (searchResults iface) b
Nothing -> return $ (searchResults iface) []
update _ NoAction m = noEff m

View File

@ -10,6 +10,7 @@ data Action
= SearchChange JSString
| OnSubmit
| SearchResult (HttpResult [ CatalogPost ])
| DisplayResults [ CatalogPost ]
| NoAction
data Model = Model
@ -20,6 +21,5 @@ data Model = Model
data Interface a = Interface
{ passAction :: Action -> a
, clientIface :: Client.Interface a [ CatalogPost ]
, searchResults :: [ CatalogPost ] -> a
}

View File

@ -62,6 +62,15 @@ data Model = Model
, current_time :: UTCTime
, tc_model :: TC.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
@ -221,8 +230,6 @@ mainUpdate (HaveThread (Client.HttpResponse {..})) m = new_model <# do
mainUpdate (GoToTime t) m = m { current_time = t } <# do
Client.fetchLatest (client_model m) t (iClient HaveLatest)
-- mainUpdate GetThread {..} m = noEff m
mainUpdate (GetThread GetThreadArgs {..}) m = m <# do
consoleLog $ "Thread " `append` (pack $ show $ board_thread_id)
pushURI new_current_uri
@ -263,6 +270,8 @@ mainUpdate (SearchAction sa) m =
Search.update iSearch sa (search_model m)
>>= \sm -> noEff m { search_model = sm }
-- mainUpdate (SearchResults result_posts) m = -- TODO
iGrid :: Grid.Interface Action
iGrid = Grid.Interface
{ Grid.passAction = GridAction
@ -297,4 +306,5 @@ iSearch =
Search.Interface
{ passAction = SearchAction
, clientIface = iClient (SearchAction . Search.SearchResult)
, searchResults = SearchResults
}