From 6d17cefabee1a36612053cfbc6f469cf437a1f13 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Fri, 1 Mar 2024 21:12:39 -0500 Subject: [PATCH] Change url to search query --- src/Action.hs | 3 ++- src/Component/Search.hs | 2 +- src/Component/Search/SearchTypes.hs | 2 +- src/Main.hs | 15 ++++++++++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Action.hs b/src/Action.hs index a58b79a..ea59cc4 100644 --- a/src/Action.hs +++ b/src/Action.hs @@ -6,6 +6,7 @@ import Data.Text (Text) import Data.Aeson (FromJSON) import Data.Int (Int64) import Data.Time.Clock (UTCTime) +import Data.JSString (JSString) import Miso (URI) import qualified Component.CatalogGrid as Grid @@ -34,5 +35,5 @@ data Action | SearchAction Search.Action | GoToTime UTCTime | ChangeURI URI - | SearchResults + | SearchResults JSString | NoAction diff --git a/src/Component/Search.hs b/src/Component/Search.hs index 8c08b3c..9db06dd 100644 --- a/src/Component/Search.hs +++ b/src/Component/Search.hs @@ -58,7 +58,7 @@ update iface (SearchResult result) model = model <# do Nothing -> return $ passAction iface $ PassPostsToSelf [] update iface (PassPostsToSelf search_results) model = model { displayResults = search_results } <# - return (searchResults iface) + (return $ (searchResults iface) (searchTerm model)) update _ NoAction m = noEff m diff --git a/src/Component/Search/SearchTypes.hs b/src/Component/Search/SearchTypes.hs index 04b08dd..ace529e 100644 --- a/src/Component/Search/SearchTypes.hs +++ b/src/Component/Search/SearchTypes.hs @@ -22,5 +22,5 @@ data Model = Model data Interface a = Interface { passAction :: Action -> a , clientIface :: Client.Interface a [ CatalogPost ] - , searchResults :: a + , searchResults :: JSString -> a } diff --git a/src/Main.hs b/src/Main.hs index f5e6f3c..11af913 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -9,12 +9,12 @@ import Data.Proxy import Data.Maybe (maybe, fromJust) import Data.Text (Text) import qualified Data.Text as T -import Network.URI (uriPath) +import Network.URI (uriPath, uriQuery, escapeURIString, isAllowedInURI) import System.FilePath (()) import Data.Time.Clock (UTCTime, getCurrentTime) import Data.Aeson (FromJSON) -import Data.JSString (pack, append) +import Data.JSString (pack, append, unpack) import Miso ( View , startApp @@ -271,7 +271,16 @@ mainUpdate (SearchAction sa) m = Search.update iSearch sa (search_model m) >>= \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