Keep filter when returning to overview.

This commit is contained in:
Vidir Valberg Gudmundsson 2017-08-13 15:24:01 +02:00
parent 27a4ff0bbb
commit 92126cc98f
2 changed files with 23 additions and 6 deletions

View file

@ -5,6 +5,7 @@ module Views.DayPicker exposing (..)
import Models exposing (..) import Models exposing (..)
import Messages exposing (Msg(..)) import Messages exposing (Msg(..))
import Routing exposing (routeToString) import Routing exposing (routeToString)
import Views.FilterView exposing (maybeFilteredOverviewRoute)
-- Core modules -- Core modules
@ -52,7 +53,7 @@ dayPicker model =
, ( "btn-default", not isAllDaysActive ) , ( "btn-default", not isAllDaysActive )
, ( "btn-primary", isAllDaysActive ) , ( "btn-primary", isAllDaysActive )
] ]
, href <| routeToString OverviewRoute , href <| routeToString <| maybeFilteredOverviewRoute model
] ]
[ text "All Days" [ text "All Days"
] ]

View file

@ -1,9 +1,9 @@
module Views.FilterView exposing (filterSidebar, applyFilters, parseFilterFromQuery, filterToQuery) module Views.FilterView exposing (filterSidebar, applyFilters, parseFilterFromQuery, filterToQuery, maybeFilteredOverviewRoute)
-- Local modules -- Local modules
import Messages exposing (Msg(..)) import Messages exposing (Msg(..))
import Models exposing (Model, EventInstance, Filter, Day, FilterQuery, Route(OverviewFilteredRoute), VideoRecordingFilter, EventType, EventLocation) import Models exposing (Model, EventInstance, Filter, Day, FilterQuery, Route(OverviewRoute, OverviewFilteredRoute), VideoRecordingFilter, EventType, EventLocation)
import Routing exposing (routeToString) import Routing exposing (routeToString)
@ -204,8 +204,8 @@ parseFilterFromQuery query model =
} }
filterToQuery : Filter -> FilterQuery filterToString : Filter -> String
filterToQuery filter = filterToString filter =
let let
typePart = typePart =
case String.join "," (List.map .slug filter.eventTypes) of case String.join "," (List.map .slug filter.eventTypes) of
@ -230,8 +230,24 @@ filterToQuery filter =
video -> video ->
"video=" ++ video "video=" ++ video
in
String.join "&" (List.filter (\x -> x /= "") [ typePart, locationPart, videoPart ])
filterToQuery : Filter -> FilterQuery
filterToQuery filter =
let
result = result =
String.join "&" (List.filter (\x -> x /= "") [ typePart, locationPart, videoPart ]) filterToString filter
in in
routeToString <| OverviewFilteredRoute result routeToString <| OverviewFilteredRoute result
maybeFilteredOverviewRoute : Model -> Route
maybeFilteredOverviewRoute model =
case filterToString model.filter of
"" ->
OverviewRoute
query ->
OverviewFilteredRoute query