Save search results inside the Search component

- still not displaying results
- still need to change url
- fails because mainUpdate doesn't handle search result action (event)
This commit is contained in:
towards-a-new-leftypol 2024-03-01 20:44:30 -05:00
parent cd01e255b3
commit 24640dda7f
4 changed files with 11 additions and 5 deletions

View File

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

View File

@ -25,6 +25,7 @@ import Miso
, (<#)
, consoleLog
, noEff
, batchEff
)
import Data.JSString (pack)
import qualified Network.Client as Client
@ -53,8 +54,11 @@ update iface (SearchResult result) model = model <# do
consoleLog $ (pack $ show $ body)
case body of
Just b -> return $ (searchResults iface) b
Nothing -> return $ (searchResults iface) []
Just catlg_posts -> return $ passAction iface $ PassPostsToSelf catlg_posts
Nothing -> return $ passAction iface $ PassPostsToSelf []
update iface (PassPostsToSelf search_results) model = model { displayResults = search_results } <#
return (searchResults iface)
update _ NoAction m = noEff m

View File

@ -10,16 +10,17 @@ data Action
= SearchChange JSString
| OnSubmit
| SearchResult (HttpResult [ CatalogPost ])
| DisplayResults [ CatalogPost ]
| PassPostsToSelf [ CatalogPost ] -- I think I don't understand something about the update type but I had to add this...
| NoAction
data Model = Model
{ searchTerm :: JSString
, clientModel :: Client.Model
, displayResults :: [ CatalogPost ]
} deriving Eq
data Interface a = Interface
{ passAction :: Action -> a
, clientIface :: Client.Interface a [ CatalogPost ]
, searchResults :: [ CatalogPost ] -> a
, searchResults :: a
}

View File

@ -106,6 +106,7 @@ initialModel pgroot client_fetch_count media_root u t = Model
, search_model = Search.Model
{ Search.searchTerm = ""
, Search.clientModel = client_model_
, Search.displayResults = []
}
}