From 9f8ab54a34964cd691d0bc49d17876f81b6fe0d5 Mon Sep 17 00:00:00 2001 From: Vidir Valberg Gudmundsson Date: Thu, 3 Aug 2017 12:51:13 +0200 Subject: [PATCH] Forgot to add SpeakerDetail.elm --- schedule/src/Views/SpeakerDetail.elm | 82 ++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 schedule/src/Views/SpeakerDetail.elm diff --git a/schedule/src/Views/SpeakerDetail.elm b/schedule/src/Views/SpeakerDetail.elm new file mode 100644 index 00000000..4c13f2b7 --- /dev/null +++ b/schedule/src/Views/SpeakerDetail.elm @@ -0,0 +1,82 @@ +module Views.SpeakerDetail exposing (..) + +-- Local modules + +import Messages exposing (Msg(BackInHistory)) +import Models exposing (Model, SpeakerSlug, Speaker, Route(EventRoute), Event) +import Routing exposing (routeToString) + + +-- External modules + +import Html exposing (Html, div, text, a, i, h3, img, ul, li, p) +import Html.Attributes exposing (classList, src, href) +import Html.Events exposing (onClick) +import Markdown + + +speakerDetailView : SpeakerSlug -> Model -> Html Msg +speakerDetailView speakerSlug model = + let + speaker = + model.speakers + |> List.filter (\speaker -> speaker.slug == speakerSlug) + |> List.head + + image = + case speaker of + Just speaker -> + case speaker.smallPictureUrl of + Just smallPictureUrl -> + [ img [ src smallPictureUrl ] [] ] + + Nothing -> + [] + + Nothing -> + [] + in + case speaker of + Just speaker -> + div [] + ([ a [ onClick BackInHistory, classList [ ( "btn", True ), ( "btn-default", True ) ] ] + [ i [ classList [ ( "fa", True ), ( "fa-chevron-left", True ) ] ] [] + , text " Back" + ] + , h3 [] [ text speaker.name ] + , div [] [ Markdown.toHtml [] speaker.biography ] + , speakerEvents speaker model + ] + ++ image + ) + + Nothing -> + div [] [ text "Unknown speaker..." ] + + +speakerEvents : Speaker -> Model -> Html Msg +speakerEvents speaker model = + let + events = + model.events + |> List.filter (\event -> List.member speaker.slug event.speakerSlugs) + in + case events of + [] -> + p [] [ text "This speaker has no events!" ] + + events -> + div [] + [ h3 [] [ text "Events:" ] + , ul [] + (List.map + eventItem + events + ) + ] + + +eventItem : Event -> Html Msg +eventItem event = + li [] + [ a [ href <| routeToString <| EventRoute event.slug ] [ text event.title ] ]