diff --git a/spago.dhall b/spago.dhall index adaa426..8e6ed97 100644 --- a/spago.dhall +++ b/spago.dhall @@ -26,6 +26,7 @@ to generate this file without the comments in this block. , "halogen" , "js-date" , "maybe" + , "now" , "prelude" , "undefined" , "web-dom" diff --git a/src/Main.purs b/src/Main.purs index df266d4..2c1dfb7 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -6,6 +6,7 @@ import Data.Maybe (Maybe(..)) import Effect (Effect) import Effect.Aff (Aff, launchAff) import Effect.Console (log) +import Effect.Now (nowDateTime) import Halogen ( HalogenM , ComponentHTML @@ -102,7 +103,8 @@ main = do Just pgroot -> do let settings = { postgrest_api_root: pgroot } log $ show settings - _ <- launchAff $ Client.searchPosts settings "TRUE CHRISTIAN" + now <- nowDateTime + _ <- launchAff $ Client.fetchCatalog settings now 1001 run where diff --git a/src/Network/Client.purs b/src/Network/Client.purs index ec2db99..dffc114 100644 --- a/src/Network/Client.purs +++ b/src/Network/Client.purs @@ -1,8 +1,7 @@ module Network.Client ( SearchResultJSON - , SearchResult , searchPosts - , fetch_catalog + , fetchCatalog ) where @@ -28,7 +27,7 @@ import Data.Traversable (for) import Effect (Effect) import Effect.Aff (Aff) import Halogen (liftEffect) -import Types (Settings) +import Types (Settings, SearchResult) import Undefined (undefined) import Web.HTML (window) import Web.HTML.Window (alert) @@ -44,17 +43,6 @@ type SearchResultJSON = , thread_id :: Number } -type SearchResult = - { post_id :: Number - , board_post_id :: Number - , creation_time :: DateTime - , body :: Maybe String - , subject :: Maybe String - , name :: String - , email :: Maybe String - , thread_id :: Number - } - type CatalogResultJSON = { post_count :: Number , estimated_post_count :: Number @@ -63,7 +51,7 @@ type CatalogResultJSON = , creation_time :: String , bump_time :: String , body :: String - , subject :: String + , subject :: Maybe String , thread_id :: Number , board_thread_id :: Number , pathpart :: String @@ -75,6 +63,7 @@ type CatalogResultJSON = id :: forall a. a -> a id x = x +-- | Check if HTTP status code is in the OK range. ok :: Int -> Boolean ok = between 200 299 @@ -82,6 +71,7 @@ ok = between 200 299 status :: forall a. Response a -> Int status = (\(StatusCode c) -> c) <<< _.status + searchResultFromJson :: SearchResultJSON -> Effect SearchResult searchResultFromJson j = do date <- getDate j.creation_time @@ -155,8 +145,8 @@ searchPosts settings search_query = do payload = encodeJson { search_text: search_query } -fetch_catalog :: Settings -> DateTime -> Int -> Aff (Maybe (Array CatalogResultJSON)) -fetch_catalog settings max_time rows_to_read = do +fetchCatalog :: Settings -> DateTime -> Int -> Aff (Maybe (Array CatalogResultJSON)) +fetchCatalog settings max_time rows_to_read = do max_time_iso_str <- liftEffect $ (toISOString <<< fromDateTime) max_time post_ settings "/rpc/fetch_catalog" (payload max_time_iso_str) diff --git a/src/Types.purs b/src/Types.purs index e3dc0da..1b618f0 100644 --- a/src/Types.purs +++ b/src/Types.purs @@ -1,8 +1,22 @@ module Types ( Settings + , SearchResult ) where +import Data.DateTime (DateTime) +import Data.Maybe (Maybe) type Settings = { postgrest_api_root :: String } +type SearchResult = + { post_id :: Number + , board_post_id :: Number + , creation_time :: DateTime + , body :: Maybe String + , subject :: Maybe String + , name :: String + , email :: Maybe String + , thread_id :: Number + } +