Change url to search query

This commit is contained in:
towards-a-new-leftypol 2024-03-01 21:12:39 -05:00
parent 24640dda7f
commit 6d17cefabe
4 changed files with 16 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import Data.Text (Text)
import Data.Aeson (FromJSON) import Data.Aeson (FromJSON)
import Data.Int (Int64) import Data.Int (Int64)
import Data.Time.Clock (UTCTime) import Data.Time.Clock (UTCTime)
import Data.JSString (JSString)
import Miso (URI) import Miso (URI)
import qualified Component.CatalogGrid as Grid import qualified Component.CatalogGrid as Grid
@ -34,5 +35,5 @@ data Action
| SearchAction Search.Action | SearchAction Search.Action
| GoToTime UTCTime | GoToTime UTCTime
| ChangeURI URI | ChangeURI URI
| SearchResults | SearchResults JSString
| NoAction | NoAction

View File

@ -58,7 +58,7 @@ update iface (SearchResult result) model = model <# do
Nothing -> return $ passAction iface $ PassPostsToSelf [] Nothing -> return $ passAction iface $ PassPostsToSelf []
update iface (PassPostsToSelf search_results) model = model { displayResults = search_results } <# update iface (PassPostsToSelf search_results) model = model { displayResults = search_results } <#
return (searchResults iface) (return $ (searchResults iface) (searchTerm model))
update _ NoAction m = noEff m update _ NoAction m = noEff m

View File

@ -22,5 +22,5 @@ data Model = Model
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 :: a , searchResults :: JSString -> a
} }

View File

@ -9,12 +9,12 @@ import Data.Proxy
import Data.Maybe (maybe, fromJust) import Data.Maybe (maybe, fromJust)
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import Network.URI (uriPath) import Network.URI (uriPath, uriQuery, escapeURIString, isAllowedInURI)
import System.FilePath ((</>)) import System.FilePath ((</>))
import Data.Time.Clock (UTCTime, getCurrentTime) import Data.Time.Clock (UTCTime, getCurrentTime)
import Data.Aeson (FromJSON) import Data.Aeson (FromJSON)
import Data.JSString (pack, append) import Data.JSString (pack, append, unpack)
import Miso import Miso
( View ( View
, startApp , startApp
@ -271,7 +271,16 @@ 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 mainUpdate (SearchResults query) m = m { current_uri = new_current_uri } <# do
pushURI new_current_uri
return NoAction
where
new_current_uri :: URI
new_current_uri = (current_uri m)
{ uriPath = "/search"
, uriQuery = "?search=" ++ (escapeURIString isAllowedInURI $ unpack query)
}
iGrid :: Grid.Interface Action iGrid :: Grid.Interface Action
iGrid = Grid.Interface iGrid = Grid.Interface