Parse thread response, begin rendering thread
This commit is contained in:
parent
37b576b96b
commit
d998067828
|
@ -68,7 +68,12 @@ executable chandlr
|
||||||
Network.Client
|
Network.Client
|
||||||
Network.ClientTypes
|
Network.ClientTypes
|
||||||
Network.CatalogPostType
|
Network.CatalogPostType
|
||||||
|
Network.BoardType
|
||||||
|
Network.SiteType
|
||||||
|
Network.PostType
|
||||||
|
Network.ThreadType
|
||||||
Routes
|
Routes
|
||||||
|
Common.AttachmentType
|
||||||
|
|
||||||
|
|
||||||
-- LANGUAGE extensions used by modules in this package.
|
-- LANGUAGE extensions used by modules in this package.
|
||||||
|
|
|
@ -11,6 +11,7 @@ import qualified Component.CatalogGrid as Grid
|
||||||
import qualified Network.ClientTypes as C
|
import qualified Network.ClientTypes as C
|
||||||
import Network.CatalogPostType (CatalogPost)
|
import Network.CatalogPostType (CatalogPost)
|
||||||
import Network.Http (HttpResult)
|
import Network.Http (HttpResult)
|
||||||
|
import Network.SiteType (Site)
|
||||||
|
|
||||||
data GetThreadArgs = GetThreadArgs
|
data GetThreadArgs = GetThreadArgs
|
||||||
{ website :: Text
|
{ website :: Text
|
||||||
|
@ -22,8 +23,8 @@ data Action
|
||||||
= GridAction Grid.Action
|
= GridAction Grid.Action
|
||||||
| GetLatest
|
| GetLatest
|
||||||
| GetThread GetThreadArgs
|
| GetThread GetThreadArgs
|
||||||
| HaveLatest (HttpResult [CatalogPost])
|
| HaveLatest (HttpResult [ CatalogPost ])
|
||||||
| HaveThread (HttpResult ())
|
| HaveThread (HttpResult [ Site ])
|
||||||
| forall a. (FromJSON a) => ClientAction (HttpResult a -> Action) (C.Action a)
|
| forall a. (FromJSON a) => ClientAction (HttpResult a -> Action) (C.Action a)
|
||||||
| ChangeURI URI
|
| ChangeURI URI
|
||||||
| NoAction
|
| NoAction
|
||||||
|
|
|
@ -41,7 +41,7 @@ data Action
|
||||||
= DisplayItems [ CatalogPost ]
|
= DisplayItems [ CatalogPost ]
|
||||||
|
|
||||||
data Interface a = Interface
|
data Interface a = Interface
|
||||||
{ passAction :: Action -> a
|
{ passAction :: Action -> a -- We're not using this.
|
||||||
, threadSelected :: CatalogPost -> a
|
, threadSelected :: CatalogPost -> a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ update
|
||||||
-> Model
|
-> Model
|
||||||
-> Effect a Model
|
-> Effect a Model
|
||||||
update _ (DisplayItems xs) m = noEff (m { display_items = xs })
|
update _ (DisplayItems xs) m = noEff (m { display_items = xs })
|
||||||
-- update _ _ m = noEff m
|
|
||||||
|
|
||||||
view :: Interface a -> Model -> View a
|
view :: Interface a -> Model -> View a
|
||||||
view iface model =
|
view iface model =
|
||||||
|
|
|
@ -1,11 +1,44 @@
|
||||||
module Component.ThreadView
|
module Component.ThreadView
|
||||||
( Model
|
( Model (..)
|
||||||
|
, initialModel
|
||||||
|
, Action (..)
|
||||||
|
, update
|
||||||
|
, view
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Common.PostsType (Post)
|
import Miso
|
||||||
|
( View
|
||||||
|
, Effect
|
||||||
|
, div_
|
||||||
|
, text
|
||||||
|
, h1_
|
||||||
|
, noEff
|
||||||
|
)
|
||||||
|
import Miso.String (toMisoString)
|
||||||
|
import GHCJS.DOM.Types (JSString)
|
||||||
|
|
||||||
|
import Network.SiteType (Site)
|
||||||
|
import qualified Network.SiteType as Site
|
||||||
|
|
||||||
data Model = Model
|
data Model = Model
|
||||||
{ thread_id :: Integer
|
{ site :: Site
|
||||||
, thread_posts :: [ Post ]
|
, media_root :: JSString
|
||||||
, thread_loading :: Bool
|
|
||||||
} deriving Eq
|
} deriving Eq
|
||||||
|
|
||||||
|
initialModel :: JSString -> Site -> Model
|
||||||
|
initialModel mroot s = Model
|
||||||
|
{ site = s
|
||||||
|
, media_root = mroot
|
||||||
|
}
|
||||||
|
|
||||||
|
data Action = RenderSite Site
|
||||||
|
|
||||||
|
update :: Action -> Model -> Effect a Model
|
||||||
|
update (RenderSite s) m = noEff (m { site = s })
|
||||||
|
|
||||||
|
view :: Model -> View a
|
||||||
|
view m =
|
||||||
|
div_
|
||||||
|
[]
|
||||||
|
[ h1_ [] [ text $ toMisoString $ Site.name $ site m ]
|
||||||
|
]
|
||||||
|
|
42
src/Main.hs
42
src/Main.hs
|
@ -46,14 +46,16 @@ import Routes
|
||||||
import qualified Network.Client as Client
|
import qualified Network.Client as Client
|
||||||
import Network.CatalogPostType (CatalogPost)
|
import Network.CatalogPostType (CatalogPost)
|
||||||
import qualified Network.CatalogPostType as CatalogPost
|
import qualified Network.CatalogPostType as CatalogPost
|
||||||
|
|
||||||
import qualified Component.CatalogGrid as Grid
|
import qualified Component.CatalogGrid as Grid
|
||||||
|
import qualified Component.ThreadView as Thread
|
||||||
|
|
||||||
|
|
||||||
data Model = Model
|
data Model = Model
|
||||||
{ gridModel :: Grid.Model
|
{ grid_model :: Grid.Model
|
||||||
, clientModel :: Client.Model
|
, client_model :: Client.Model
|
||||||
|
, thread_model :: Maybe Thread.Model
|
||||||
, current_uri :: URI
|
, current_uri :: URI
|
||||||
|
, media_root_ :: JSString
|
||||||
} deriving Eq
|
} deriving Eq
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,12 +80,14 @@ initialModel
|
||||||
-> URI
|
-> URI
|
||||||
-> Model
|
-> Model
|
||||||
initialModel pgroot client_fetch_count media_root u = Model
|
initialModel pgroot client_fetch_count media_root u = Model
|
||||||
{ gridModel = Grid.initialModel media_root
|
{ grid_model = Grid.initialModel media_root
|
||||||
, clientModel = Client.Model
|
, client_model = Client.Model
|
||||||
{ Client.pgApiRoot = pgroot
|
{ Client.pgApiRoot = pgroot
|
||||||
, Client.fetchCount = client_fetch_count
|
, Client.fetchCount = client_fetch_count
|
||||||
}
|
}
|
||||||
|
, thread_model = Nothing
|
||||||
, current_uri = u
|
, current_uri = u
|
||||||
|
, media_root_ = media_root
|
||||||
}
|
}
|
||||||
|
|
||||||
getMetadata :: String -> IO (Maybe JSString)
|
getMetadata :: String -> IO (Maybe JSString)
|
||||||
|
@ -142,12 +146,14 @@ mainView model = view
|
||||||
catalog_view :: Model -> View Action
|
catalog_view :: Model -> View Action
|
||||||
catalog_view _ = div_ []
|
catalog_view _ = div_ []
|
||||||
[ h1_ [] [ text "Overboard Catalog" ]
|
[ h1_ [] [ text "Overboard Catalog" ]
|
||||||
, Grid.view iGrid (gridModel model)
|
, Grid.view iGrid (grid_model model)
|
||||||
]
|
]
|
||||||
|
|
||||||
thread_view :: Text -> Text -> BoardThreadId -> Model -> View Action
|
thread_view :: Text -> Text -> BoardThreadId -> Model -> View Action
|
||||||
thread_view site_name board_pathpart board_thread_id m =
|
thread_view site_name board_pathpart board_thread_id m = maybe
|
||||||
h1_ [] [ text "Thread View" ]
|
(h1_ [] [ text "Thread View" ])
|
||||||
|
Thread.view
|
||||||
|
(thread_model m)
|
||||||
|
|
||||||
page404 :: View Action
|
page404 :: View Action
|
||||||
page404 = h1_ [] [ text "404 Not Found" ]
|
page404 = h1_ [] [ text "404 Not Found" ]
|
||||||
|
@ -172,18 +178,24 @@ mainUpdate (HaveThread Client.Error) m = m <# do
|
||||||
consoleLog "Getting Thread failed!"
|
consoleLog "Getting Thread failed!"
|
||||||
return NoAction
|
return NoAction
|
||||||
|
|
||||||
mainUpdate (HaveThread (Client.HttpResponse {..})) m = m <# do
|
mainUpdate (HaveThread (Client.HttpResponse {..})) m = new_model <# do
|
||||||
consoleLog "Have Thread!"
|
consoleLog "Have Thread!"
|
||||||
return NoAction
|
return NoAction
|
||||||
|
|
||||||
mainUpdate GetLatest m = m <# Client.fetchLatest (clientModel m) (iClient HaveLatest)
|
where
|
||||||
|
new_model = m
|
||||||
|
{ thread_model =
|
||||||
|
body >>= Just . (Thread.initialModel (media_root_ m)) . head
|
||||||
|
}
|
||||||
|
|
||||||
|
mainUpdate GetLatest m = m <# Client.fetchLatest (client_model m) (iClient HaveLatest)
|
||||||
|
|
||||||
-- mainUpdate GetThread {..} m = noEff m
|
-- mainUpdate GetThread {..} m = noEff m
|
||||||
|
|
||||||
mainUpdate (GetThread GetThreadArgs {..}) m = m <# do
|
mainUpdate (GetThread GetThreadArgs {..}) m = m <# do
|
||||||
consoleLog $ "Thread " `append` (pack $ show $ board_thread_id)
|
consoleLog $ "Thread " `append` (pack $ show $ board_thread_id)
|
||||||
pushURI new_current_uri
|
pushURI new_current_uri
|
||||||
Client.getThread (clientModel m) (iClient HaveThread) GetThreadArgs {..}
|
Client.getThread (client_model m) (iClient HaveThread) GetThreadArgs {..}
|
||||||
|
|
||||||
where
|
where
|
||||||
new_current_uri :: URI
|
new_current_uri :: URI
|
||||||
|
@ -198,12 +210,12 @@ mainUpdate (ChangeURI old_uri) m = m { current_uri = old_uri } <# do
|
||||||
return NoAction
|
return NoAction
|
||||||
|
|
||||||
mainUpdate (GridAction ga) m =
|
mainUpdate (GridAction ga) m =
|
||||||
Grid.update iGrid ga (gridModel m)
|
Grid.update iGrid ga (grid_model m)
|
||||||
>>= \gm -> noEff (m { gridModel = gm })
|
>>= \gm -> noEff (m { grid_model = gm })
|
||||||
|
|
||||||
mainUpdate (ClientAction action ca) m =
|
mainUpdate (ClientAction action ca) m =
|
||||||
Client.update (iClient action) ca (clientModel m)
|
Client.update (iClient action) ca (client_model m)
|
||||||
>>= \cm -> noEff (m { clientModel = cm })
|
>>= \cm -> noEff (m { client_model = cm })
|
||||||
|
|
||||||
|
|
||||||
iGrid :: Grid.Interface Action
|
iGrid :: Grid.Interface Action
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
|
||||||
|
module Network.BoardType where
|
||||||
|
|
||||||
|
import GHC.Generics
|
||||||
|
import Data.Text (Text)
|
||||||
|
import Data.Aeson (FromJSON, ToJSON)
|
||||||
|
import Network.ThreadType (Thread)
|
||||||
|
|
||||||
|
data Board = Board
|
||||||
|
{ board_id :: Int
|
||||||
|
, name :: Maybe Text
|
||||||
|
, pathpart :: Text
|
||||||
|
, site_id :: Int
|
||||||
|
, threads :: [ Thread ]
|
||||||
|
} deriving (Show, Generic, FromJSON, ToJSON, Eq)
|
||||||
|
|
|
@ -30,6 +30,7 @@ import Miso.String (toMisoString)
|
||||||
|
|
||||||
import qualified Network.Http as Http
|
import qualified Network.Http as Http
|
||||||
import Network.CatalogPostType (CatalogPost)
|
import Network.CatalogPostType (CatalogPost)
|
||||||
|
import Network.SiteType (Site)
|
||||||
import qualified Action as A
|
import qualified Action as A
|
||||||
import Network.ClientTypes
|
import Network.ClientTypes
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ http_
|
||||||
-> Http.HttpMethod
|
-> Http.HttpMethod
|
||||||
-> Maybe c
|
-> Maybe c
|
||||||
-> IO a
|
-> IO a
|
||||||
http_ m iface api_path method payload = do
|
http_ m iface api_path method payload =
|
||||||
Http.http
|
Http.http
|
||||||
(pgApiRoot m <> api_path)
|
(pgApiRoot m <> api_path)
|
||||||
method
|
method
|
||||||
|
@ -79,7 +80,7 @@ fetchLatest m iface = do
|
||||||
http_ m iface "/rpc/fetch_catalog" Http.POST payload
|
http_ m iface "/rpc/fetch_catalog" Http.POST payload
|
||||||
|
|
||||||
|
|
||||||
getThread :: Model -> Interface a () -> A.GetThreadArgs -> IO a
|
getThread :: Model -> Interface a [ Site ] -> A.GetThreadArgs -> IO a
|
||||||
getThread m iface A.GetThreadArgs {..} =
|
getThread m iface A.GetThreadArgs {..} =
|
||||||
http_ m iface path Http.GET (Nothing :: Maybe ())
|
http_ m iface path Http.GET (Nothing :: Maybe ())
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
module Network.ClientTypes where
|
module Network.ClientTypes where
|
||||||
|
|
||||||
import qualified Network.Http as Http
|
import qualified Network.Http as Http
|
||||||
import Network.CatalogPostType (CatalogPost)
|
|
||||||
import GHCJS.DOM.Types (JSString)
|
import GHCJS.DOM.Types (JSString)
|
||||||
|
|
||||||
data Action a = Connect (Http.HttpActionResult a)
|
data Action a = Connect (Http.HttpActionResult a)
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
|
||||||
|
module Network.PostType where
|
||||||
|
|
||||||
|
import GHC.Generics
|
||||||
|
import Data.Text (Text)
|
||||||
|
import Data.Time.Clock (UTCTime)
|
||||||
|
import Data.Aeson (FromJSON, ToJSON)
|
||||||
|
import Common.AttachmentType (Attachment)
|
||||||
|
|
||||||
|
data Post = Post
|
||||||
|
{ post_id :: Integer
|
||||||
|
, board_post_id :: Integer
|
||||||
|
, creation_time :: UTCTime
|
||||||
|
, body :: Maybe Text
|
||||||
|
, subject :: Maybe Text
|
||||||
|
, name :: Maybe Text
|
||||||
|
, email :: Maybe Text
|
||||||
|
, body_search_index :: Text
|
||||||
|
, thread_id :: Integer
|
||||||
|
, attachments :: [ Attachment ]
|
||||||
|
} deriving (Show, Generic, FromJSON, ToJSON, Eq)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
|
||||||
|
module Network.SiteType where
|
||||||
|
|
||||||
|
import GHC.Generics
|
||||||
|
import Data.Text (Text)
|
||||||
|
import Data.Aeson (FromJSON, ToJSON)
|
||||||
|
import Network.BoardType (Board)
|
||||||
|
|
||||||
|
data Site = Site
|
||||||
|
{ site_id :: Int
|
||||||
|
, name :: Text
|
||||||
|
, url :: Text
|
||||||
|
, boards :: [ Board ]
|
||||||
|
} deriving (Show, Generic, FromJSON, ToJSON, Eq)
|
|
@ -0,0 +1,17 @@
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
|
||||||
|
module Network.ThreadType where
|
||||||
|
|
||||||
|
import GHC.Generics
|
||||||
|
import Data.Time.Clock (UTCTime)
|
||||||
|
import Data.Aeson (FromJSON, ToJSON)
|
||||||
|
import Network.PostType (Post)
|
||||||
|
|
||||||
|
data Thread = Thread
|
||||||
|
{ thread_id :: Integer
|
||||||
|
, board_thread_id :: Integer
|
||||||
|
, creation_time :: UTCTime
|
||||||
|
, board_id :: Int
|
||||||
|
, posts :: [ Post ]
|
||||||
|
} deriving (Show, Generic, FromJSON, ToJSON, Eq)
|
Loading…
Reference in New Issue