Skip to content

Instantly share code, notes, and snippets.

readPostBody : Post -> Html msg
readPostBody post =
main_ [ class "container" ]
[ div [ class "row" ]
[ div [ class "col l6 offset-l3" ]
[ h1 [] [ text <| "ID " ++ post.id ++ ": "++ post.title ]
, List.repeat 10 post.body |> List.map (\par -> p [] [ text par ]) |> div []
]
]
]
readPost : String -> Model -> Html msg
readPost id model =
case List.head <| List.filter (\post -> post.id == id) model.posts of
Just post ->
layout authHeader <| readPostBody post
Nothing ->
error "404 Not Found"
error : a -> Html msg
@grrinchas
grrinchas / Main.elm
Last active December 19, 2017 15:04
main : Program Never Model msg
main = program
{ init = (initialModel, Cmd.none )
-- , view = Pages.landing
, view = Pages.readPost "3"
, update = \msg model -> (model, Cmd.none)
, subscriptions = \model -> Sub.none
}
type alias User =
{ email : String
}
type alias Model =
{ posts: List Post
, user: User -- Added User to the Model
}
initialModel : Model
userHeader : User -> Html msg
userHeader user =
header []
[ nav []
[ div [ class "nav-wrapper container" ]
[ a [class "btn" ] [ text "New Post" ]
, ul [ class "right" ]
[ li [] [ text user.email ]
, li [] [ a [class "btn" ] [ text "Logout" ] ]
]
createPost : Model -> Html msg
createPost model =
layout (userHeader model.user) createPostBody
emailInput : Html msg
emailInput =
div [ class "input-field" ]
[ i [ class "material-icons prefix" ] [ text "email" ]
, input [ placeholder "Email", type_ "text" ] []
]
passwordInput : Html msg
passwordInput =
div [ class "input-field" ]
login : Model -> Html msg
login model = Components.login
signUp : Model -> Html msg
signUp model = Components.signUp
// Do not remove this
$roboto-font-path: "~materialize-css/dist/fonts/roboto/";
@import "../node_modules/materialize-css/sass/materialize";
.full-height {
height: 100%;
}
body, html, #app, main{
@extend .full-height;
module Routes exposing (..)
import Navigation exposing (Location)
import UrlParser exposing (..)
type Route
= HomeRoute
| ReadPostRoute String
| CreatePostRoute
| LoginRoute