~ben/aurelius

5785676720d53a95c61d653e44d5332da82af2b6 — Ben Sima 3 years ago 555e012
Add AllQuotes and navbar
5 files changed, 86 insertions(+), 49 deletions(-)

M assets/css/main.css
M index.html
M src/Main.elm
M src/Quote.elm
M src/Routing.elm
M assets/css/main.css => assets/css/main.css +8 -0
@@ 105,6 105,14 @@ header a:hover
{ color: #999
}

header a#refresh
{ color: #999
}

header a#refresh:hover
{ color: #111
}

#content,
h1, h2, h3, h4, h5, h6
{ font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif

M index.html => index.html +2 -2
@@ 11,8 11,8 @@
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <link rel="stylesheet" href="assets/css/normalize.css">
    <link rel="stylesheet" href="assets/css/main.css">
    <link rel="stylesheet" href="/assets/css/normalize.css">
    <link rel="stylesheet" href="/assets/css/main.css">
    <script type="text/javascript" src="out/main.js"></script>
  </head>
  <body></body>

M src/Main.elm => src/Main.elm +60 -35
@@ 1,7 1,7 @@
module Main exposing (..)

import Html exposing (Html, button, div, text, h1, h2, span, p, article)
import Html.Attributes exposing (class, style, id)
import Html exposing (Html, button, div, text, h1, h2, span, p, article, header, nav, a)
import Html.Attributes exposing (class, style, id, href, target)
import Html.Events exposing (onClick)
import Navigation exposing (Location)
import Markdown


@@ 77,6 77,33 @@ update msg model =
                ( { model | route = newRoute }, Cmd.none )


shoveWebData : (a -> Html Msg) -> WebData a -> Html Msg
shoveWebData viewer data =
    case data of
        NotAsked ->
            wrap <| p [] [ text "Initializing." ]

        Loading ->
            wrap <| p [] [ text "Loading..." ]

        Failure err ->
            wrap <|
                div []
                    [ p [] [ text <| "Error: " ++ (toString err) ]
                    , Markdown.toHtml [ class "content" ]
                        """
Try refreshing?

If the problem persists, please report
the error at [GitHub](https://github.com/bsima/aurelius/issues)
and I will fix it right away. Thanks!
"""
                    ]

        Success stuff ->
            wrap <| viewer stuff


view : Model -> Html Msg
view model =
    case model.route of


@@ 86,44 113,42 @@ view model =
        Index ->
            wrap <| p [] [ text "Loading..." ]

        QuoteRoute book section ->
            case model.quotes of
                NotAsked ->
                    wrap <| p [] [ text "Initializing." ]

                Loading ->
                    wrap <| p [] [ text "Loading..." ]
        AllQuotes ->
            model.quotes
                |> shoveWebData (\xs -> div [] <| List.map Quote.view_ xs)

                Failure err ->
                    wrap <|
                        div []
                            [ p [] [ text <| "Error: " ++ (toString err) ]
                            , Markdown.toHtml [ class "content" ]
                                """Try refreshing?

                              If the problem persists, please report
                              the error at [GitHub](https://github.com/bsima/aurelius/issues)
                              and I will fix it right away. Thanks!"""
                            ]

                Success quotes ->
                    wrap <| Quote.view quotes model.route
        QuoteRoute book section ->
            shoveWebData (Quote.view model.route) model.quotes


wrap : Html Msg -> Html Msg
wrap kids =
    div [ id "content", class "wrapper" ]
        [ button
            [ class "sans"
            , style
                [ ( "border", "none" )
                , ( "background", "transparent" )
                , ( "margin-top", "1rem" )
    div []
        [ navbar
        , div
            [ id "content", class "wrapper" ]
            [ h1 [] [ text "Marcus Aurelius" ]
            , p [ class "subtitle" ] [ text "Meditations" ]
            , kids
            ]
        ]


navbar : Html Msg
navbar =
    header [ class "scroll wrapper" ]
        [ nav []
            [ a
                [ href "#"
                , id "refresh"
                , onClick Refresh
                ]
                [ text "Refresh" ]
            , a [ href "#/all" ] [ text "All Quotes" ]
            , a
                [ href "https://goo.gl/forms/zivB95KX91rzcPHT2"
                , target "_blank"
                ]
            , onClick Refresh
                [ text "Submit a Quote" ]
            ]
            [ text "Refresh" ]
        , h1 [] [ text "Marcus Aurelius" ]
        , p [ class "subtitle" ] [ text "Meditations" ]
        , kids
        ]

M src/Quote.elm => src/Quote.elm +14 -12
@@ 37,8 37,20 @@ select book section quotes =
                Result.Err (QuoteSelectError book section)


view : List Quote -> Route -> Html Msg
view quotes route =
view_ : Quote -> Html Msg
view_ quote =
    div []
        [ viewMeta quote
        , article []
            [ quote.content
                |> String.join "\n\n"
                |> Markdown.toHtml [ class "content" ]
            ]
        ]


view : Route -> List Quote -> Html Msg
view route quotes =
    let
        ( book, section ) =
            case route of


@@ 48,16 60,6 @@ view quotes route =
                _ ->
                    ( 0, 0 )

        view_ quote =
            div []
                [ viewMeta quote
                , article []
                    [ quote.content
                        |> String.join "\n\n"
                        |> Markdown.toHtml [ class "content" ]
                    ]
                ]

        helpMsg =
            Markdown.toHtml [ class "content" ]
                """This is an open source project, and not all of the

M src/Routing.elm => src/Routing.elm +2 -0
@@ 6,6 6,7 @@ import UrlParser exposing (..)
type Route
    = QuoteRoute Int Int
    | Index
    | AllQuotes
    | NotFoundRoute




@@ 13,6 14,7 @@ matchers : Parser (Route -> a) a
matchers =
    oneOf
        [ map QuoteRoute  ( int </> int)
        , map AllQuotes (s "all")
        , map Index top
        ]