Hook in search into the update loop

- new SearchType module to prevent cyclical imports
- Can't currently decode search results with the CatalogPost type, need
  to update the database search function
This commit is contained in:
towards-a-new-leftypol 2024-03-01 18:29:12 -05:00
parent cd72af095e
commit b42510f72c
4 changed files with 32 additions and 23 deletions

View File

@ -86,6 +86,7 @@ executable chandlr
Parsing.PostPartType Parsing.PostPartType
Component.TimeControl Component.TimeControl
Component.Search Component.Search
Component.Search.SearchTypes
-- LANGUAGE extensions used by modules in this package. -- LANGUAGE extensions used by modules in this package.

View File

@ -15,7 +15,7 @@ import Network.Http (HttpResult)
import Network.SiteType (Site) import Network.SiteType (Site)
import qualified Component.ThreadView as Thread import qualified Component.ThreadView as Thread
import qualified Component.TimeControl as TC import qualified Component.TimeControl as TC
import qualified Component.Search as Search import qualified Component.Search.SearchTypes as Search
data GetThreadArgs = GetThreadArgs data GetThreadArgs = GetThreadArgs
{ website :: Text { website :: Text

View File

@ -26,27 +26,10 @@ import Miso
, consoleLog , consoleLog
, noEff , noEff
) )
import Data.JSString (JSString, pack) import Data.JSString (pack)
import qualified Network.ClientTypes as Client import qualified Network.Client as Client
import Network.CatalogPostType (CatalogPost)
import Network.Http (HttpResult (..)) import Network.Http (HttpResult (..))
import Component.Search.SearchTypes
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 ]
}
update :: Interface a -> Action -> Model -> Effect a Model update :: Interface a -> Action -> Model -> Effect a Model
update iface (SearchChange q) model = model { searchTerm = q } <# do 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 return $ (passAction iface) NoAction
update iface OnSubmit model = model <# do update iface OnSubmit model = model <# do
consoleLog $ "Submit!" <> searchTerm model consoleLog $ "Submit! " <> searchTerm model
return $ (passAction iface) NoAction Client.search (clientModel model) (searchTerm model) (clientIface iface)
update iface (SearchResult result) model = model <# do update iface (SearchResult result) model = model <# do
consoleLog $ "Search result" consoleLog $ "Search result"

View File

@ -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 ]
}