No need for activeDay stuff. Also make back button in EventDetail more flexible.

This commit is contained in:
Vidir Valberg Gudmundsson 2017-07-19 18:30:50 +02:00
parent 725535d4a7
commit 27d90c8041
8 changed files with 44 additions and 29 deletions

View File

@ -107,7 +107,7 @@ eventTypeDecoder =
|> required "light_text" bool
initDataDecoder : Decoder (Flags -> Maybe Day -> Filter -> Route -> Model)
initDataDecoder : Decoder (Flags -> Filter -> Route -> Model)
initDataDecoder =
decode Model
|> required "days" (list dayDecoder)

View File

@ -38,7 +38,7 @@ init flags location =
Filter [] [] []
initModel =
(Model [] [] [] [] [] flags Nothing emptyFilter currentRoute)
Model [] [] [] [] [] flags emptyFilter currentRoute
in
initModel ! [ sendInitMessage flags.camp_slug ]

View File

@ -13,9 +13,8 @@ import Navigation exposing (Location)
type Msg
= NoOp
| WebSocketPayload String
| MakeActiveday Day
| RemoveActiveDay
| ToggleEventTypeFilter EventType
| ToggleEventLocationFilter EventLocation
| ToggleVideoRecordingFilter { name : String, filter : EventInstance -> Bool }
| OnLocationChange Location
| BackInHistory

View File

@ -17,7 +17,6 @@ type alias Model =
, eventLocations : List EventLocation
, eventTypes : List EventType
, flags : Flags
, activeDay : Maybe Day
, filter : Filter
, route : Route
}

View File

@ -13,6 +13,11 @@ import Routing exposing (parseLocation)
import Json.Decode
-- External modules
import Navigation
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
@ -28,7 +33,7 @@ update msg model =
"init" ->
case Json.Decode.decodeString initDataDecoder str of
Ok m ->
m model.flags Nothing (Filter [] [] []) model.route
m model.flags (Filter [] [] []) model.route
Err error ->
model
@ -41,12 +46,6 @@ update msg model =
in
newModel ! []
MakeActiveday day ->
{ model | activeDay = Just day } ! []
RemoveActiveDay ->
{ model | activeDay = Nothing } ! []
ToggleEventTypeFilter eventType ->
let
eventTypesFilter =
@ -101,3 +100,6 @@ update msg model =
parseLocation location
in
{ model | route = newRoute } ! []
BackInHistory ->
model ! [ Navigation.back 1 ]

View File

@ -6,20 +6,33 @@ import Models exposing (..)
import Messages exposing (Msg(..))
-- Core modules
import Date exposing (Date)
-- External modules
import Html exposing (Html, text, a, div)
import Html.Attributes exposing (class, classList, href, id)
import Html.Events exposing (onClick)
import Date.Extra as Date
import Date.Extra
dayPicker : Model -> Html Msg
dayPicker model =
let
activeDate =
case model.route of
DayRoute iso ->
Date.Extra.fromIsoString iso
_ ->
Nothing
isAllDaysActive =
case model.activeDay of
Just activeDay ->
case activeDate of
Just _ ->
False
Nothing ->
@ -34,23 +47,22 @@ dayPicker model =
, ( "btn-primary", isAllDaysActive )
]
, href ("#")
, onClick (RemoveActiveDay)
]
[ text "All Days"
]
]
++ (List.map (\day -> dayButton day model.activeDay) model.days)
++ (List.map (\day -> dayButton day activeDate) model.days)
)
]
dayButton : Day -> Maybe Day -> Html Msg
dayButton day activeDay =
dayButton : Day -> Maybe Date -> Html Msg
dayButton day activeDate =
let
isActive =
case activeDay of
Just activeDay ->
day == activeDay
case activeDate of
Just activeDate ->
day.date == activeDate
Nothing ->
False
@ -61,8 +73,7 @@ dayButton day activeDay =
, ( "btn-default", not isActive )
, ( "btn-primary", isActive )
]
, href ("#day/" ++ (Date.toFormattedString "y-MM-dd" day.date))
, onClick (MakeActiveday day)
, href ("#day/" ++ (Date.Extra.toFormattedString "y-MM-dd" day.date))
]
[ text day.day_name
]

View File

@ -13,8 +13,8 @@ import Date exposing (Date)
-- External modules
import Html exposing (Html, text, div, ul, li, span, i, h4, table, p)
import Html.Attributes exposing (classList, style)
import Html exposing (Html, text, div, ul, li, span, i, h4, table, p, a)
import Html.Attributes exposing (classList, style, href)
import Date.Extra
@ -121,7 +121,7 @@ eventInstanceBlock eventInstance =
height =
(toString (length * toFloat blockHeight)) ++ "px"
in
div
a
[ classList
[ ( "event", True )
, ( "event-in-dayview", True )
@ -129,7 +129,9 @@ eventInstanceBlock eventInstance =
, style
[ ( "height", height )
, ( "background-color", eventInstance.backgroundColor )
, ( "color", eventInstance.forgroundColor )
]
, href ("#event/" ++ eventInstance.eventSlug)
]
[ p [] [ text ((Date.Extra.toFormattedString "HH:mm" eventInstance.from) ++ " " ++ eventInstance.title) ]
]

View File

@ -10,6 +10,7 @@ import Models exposing (..)
import Html exposing (Html, text, div, ul, li, span, i, h4, a, p, hr)
import Html.Attributes exposing (class, classList, href)
import Html.Events exposing (onClick)
import Markdown
import Date.Extra
@ -27,8 +28,9 @@ eventDetailView eventSlug model =
in
div [ class "row" ]
[ div [ class "col-sm-9" ]
[ a [ href "#" ]
[ text "Back"
[ a [ onClick BackInHistory, classList [ ( "btn", True ), ( "btn-default", True ) ] ]
[ i [ classList [ ( "fa", True ), ( "fa-chevron-left", True ) ] ] []
, text " Back"
]
, h4 [] [ text event.title ]
, p [] [ Markdown.toHtml [] event.abstract ]