Skip to content

Commit

Permalink
Merge pull request #483 from geeksforsocialchange/keep-region-selection
Browse files Browse the repository at this point in the history
fix: Maintain selected region when switching between pages
  • Loading branch information
james-collapse authored Dec 17, 2024
2 parents 2fe1679 + a98bb77 commit 00a15d8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
20 changes: 14 additions & 6 deletions app/Route/Events.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Theme.RegionSelector
import Time
import UrlPath
import View exposing (View)
import Messages exposing (Msg(..))


type alias Model =
Expand Down Expand Up @@ -66,7 +67,7 @@ update :
-> Shared.Model
-> Msg
-> Model
-> ( Model, Effect.Effect Msg )
-> ( Model, Effect.Effect Msg, Maybe Shared.Msg )
update app _ msg model =
case msg of
Theme.Page.Events.PaginatorMsg submsg ->
Expand All @@ -77,20 +78,23 @@ update app _ msg model =
Theme.Paginator.Day posix
}
, Effect.none
, Nothing
)

Theme.Paginator.ClickedAllPastEvents ->
( { model
| filterByDate = Theme.Paginator.Past
}
, Effect.none
, Nothing
)

Theme.Paginator.ClickedAllFutureEvents ->
( { model
| filterByDate = Theme.Paginator.Future
}
, Effect.none
, Nothing
)

Theme.Paginator.GetTime newTime ->
Expand All @@ -99,6 +103,7 @@ update app _ msg model =
, nowTime = newTime
}
, Effect.none
, Nothing
)

Theme.Paginator.ScrollRight ->
Expand All @@ -107,6 +112,7 @@ update app _ msg model =
(Theme.Paginator.scrollPagination Theme.Paginator.Right model.viewportWidth)
|> Cmd.map Theme.Page.Events.fromPaginatorMsg
|> Effect.fromCmd
, Nothing
)

Theme.Paginator.ScrollLeft ->
Expand All @@ -115,21 +121,23 @@ update app _ msg model =
(Theme.Paginator.scrollPagination Theme.Paginator.Left model.viewportWidth)
|> Cmd.map Theme.Page.Events.fromPaginatorMsg
|> Effect.fromCmd
, Nothing
)

Theme.Paginator.GotViewport viewport ->
( { model | viewportWidth = Maybe.withDefault model.viewportWidth (Just viewport.scene.width) }, Effect.none )
( { model | viewportWidth = Maybe.withDefault model.viewportWidth (Just viewport.scene.width) }, Effect.none, Nothing )

Theme.Paginator.NoOp ->
( model, Effect.none )
( model, Effect.none, Nothing )

Theme.Page.Events.RegionSelectorMsg submsg ->
case submsg of
Theme.RegionSelector.ClickedSelector regionId ->
Theme.RegionSelector.ClickedSelector tagId ->
( { model
| filterByRegion = regionId
| filterByRegion = tagId
}
, Effect.none
, Just (SetRegion tagId)
)


Expand All @@ -142,7 +150,7 @@ route : RouteBuilder.StatefulRoute RouteParams Data ActionData Model Msg
route =
RouteBuilder.single
{ data = data, head = head }
|> RouteBuilder.buildWithLocalState
|> RouteBuilder.buildWithSharedState
{ init = init
, view = view
, update = update
Expand Down
6 changes: 4 additions & 2 deletions app/Route/Index.elm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Theme.RegionSelector exposing (Msg(..))
import Time
import UrlPath
import View
import Messages exposing (Msg(..))


type alias Model =
Expand Down Expand Up @@ -56,14 +57,15 @@ update :
-> Shared.Model
-> Msg
-> Model
-> ( Model, Effect.Effect Msg )
-> ( Model, Effect.Effect Msg, Maybe Shared.Msg )
update app _ msg model =
case msg of
ClickedSelector tagId ->
( { model
| filterByRegion = tagId
}
, Effect.none
, Just (SetRegion tagId)
)


Expand All @@ -76,7 +78,7 @@ route : RouteBuilder.StatefulRoute RouteParams Data ActionData Model Msg
route =
RouteBuilder.single
{ data = data, head = head }
|> RouteBuilder.buildWithLocalState
|> RouteBuilder.buildWithSharedState
{ init = init
, view = view
, update = update
Expand Down
6 changes: 4 additions & 2 deletions app/Route/Partners.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Theme.PageTemplate
import Theme.RegionSelector exposing (Msg(..))
import UrlPath
import View
import Messages exposing (Msg(..))


type alias Model =
Expand Down Expand Up @@ -50,14 +51,15 @@ update :
-> Shared.Model
-> Msg
-> Model
-> ( Model, Effect.Effect Msg )
-> ( Model, Effect.Effect Msg, Maybe Shared.Msg )
update app _ msg model =
case msg of
ClickedSelector tagId ->
( { model
| filterByRegion = tagId
}
, Effect.none
, Just (SetRegion tagId)
)


Expand All @@ -70,7 +72,7 @@ route : RouteBuilder.StatefulRoute RouteParams Data ActionData Model Msg
route =
RouteBuilder.single
{ data = data, head = head }
|> RouteBuilder.buildWithLocalState
|> RouteBuilder.buildWithSharedState
{ init = init
, view = view
, update = update
Expand Down
4 changes: 4 additions & 0 deletions app/Shared.elm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ update msg model =
-- Shared
SharedMsg _ ->
( model, Effect.none )

-- Update region filter
SetRegion tagId ->
( { model | filterParam = Just (tagId) }, Effect.none )


subscriptions : UrlPath -> Model -> Sub Msg
Expand Down
1 change: 1 addition & 0 deletions src/Messages.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Msg
| ToggleMenu
-- Shared
| SharedMsg SharedMsg
| SetRegion Int


type SharedMsg
Expand Down

0 comments on commit 00a15d8

Please sign in to comment.