Skip to content

Commit

Permalink
Add from constructors from #18
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyAlex200 committed Oct 1, 2018
1 parent bdd01ba commit a8ce506
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 16 deletions.
49 changes: 40 additions & 9 deletions ui/src/PostSummary.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
module PostSummary exposing (..)
module PostSummary exposing
( Model
, Msg
, fromHash
, fromPost
, update
, view
)

import Html.Attributes as Attributes
import Loadable exposing (Loadable)
Expand Down Expand Up @@ -27,20 +34,44 @@ type Msg
| VoteViewMsg VoteView.Msg
| NoOp

uninitialized : VoteView.Model -> KarmaMap -> String -> Maybe (List Tag) -> Model
uninitialized voteViewModel karmaMap hash inTermsOf =
Model
Loadable.Unloaded
voteViewModel
karmaMap
inTermsOf
hash

fromPost : Post -> KarmaMap -> String -> Maybe (List Tag) -> ( Model, Cmd Msg )
fromPost post karmaMap hash inTermsOf =
let
( voteViewModel, voteViewCmd ) =
VoteView.fromHash karmaMap hash inTermsOf
in
uninitialized voteViewModel karmaMap hash inTermsOf
|> update (ReceivePost post)
|> Tuple.mapSecond (\cmd ->
Cmd.batch
[ cmd
, Cmd.map VoteViewMsg voteViewCmd
]
)

fromHash : KarmaMap -> String -> Maybe (List Tag) -> ( Model, Cmd Msg )
fromHash karmaMap hash inTermsOf =
let
( voteViewModel, voteViewCmd ) =
VoteView.fromHash karmaMap hash inTermsOf
uninitialized =
Model
Loadable.Unloaded
voteViewModel
karmaMap
inTermsOf
hash
in
update (RequestPost hash) uninitialized
uninitialized voteViewModel karmaMap hash inTermsOf
|> update (RequestPost hash)
|> Tuple.mapSecond (\cmd ->
Cmd.batch
[ cmd
, Cmd.map VoteViewMsg voteViewCmd
]
)

-- Update

Expand Down
28 changes: 21 additions & 7 deletions ui/src/PostView.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module PostView exposing (..)
module PostView exposing
( Model
, Msg
, fromHash
, fromPost
, update
, documentTitle
, view
)

import Tuple exposing (first, second)
import Html.Attributes as Attributes
Expand Down Expand Up @@ -42,10 +50,8 @@ type Msg
| ReceiveInTermsOf (List Tag)
-- TODO: UpdateKarmaMap Msg

fromHash : KarmaMap -> String -> Maybe (List Tag) -> ( Model, Cmd Msg )
fromHash karmaMap hash inTermsOf =
let
uninitialized =
uninitialized : KarmaMap -> String -> Maybe (List Tag) -> Model
uninitialized karmaMap hash inTermsOf =
Model
Loadable.Unloaded
(first (CommentsView.fromHash karmaMap hash inTermsOf))
Expand All @@ -55,8 +61,16 @@ fromHash karmaMap hash inTermsOf =
MarkdownCompose.init
False
inTermsOf
in
update (RequestPost hash) uninitialized

fromHash : KarmaMap -> String -> Maybe (List Tag) -> ( Model, Cmd Msg )
fromHash karmaMap hash inTermsOf =
uninitialized karmaMap hash inTermsOf
|> update (RequestPost hash)

fromPost : Post -> KarmaMap -> String -> Maybe (List Tag) -> ( Model, Cmd Msg )
fromPost post karmaMap hash inTermsOf =
uninitialized karmaMap hash inTermsOf
|> update (ReceivePost post)

-- Update

Expand Down

0 comments on commit a8ce506

Please sign in to comment.