Skip to content

Commit

Permalink
Merge pull request #468 from geeksforsocialchange/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
katjam authored Dec 8, 2024
2 parents 895258f + 9a9391a commit 43fb084
Show file tree
Hide file tree
Showing 16 changed files with 711 additions and 200 deletions.
139 changes: 74 additions & 65 deletions app/Route/Events.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ import Shared
import Task
import Theme.Page.Events
import Theme.PageTemplate
import Theme.Paginator exposing (Msg(..))
import Theme.Paginator
import Theme.RegionSelector
import Time
import UrlPath
import View exposing (View)


type alias Model =
{ filterBy : Theme.Paginator.Filter
, visibleEvents : List Data.PlaceCal.Events.Event
{ filterByDate : Theme.Paginator.Filter
, filterByRegion : Int
, nowTime : Time.Posix
, viewportWidth : Float
}


type alias Msg =
Theme.Paginator.Msg
Theme.Page.Events.Msg


type alias RouteParams =
Expand All @@ -47,15 +48,15 @@ init :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> ( Model, Effect.Effect Msg )
init app _ =
( { filterBy = Theme.Paginator.None
, visibleEvents = Data.PlaceCal.Events.eventsWithPartners app.sharedData.events app.sharedData.partners
init app shared =
( { filterByDate = Theme.Paginator.None
, filterByRegion = Maybe.withDefault 0 shared.filterParam
, nowTime = Time.millisToPosix 0
, viewportWidth = 320
}
, Effect.batch
[ Task.perform GetTime Time.now |> Effect.fromCmd
, Task.perform GotViewport Browser.Dom.getViewport |> Effect.fromCmd
[ Task.perform Theme.Paginator.GetTime Time.now |> Cmd.map Theme.Page.Events.fromPaginatorMsg |> Effect.fromCmd
, Task.perform Theme.Paginator.GotViewport Browser.Dom.getViewport |> Cmd.map Theme.Page.Events.fromPaginatorMsg |> Effect.fromCmd
]
)

Expand All @@ -68,60 +69,68 @@ update :
-> ( Model, Effect.Effect Msg )
update app _ msg model =
case msg of
ClickedDay posix ->
( { model
| filterBy = Theme.Paginator.Day posix
, visibleEvents =
Data.PlaceCal.Events.eventsWithPartners (Data.PlaceCal.Events.eventsFromDate app.sharedData.events posix) app.sharedData.partners
}
, Effect.none
)

ClickedAllPastEvents ->
( { model
| filterBy = Theme.Paginator.Past
, visibleEvents = Data.PlaceCal.Events.eventsWithPartners (List.reverse (Data.PlaceCal.Events.onOrBeforeDate app.sharedData.events model.nowTime)) app.sharedData.partners
}
, Effect.none
)

ClickedAllFutureEvents ->
( { model
| filterBy = Theme.Paginator.Future
, visibleEvents = Data.PlaceCal.Events.eventsWithPartners (Data.PlaceCal.Events.afterDate app.sharedData.events model.nowTime) app.sharedData.partners
}
, Effect.none
)

GetTime newTime ->
( { model
| filterBy = Theme.Paginator.Day newTime
, nowTime = newTime
, visibleEvents =
Data.PlaceCal.Events.eventsWithPartners (Data.PlaceCal.Events.eventsFromDate app.sharedData.events newTime) app.sharedData.partners
}
, Effect.none
)

ScrollRight ->
( model
, Task.attempt (\_ -> NoOp)
(Theme.Paginator.scrollPagination Theme.Paginator.Right model.viewportWidth)
|> Effect.fromCmd
)

ScrollLeft ->
( model
, Task.attempt (\_ -> NoOp)
(Theme.Paginator.scrollPagination Theme.Paginator.Left model.viewportWidth)
|> Effect.fromCmd
)

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

NoOp ->
( model, Effect.none )
Theme.Page.Events.PaginatorMsg submsg ->
case submsg of
Theme.Paginator.ClickedDay posix ->
( { model
| filterByDate =
Theme.Paginator.Day posix
}
, Effect.none
)

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

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

Theme.Paginator.GetTime newTime ->
( { model
| filterByDate = Theme.Paginator.Day newTime
, nowTime = newTime
}
, Effect.none
)

Theme.Paginator.ScrollRight ->
( model
, Task.attempt (\_ -> Theme.Paginator.NoOp)
(Theme.Paginator.scrollPagination Theme.Paginator.Right model.viewportWidth)
|> Cmd.map Theme.Page.Events.fromPaginatorMsg
|> Effect.fromCmd
)

Theme.Paginator.ScrollLeft ->
( model
, Task.attempt (\_ -> Theme.Paginator.NoOp)
(Theme.Paginator.scrollPagination Theme.Paginator.Left model.viewportWidth)
|> Cmd.map Theme.Page.Events.fromPaginatorMsg
|> Effect.fromCmd
)

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

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

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


subscriptions : RouteParams -> UrlPath.UrlPath -> Shared.Model -> Model -> Sub Msg
Expand Down Expand Up @@ -168,15 +177,15 @@ view :
-> Shared.Model
-> Model
-> View (PagesMsg.PagesMsg Msg)
view _ _ model =
view app _ model =
{ title = t (PageMetaTitle (t EventsTitle))
, body =
[ Theme.PageTemplate.view
{ headerType = Just "pink"
, title = t EventsTitle
, bigText = { text = t EventsSummary, node = "h3" }
, smallText = Nothing
, innerContent = Just (Theme.Page.Events.viewEvents model)
, innerContent = Just (Theme.Page.Events.viewEvents (Data.PlaceCal.Events.eventsWithPartners app.sharedData.events app.sharedData.partners) model)
, outerContent = Nothing
}
|> Html.Styled.map PagesMsg.fromMsg
Expand Down
63 changes: 56 additions & 7 deletions app/Route/Index.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,79 @@ module Route.Index exposing (Model, Msg, RouteParams, route, Data, ActionData)
import BackendTask
import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import Effect
import FatalError
import Head
import Html.Styled
import PagesMsg
import RouteBuilder
import Shared
import Task
import Theme.Page.Index
import Theme.PageTemplate
import Theme.RegionSelector exposing (Msg(..))
import Time
import UrlPath
import View


type alias Model =
{}
{ filterByRegion : Int
, nowTime : Time.Posix
}


type alias Msg =
()
Theme.RegionSelector.Msg


type alias RouteParams =
{}


route : RouteBuilder.StatelessRoute RouteParams Data ActionData
init :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> ( Model, Effect.Effect Msg )
init app shared =
( { filterByRegion = Maybe.withDefault 0 shared.filterParam
, nowTime = app.sharedData.time
}
, Effect.none
)


update :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> Msg
-> Model
-> ( Model, Effect.Effect Msg )
update app _ msg model =
case msg of
ClickedSelector tagId ->
( { model
| filterByRegion = tagId
}
, Effect.none
)


subscriptions : RouteParams -> UrlPath.UrlPath -> Shared.Model -> Model -> Sub Msg
subscriptions _ _ _ _ =
Sub.none


route : RouteBuilder.StatefulRoute RouteParams Data ActionData Model Msg
route =
RouteBuilder.single
{ data = data, head = head }
|> RouteBuilder.buildNoState
{ view = view }
|> RouteBuilder.buildWithLocalState
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}


type alias Data =
Expand Down Expand Up @@ -64,8 +109,12 @@ head _ =
view :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> Model
-> View.View (PagesMsg.PagesMsg Msg)
view app _ =
view app _ model =
{ title = t SiteTitle
, body = [ Theme.Page.Index.view app.sharedData ]
, body =
[ Theme.Page.Index.view app.sharedData model
|> Html.Styled.map PagesMsg.fromMsg
]
}
58 changes: 51 additions & 7 deletions app/Route/Partners.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,73 @@ module Route.Partners exposing (Model, Msg, RouteParams, route, Data, ActionData
import BackendTask
import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import Effect
import FatalError
import Head
import Html.Styled
import PagesMsg
import RouteBuilder
import Shared
import Theme.Page.Partners
import Theme.PageTemplate
import Theme.RegionSelector exposing (Msg(..))
import UrlPath
import View


type alias Model =
{}
{ filterByRegion : Int }


type alias Msg =
()
Theme.RegionSelector.Msg


type alias RouteParams =
{}


route : RouteBuilder.StatelessRoute RouteParams Data ActionData
init :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> ( Model, Effect.Effect Msg )
init _ shared =
( { filterByRegion = Maybe.withDefault 0 shared.filterParam }
, Effect.none
)


update :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> Msg
-> Model
-> ( Model, Effect.Effect Msg )
update app _ msg model =
case msg of
ClickedSelector tagId ->
( { model
| filterByRegion = tagId
}
, Effect.none
)


subscriptions : RouteParams -> UrlPath.UrlPath -> Shared.Model -> Model -> Sub Msg
subscriptions _ _ _ _ =
Sub.none


route : RouteBuilder.StatefulRoute RouteParams Data ActionData Model Msg
route =
RouteBuilder.single
{ data = data, head = head }
|> RouteBuilder.buildNoState
{ view = view }
|> RouteBuilder.buildWithLocalState
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}


type alias Data =
Expand Down Expand Up @@ -64,16 +103,21 @@ head _ =
view :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> Model
-> View.View (PagesMsg.PagesMsg Msg)
view app _ =
view app _ model =
{ title = t (PageMetaTitle (t PartnersTitle))
, body =
[ Theme.PageTemplate.view
{ headerType = Just "pink"
, title = t PartnersTitle
, bigText = { text = t PartnersIntroSummary, node = "p" }
, smallText = Just [ t PartnersIntroDescription ]
, innerContent = Just (Theme.Page.Partners.viewPartners app.sharedData.partners)
, innerContent =
Just
(Theme.Page.Partners.viewPartners app.sharedData.partners model
|> Html.Styled.map PagesMsg.fromMsg
)
, outerContent = Nothing
}
]
Expand Down
Loading

0 comments on commit 43fb084

Please sign in to comment.