Refactor a tiny bit

This commit is contained in:
towards-a-new-leftypol 2023-11-15 16:48:43 -05:00
parent 2ac0d249b1
commit 7a09471bd7
4 changed files with 25 additions and 18 deletions

View File

@ -26,6 +26,7 @@ to generate this file without the comments in this block.
, "halogen"
, "js-date"
, "maybe"
, "now"
, "prelude"
, "undefined"
, "web-dom"

View File

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

View File

@ -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)

View File

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