Put Model into separate module

- pass model to BodyRender
    - so we can render the quotelinks better (TODO)
This commit is contained in:
towards-a-new-leftypol 2024-02-11 13:58:16 -05:00
parent be7b381988
commit 24758470af
4 changed files with 48 additions and 33 deletions

View File

@ -75,6 +75,7 @@ executable chandlr
Component.ThreadView Component.ThreadView
Component.Thread.Files Component.Thread.Files
Component.Thread.Intro Component.Thread.Intro
Component.Thread.Model
Component.BodyRender Component.BodyRender
Routes Routes
Common.AttachmentType Common.AttachmentType

View File

@ -23,6 +23,9 @@ import Miso.String (toMisoString, fromMisoString)
import Text.Parsec (ParseError) import Text.Parsec (ParseError)
import BodyParser (PostPart (..)) import BodyParser (PostPart (..))
import QuoteLinkParser import QuoteLinkParser
import qualified Component.Thread.Model as Model
import qualified Network.SiteType as Site
import qualified Network.ThreadType as Thread
{- {-
- This is the inverse of parsePostBody from BodyParser except - This is the inverse of parsePostBody from BodyParser except
@ -34,21 +37,21 @@ import QuoteLinkParser
- (is there an easy way to render a miso View?, that's what's missing - (is there an easy way to render a miso View?, that's what's missing
- a f :: View a -> Text) - a f :: View a -> Text)
-} -}
render :: [ PostPart ] -> [ View a ] render :: Model.Model -> [ PostPart ] -> [ View a ]
render = map renderPostPart render m = map (renderPostPart m)
renderPostPart :: PostPart -> View a renderPostPart :: Model.Model -> PostPart -> View a
renderPostPart (SimpleText txt) = text txt renderPostPart _ (SimpleText txt) = text txt
renderPostPart (PostedUrl u) = renderPostPart _ (PostedUrl u) =
a_ a_
[ href_ u [ href_ u
, target_ "_blank" , target_ "_blank"
] ]
[ text u ] [ text u ]
renderPostPart Skip = br_ [] renderPostPart _ Skip = br_ []
renderPostPart (Quote url) = elems parse_result renderPostPart m (Quote url) = elems parse_result
where where
parse_result = parseURL $ fromMisoString url parse_result = parseURL $ fromMisoString url
@ -64,27 +67,27 @@ renderPostPart (Quote url) = elems parse_result
[ href_ url ] [ href_ url ]
[ text url ] [ text url ]
renderPostPart (GreenText parts) = renderPostPart m (GreenText parts) =
span_ [ class_ "quote" ] (render parts) span_ [ class_ "quote" ] (render m parts)
renderPostPart (OrangeText parts) = renderPostPart m (OrangeText parts) =
span_ [ class_ "orangeQuote" ] (render parts) span_ [ class_ "orangeQuote" ] (render m parts)
renderPostPart (RedText parts) = renderPostPart m (RedText parts) =
span_ [ class_ "heading" ] (render parts) span_ [ class_ "heading" ] (render m parts)
renderPostPart (Spoiler parts) = renderPostPart m (Spoiler parts) =
span_ [ class_ "spoiler" ] (render parts) span_ [ class_ "spoiler" ] (render m parts)
renderPostPart (Bold parts) = renderPostPart m (Bold parts) =
strong_ [] (render parts) strong_ [] (render m parts)
renderPostPart (Underlined parts) = renderPostPart m (Underlined parts) =
u_ [] (render parts) u_ [] (render m parts)
renderPostPart (Italics parts) = renderPostPart m (Italics parts) =
em_ [] (render parts) em_ [] (render m parts)
renderPostPart (Strikethrough parts) = renderPostPart m (Strikethrough parts) =
s_ [] (render parts) s_ [] (render m parts)

View File

@ -0,0 +1,15 @@
module Component.Thread.Model where
import GHCJS.DOM.Types (JSString)
import Network.SiteType (Site)
import Network.PostType (Post)
import BodyParser (PostPart)
type PostWithBody = (Post, [ PostPart ])
data Model = Model
{ site :: Site
, media_root :: JSString
, post_bodies :: [ PostWithBody ]
} deriving Eq

View File

@ -37,17 +37,10 @@ import qualified Network.BoardType as Board
import qualified Network.ThreadType as Thread import qualified Network.ThreadType as Thread
import Component.Thread.Files (files) import Component.Thread.Files (files)
import Component.Thread.Intro (intro) import Component.Thread.Intro (intro)
import Component.Thread.Model
import BodyParser import BodyParser
import qualified Component.BodyRender as Body import qualified Component.BodyRender as Body
type PostWithBody = (Post, [ PostPart ])
data Model = Model
{ site :: Site
, media_root :: JSString
, post_bodies :: [ PostWithBody ]
} deriving Eq
initialModel :: JSString -> Site -> Model initialModel :: JSString -> Site -> Model
initialModel mroot s = Model initialModel mroot s = Model
{ site = s { site = s
@ -127,7 +120,7 @@ op m op_post =
where where
body :: [ PostWithBody ] -> [ View a ] body :: [ PostWithBody ] -> [ View a ]
body [] = [] body [] = []
body x = Body.render $ snd $ head x body x = Body.render m $ snd $ head x
multi :: Post -> [ Attribute a ] multi :: Post -> [ Attribute a ]
@ -143,6 +136,9 @@ reply m (post, parts) = div_
, textProp "data-board" "leftypol" , textProp "data-board" "leftypol"
] ]
[ div_ [ div_
[ class_ "sidearrows" ]
[ text ">>" ]
, div_
( (
[ class_ "post reply" [ class_ "post reply"
, id_ "reply_477702" , id_ "reply_477702"
@ -152,6 +148,6 @@ reply m (post, parts) = div_
, files (media_root m) (site m) post , files (media_root m) (site m) post
, div_ , div_
[ class_ "body" ] [ class_ "body" ]
(Body.render parts) (Body.render m parts)
] ]
] ]