Skip to content

Commit

Permalink
Merge pull request #438 from GenderedIntelligence/feat/214-add-single…
Browse files Browse the repository at this point in the history
…-event-page-route

Feat/214 add single event page route
  • Loading branch information
katjam authored Sep 25, 2024
2 parents ec4d672 + 6500290 commit 24e1677
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 18 deletions.
20 changes: 10 additions & 10 deletions app/Route/Events.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ init :
-> ( Model, Effect.Effect Msg )
init app shared =
( { filterBy = Theme.Paginator.None
, visibleEvents = app.sharedData.events
, visibleEvents = eventsWithPartners app.sharedData.events app.sharedData.partners
, nowTime = Time.millisToPosix 0
, viewportWidth = 320
}
Expand All @@ -74,23 +74,23 @@ update app shared msg model =
( { model
| filterBy = Theme.Paginator.Day posix
, visibleEvents =
Data.PlaceCal.Events.eventsFromDate app.sharedData.events posix
eventsWithPartners (Data.PlaceCal.Events.eventsFromDate app.sharedData.events posix) app.sharedData.partners
}
, Effect.none
)

ClickedAllPastEvents ->
( { model
| filterBy = Theme.Paginator.Past
, visibleEvents = List.reverse (Data.PlaceCal.Events.onOrBeforeDate app.sharedData.events model.nowTime)
, visibleEvents = 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.afterDate app.sharedData.events model.nowTime
, visibleEvents = eventsWithPartners (Data.PlaceCal.Events.afterDate app.sharedData.events model.nowTime) app.sharedData.partners
}
, Effect.none
)
Expand All @@ -100,7 +100,7 @@ update app shared msg model =
| filterBy = Theme.Paginator.Day newTime
, nowTime = newTime
, visibleEvents =
Data.PlaceCal.Events.eventsFromDate app.sharedData.events newTime
eventsWithPartners (Data.PlaceCal.Events.eventsFromDate app.sharedData.events newTime) app.sharedData.partners
}
, Effect.none
)
Expand Down Expand Up @@ -156,11 +156,6 @@ data =
BackendTask.succeed ()


setPartnerName : Data.PlaceCal.Events.EventPartner -> Maybe String -> Data.PlaceCal.Events.EventPartner
setPartnerName oldEventPartner partnerName =
{ oldEventPartner | name = partnerName }


head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
head static =
Theme.PageTemplate.pageMetaTags
Expand Down Expand Up @@ -189,3 +184,8 @@ view app shared model =
|> Html.Styled.map PagesMsg.fromMsg
]
}


eventsWithPartners : List Data.PlaceCal.Events.Event -> List Data.PlaceCal.Partners.Partner -> List Data.PlaceCal.Events.Event
eventsWithPartners eventList partnerList =
Data.PlaceCal.Partners.addPartnerToEvents eventList partnerList
118 changes: 118 additions & 0 deletions app/Route/Events/Event_.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
module Route.Events.Event_ exposing (Model, Msg, RouteParams, route, Data, ActionData)

{-|
@docs Model, Msg, RouteParams, route, Data, ActionData
-}

import BackendTask
import BackendTask.Custom
import Browser.Dom
import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import Data.PlaceCal.Api
import Data.PlaceCal.Events
import Data.PlaceCal.Partners
import Effect
import FatalError
import Head
import Json.Encode
import PagesMsg
import RouteBuilder
import Shared
import Task
import Theme.EventPage
import Theme.PageTemplate
import Theme.TransMarkdown
import Time
import View


type alias Model =
{}


type alias Msg =
()


type alias RouteParams =
{ event : String }


route : RouteBuilder.StatelessRoute RouteParams Data ActionData
route =
RouteBuilder.preRender
{ data = data, pages = pages, head = head }
|> RouteBuilder.buildNoState
{ view = view }


type alias Data =
()


type alias ActionData =
BackendTask.BackendTask FatalError.FatalError (List RouteParams)


data : RouteParams -> BackendTask.BackendTask FatalError.FatalError Data
data _ =
BackendTask.succeed ()


pages : BackendTask.BackendTask FatalError.FatalError (List RouteParams)
pages =
BackendTask.map
(\eventData ->
eventData.allEvents
|> List.map (\event -> { event = event.id })
)
(Data.PlaceCal.Api.fetchAndCachePlaceCalData
"events"
Data.PlaceCal.Events.allEventsQuery
Data.PlaceCal.Events.eventsDecoder
)
|> BackendTask.allowFatal


head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
head app =
let
event =
Data.PlaceCal.Events.eventFromSlug app.routeParams.event app.sharedData.events
in
Theme.PageTemplate.pageMetaTags
{ title = EventTitle event.name
, description = EventMetaDescription event.name event.summary
, imageSrc = Nothing
}


view :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> View.View (PagesMsg.PagesMsg Msg)
view app shared =
let
event : Data.PlaceCal.Events.Event
event =
Data.PlaceCal.Events.eventFromSlug app.routeParams.event app.sharedData.events

eventWithPartner : Data.PlaceCal.Events.Event
eventWithPartner =
{ event | partner = Data.PlaceCal.Partners.eventPartnerFromId app.sharedData.partners event.partner.id }
in
{ title = t (PageMetaTitle event.name)
, body =
[ Theme.PageTemplate.view
{ headerType = Just "pink"
, title = t EventsTitle
, bigText = { text = event.name, node = "h3" }
, smallText = Nothing
, innerContent = Just (Theme.EventPage.viewEventInfo eventWithPartner)
, outerContent = Just (Theme.EventPage.viewButtons event)
}
]
}
22 changes: 16 additions & 6 deletions app/Route/Partners/Partner_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import FatalError
import Head
import Helpers.TransRoutes exposing (Route(..))
import Html.Styled
import Json.Encode
import PagesMsg
import RouteBuilder
import Shared
Expand Down Expand Up @@ -112,28 +111,32 @@ update :
-> Model
-> ( Model, Effect.Effect Msg )
update app shared msg model =
let
aPartner =
Data.PlaceCal.Partners.partnerFromSlug app.sharedData.partners app.routeParams.partner
in
case msg of
ClickedDay posix ->
( { model
| filterBy = Theme.Paginator.Day posix
, visibleEvents =
Data.PlaceCal.Events.eventsFromDate app.sharedData.events posix
eventsFromPartnerId aPartner.id (Data.PlaceCal.Events.eventsFromDate app.sharedData.events posix)
}
, Effect.none
)

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

ClickedAllFutureEvents ->
( { model
| filterBy = Theme.Paginator.Future
, visibleEvents = Data.PlaceCal.Events.afterDate app.sharedData.events model.nowTime
, visibleEvents = eventsFromPartnerId aPartner.id (Data.PlaceCal.Events.afterDate app.sharedData.events model.nowTime)
}
, Effect.none
)
Expand All @@ -143,7 +146,7 @@ update app shared msg model =
| filterBy = Theme.Paginator.Day newTime
, nowTime = newTime
, visibleEvents =
Data.PlaceCal.Events.eventsFromDate app.sharedData.events newTime
eventsFromPartnerId aPartner.id (Data.PlaceCal.Events.eventsFromDate app.sharedData.events newTime)
}
, Effect.none
)
Expand Down Expand Up @@ -220,7 +223,9 @@ view app shared model =
, innerContent =
Just
(Theme.PartnerPage.viewInfo model
{ partner = aPartner, events = app.sharedData.events }
{ partner = aPartner
, events = eventsFromPartnerId aPartner.id app.sharedData.events
}
)
, outerContent = Just (Theme.Global.viewBackButton (Helpers.TransRoutes.toAbsoluteUrl Partners) (t BackToPartnersLinkText))
}
Expand All @@ -242,3 +247,8 @@ pages =
Data.PlaceCal.Partners.partnersDecoder
)
|> BackendTask.allowFatal


eventsFromPartnerId : String -> List Data.PlaceCal.Events.Event -> List Data.PlaceCal.Events.Event
eventsFromPartnerId partnerId eventList =
List.filter (\event -> partnerId == event.partner.id) eventList
9 changes: 8 additions & 1 deletion src/Data/PlaceCal/Events.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Data.PlaceCal.Events exposing (Event, EventPartner, Realm(..), afterDate, emptyEvent, eventsData, eventsFromDate, eventsFromPartnerId, next4Events, onOrBeforeDate)
module Data.PlaceCal.Events exposing (Event, EventPartner, Realm(..), afterDate, allEventsQuery, emptyEvent, eventFromSlug, eventsData, eventsDecoder, eventsFromDate, eventsFromPartnerId, next4Events, onOrBeforeDate)

import BackendTask
import BackendTask.Custom
Expand Down Expand Up @@ -78,6 +78,13 @@ type Realm
= Online


eventFromSlug : String -> List Event -> Event
eventFromSlug eventId eventsList =
List.filter (\event -> event.id == eventId) eventsList
|> List.head
|> Maybe.withDefault emptyEvent


eventsFromPartnerId : List Event -> String -> List Event
eventsFromPartnerId eventsList id =
List.filter (\event -> event.partner.id == id) eventsList
Expand Down
9 changes: 8 additions & 1 deletion src/Data/PlaceCal/Partners.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, allPartnersQuery, eventPartnerFromId, partnerFromSlug, partnerNameFromId, partnerNamesFromIds, partnersData, partnersDecoder)
module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, addPartnerToEvents, allPartnersQuery, eventPartnerFromId, partnerFromSlug, partnerNameFromId, partnerNamesFromIds, partnersData, partnersDecoder)

import BackendTask
import BackendTask.Custom
Expand Down Expand Up @@ -195,3 +195,10 @@ eventPartnerFromId partnerList partnerId =
)
|> List.head
|> Maybe.withDefault { name = Nothing, maybeContactDetails = Nothing, maybeUrl = Nothing, id = partnerId }


addPartnerToEvents : List Data.PlaceCal.Events.Event -> List Partner -> List Data.PlaceCal.Events.Event
addPartnerToEvents eventList partnerList =
List.map
(\event -> { event | partner = eventPartnerFromId partnerList event.partner.id })
eventList
Loading

0 comments on commit 24e1677

Please sign in to comment.