summaryrefslogtreecommitdiffstats
path: root/src/Pages/Profile.elm
blob: 479c90807916107ef15c2bf02debc289a85c6e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Pages.Profile exposing (..)

import Components.PostList exposing (postList)
import Css exposing (marginBottom, px)
import Html.Styled exposing (..)
import Html.Styled.Attributes exposing (css)
import RemoteData exposing (RemoteData(..))
import Types exposing (Model, Msg, Post, UrlSegmentUserId)
import Utils exposing (templ)


styles =
    { container =
        css
            [ marginBottom (px 10)
            ]
    }


postsContainer : Model -> UrlSegmentUserId -> Html Msg
postsContainer model id =
    let
        onlyProfilePosts : List Post -> List Post
        onlyProfilePosts posts =
            List.filter (\p -> p.author.id == id) posts
    in
    case model.posts of
        Initial ->
            div [] []

        Loading ->
            div [] [ text "Loading posts..." ]

        Failure _ ->
            div [] []

        Success posts ->
            postList model.now (onlyProfilePosts posts)


body : Model -> UrlSegmentUserId -> Html Msg
body model id =
    div [ styles.container ]
        [ h2 [] [ "Posts by {0}" |> templ [ id ] |> text ]
        , postsContainer model id
        ]


profileView : UrlSegmentUserId -> Model -> List (Html Msg)
profileView userId model =
    [ body model userId ]