diff --git a/chandlr.cabal b/chandlr.cabal index 7538801..6ba0acb 100644 --- a/chandlr.cabal +++ b/chandlr.cabal @@ -86,6 +86,7 @@ executable chandlr Parsing.PostPartType Component.TimeControl Component.Search + Component.Search.SearchTypes -- LANGUAGE extensions used by modules in this package. diff --git a/src/Action.hs b/src/Action.hs index 1d9fb42..36b9d81 100644 --- a/src/Action.hs +++ b/src/Action.hs @@ -15,7 +15,7 @@ import Network.Http (HttpResult) import Network.SiteType (Site) import qualified Component.ThreadView as Thread import qualified Component.TimeControl as TC -import qualified Component.Search as Search +import qualified Component.Search.SearchTypes as Search data GetThreadArgs = GetThreadArgs { website :: Text diff --git a/src/Component/Search.hs b/src/Component/Search.hs index dfde953..224ac8e 100644 --- a/src/Component/Search.hs +++ b/src/Component/Search.hs @@ -26,27 +26,10 @@ import Miso , consoleLog , noEff ) -import Data.JSString (JSString, pack) -import qualified Network.ClientTypes as Client -import Network.CatalogPostType (CatalogPost) +import Data.JSString (pack) +import qualified Network.Client as Client import Network.Http (HttpResult (..)) - -data Action - = SearchChange JSString - | OnSubmit - | SearchResult (HttpResult [ CatalogPost ]) - | NoAction - -data Model = Model - { searchTerm :: JSString - , clientModel :: Client.Model - } deriving Eq - -data Interface a = Interface - { passAction :: Action -> a - , clientIface :: Client.Interface a [ CatalogPost ] - } - +import Component.Search.SearchTypes update :: Interface a -> Action -> Model -> Effect a Model update iface (SearchChange q) model = model { searchTerm = q } <# do @@ -54,8 +37,8 @@ update iface (SearchChange q) model = model { searchTerm = q } <# do return $ (passAction iface) NoAction update iface OnSubmit model = model <# do - consoleLog $ "Submit!" <> searchTerm model - return $ (passAction iface) NoAction + consoleLog $ "Submit! " <> searchTerm model + Client.search (clientModel model) (searchTerm model) (clientIface iface) update iface (SearchResult result) model = model <# do consoleLog $ "Search result" diff --git a/src/Component/Search/SearchTypes.hs b/src/Component/Search/SearchTypes.hs new file mode 100644 index 0000000..adf342f --- /dev/null +++ b/src/Component/Search/SearchTypes.hs @@ -0,0 +1,25 @@ +module Component.Search.SearchTypes where + +import Data.JSString (JSString) +import Network.Http (HttpResult (..)) + +import qualified Network.ClientTypes as Client +import Network.CatalogPostType (CatalogPost) + +data Action + = SearchChange JSString + | OnSubmit + | SearchResult (HttpResult [ CatalogPost ]) + | NoAction + +data Model = Model + { searchTerm :: JSString + , clientModel :: Client.Model + } deriving Eq + +data Interface a = Interface + { passAction :: Action -> a + , clientIface :: Client.Interface a [ CatalogPost ] + } + +