Commit 0e7375aa authored by Darya Rednikina's avatar Darya Rednikina
Browse files

(#2) Added file Page.elm for decomposition, fixed page titles

parent 0d3e3f6e
......@@ -109,24 +109,27 @@ viewForm form =
]
view : Model -> Html Msg
view : Model -> { title : String, content : Html Msg }
view model =
div [ class "cred-page" ]
[ div [ class "container page" ]
[ div [ class "row" ]
[ div [ class "col-md-6 offset-md-3 col-xs-12" ]
[ h1 [ class "text-xs-center" ] [ text "Sign in" ]
, p [ class "text-xs-center" ]
[ a [ Route.href Route.Register ]
[ text "Need an account?" ]
{ title = "Log In"
, content =
div [ class "cred-page" ]
[ div [ class "container page" ]
[ div [ class "row" ]
[ div [ class "col-md-6 offset-md-3 col-xs-12" ]
[ h1 [ class "text-xs-center" ] [ text "Sign in" ]
, p [ class "text-xs-center" ]
[ a [ Route.href Route.Register ]
[ text "Need an account?" ]
]
, ul [ class "error-messages" ]
(List.map viewProblem model.problems)
, viewForm model.form
]
, ul [ class "error-messages" ]
(List.map viewProblem model.problems)
, viewForm model.form
]
]
]
]
}
......
......@@ -4,6 +4,7 @@ import Browser exposing (UrlRequest, application)
import Browser.Navigation as Nav
import Html exposing (Html, h3, text)
import Login exposing (Model)
import Page exposing (Page, view)
import Register exposing (Model)
import Route exposing (Route)
import Url exposing (Url)
......@@ -101,27 +102,32 @@ type alias Document msg =
view : Model -> Document Msg
view model =
{ title = "Post App"
, body = [ currView model ]
}
currView : Model -> Html Msg
currView model =
let
mappedView page toMsg v =
let
{ title, body } =
Page.view page v
in
{ title = title
, body = List.map (Html.map toMsg) body
}
in
case model.page of
NotFoundPage ->
notFoundView
Page.view Page.Other notFoundView
LoginPage pageModel ->
Login.view pageModel |> Html.map LoginMsg
mappedView Page.Login LoginMsg (Login.view pageModel)
RegisterPage pageModel ->
Register.view pageModel |> Html.map RegisterMsg
mappedView Page.Register RegisterMsg (Register.view pageModel)
notFoundView : Html msg
notFoundView : { title : String, content : Html msg }
notFoundView =
h3 [] [ text "Oops! The page you requested was not found!" ]
{ title = "Not 404 found"
, content = h3 [] [ text "Oops! The page you requested was not found!" ]
}
......
module Page exposing (Page(..), view)
import Browser exposing (Document)
import Html exposing (Html)
view :
Page
-> { title : String, content : Html msg }
-> Document msg
view _ { title, content } =
{ title = title
, body = [ content ]
}
{-| PAGE type for future configurations of header/footer/...
-}
type Page
= Other
| Login
| Register
......@@ -131,24 +131,27 @@ viewForm form =
]
view : Model -> Html Msg
view : Model -> { title : String, content : Html Msg }
view model =
div [ class "cred-page" ]
[ div [ class "container page" ]
[ div [ class "row" ]
[ div [ class "col-md-6 offset-md-3 col-xs-12" ]
[ h1 [ class "text-xs-center" ] [ text "Sign up" ]
, p [ class "text-xs-center" ]
[ a [ Route.href Route.Login ]
[ text "Already have an account?" ]
{ title = "Register"
, content =
div [ class "cred-page" ]
[ div [ class "container page" ]
[ div [ class "row" ]
[ div [ class "col-md-6 offset-md-3 col-xs-12" ]
[ h1 [ class "text-xs-center" ] [ text "Sign up" ]
, p [ class "text-xs-center" ]
[ a [ Route.href Route.Login ]
[ text "Already have an account?" ]
]
, ul [ class "error-messages" ]
(List.map V.viewProblem model.problems)
, viewForm model.form
]
, ul [ class "error-messages" ]
(List.map V.viewProblem model.problems)
, viewForm model.form
]
]
]
]
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment