2017-07-17 09:25:57 +00:00
|
|
|
module Update exposing (update)
|
|
|
|
|
|
|
|
-- Local modules
|
|
|
|
|
2017-07-17 19:48:56 +00:00
|
|
|
import Models exposing (Model, Route(OverviewRoute, EventRoute), Filter)
|
2017-07-17 09:25:57 +00:00
|
|
|
import Messages exposing (Msg(..))
|
|
|
|
import Decoders exposing (webSocketActionDecoder, initDataDecoder, eventDecoder)
|
|
|
|
import Routing exposing (parseLocation)
|
|
|
|
|
|
|
|
|
|
|
|
-- Core modules
|
|
|
|
|
|
|
|
import Json.Decode
|
|
|
|
|
|
|
|
|
2017-07-19 16:30:50 +00:00
|
|
|
-- External modules
|
|
|
|
|
|
|
|
import Navigation
|
|
|
|
|
|
|
|
|
2017-07-17 09:25:57 +00:00
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
|
|
update msg model =
|
|
|
|
case msg of
|
|
|
|
NoOp ->
|
|
|
|
( model, Cmd.none )
|
|
|
|
|
|
|
|
WebSocketPayload str ->
|
|
|
|
let
|
|
|
|
newModel =
|
|
|
|
case Json.Decode.decodeString webSocketActionDecoder str of
|
|
|
|
Ok webSocketAction ->
|
|
|
|
case webSocketAction.action of
|
|
|
|
"init" ->
|
|
|
|
case Json.Decode.decodeString initDataDecoder str of
|
|
|
|
Ok m ->
|
2017-07-19 16:30:50 +00:00
|
|
|
m model.flags (Filter [] [] []) model.route
|
2017-07-17 09:25:57 +00:00
|
|
|
|
|
|
|
Err error ->
|
|
|
|
model
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
model
|
|
|
|
|
|
|
|
Err error ->
|
|
|
|
model
|
|
|
|
in
|
|
|
|
newModel ! []
|
|
|
|
|
|
|
|
ToggleEventTypeFilter eventType ->
|
|
|
|
let
|
|
|
|
eventTypesFilter =
|
|
|
|
if List.member eventType model.filter.eventTypes then
|
|
|
|
List.filter (\x -> x /= eventType) model.filter.eventTypes
|
|
|
|
else
|
|
|
|
eventType :: model.filter.eventTypes
|
|
|
|
|
|
|
|
currentFilter =
|
|
|
|
model.filter
|
|
|
|
|
|
|
|
newFilter =
|
|
|
|
{ currentFilter | eventTypes = eventTypesFilter }
|
|
|
|
in
|
|
|
|
{ model | filter = newFilter } ! []
|
|
|
|
|
|
|
|
ToggleEventLocationFilter eventLocation ->
|
|
|
|
let
|
|
|
|
eventLocationsFilter =
|
|
|
|
if List.member eventLocation model.filter.eventLocations then
|
|
|
|
List.filter (\x -> x /= eventLocation) model.filter.eventLocations
|
|
|
|
else
|
|
|
|
eventLocation :: model.filter.eventLocations
|
|
|
|
|
|
|
|
currentFilter =
|
|
|
|
model.filter
|
|
|
|
|
|
|
|
newFilter =
|
|
|
|
{ currentFilter | eventLocations = eventLocationsFilter }
|
|
|
|
in
|
|
|
|
{ model | filter = newFilter } ! []
|
|
|
|
|
2017-07-18 11:35:17 +00:00
|
|
|
ToggleVideoRecordingFilter videoRecording ->
|
|
|
|
let
|
|
|
|
videoRecordingFilter =
|
|
|
|
if List.member videoRecording model.filter.videoRecording then
|
|
|
|
List.filter (\x -> x /= videoRecording) model.filter.videoRecording
|
|
|
|
else
|
|
|
|
videoRecording :: model.filter.videoRecording
|
|
|
|
|
|
|
|
currentFilter =
|
|
|
|
model.filter
|
|
|
|
|
|
|
|
newFilter =
|
|
|
|
{ currentFilter | videoRecording = videoRecordingFilter }
|
|
|
|
in
|
|
|
|
{ model | filter = newFilter } ! []
|
|
|
|
|
2017-07-17 09:25:57 +00:00
|
|
|
OnLocationChange location ->
|
|
|
|
let
|
|
|
|
newRoute =
|
2017-07-17 14:05:38 +00:00
|
|
|
parseLocation location
|
2017-07-17 09:25:57 +00:00
|
|
|
in
|
2017-07-18 09:26:56 +00:00
|
|
|
{ model | route = newRoute } ! []
|
2017-07-19 16:30:50 +00:00
|
|
|
|
|
|
|
BackInHistory ->
|
|
|
|
model ! [ Navigation.back 1 ]
|