Skip to content

Commit

Permalink
Re-jig events data views and add content to index
Browse files Browse the repository at this point in the history
  • Loading branch information
katjam committed Oct 4, 2024
1 parent 24e1677 commit c2fe91e
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 109 deletions.
24 changes: 9 additions & 15 deletions app/Route/Events.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Browser.Navigation
import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import Data.PlaceCal.Events
import Data.PlaceCal.Partners
import Effect
import FatalError
import Head
Expand Down Expand Up @@ -49,9 +48,9 @@ init :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> ( Model, Effect.Effect Msg )
init app shared =
init app _ =
( { filterBy = Theme.Paginator.None
, visibleEvents = eventsWithPartners app.sharedData.events app.sharedData.partners
, visibleEvents = Data.PlaceCal.Events.eventsWithPartners app.sharedData.events app.sharedData.partners
, nowTime = Time.millisToPosix 0
, viewportWidth = 320
}
Expand All @@ -68,29 +67,29 @@ update :
-> Msg
-> Model
-> ( Model, Effect.Effect Msg )
update app shared msg model =
update app _ msg model =
case msg of
ClickedDay posix ->
( { model
| filterBy = Theme.Paginator.Day posix
, visibleEvents =
eventsWithPartners (Data.PlaceCal.Events.eventsFromDate app.sharedData.events posix) app.sharedData.partners
Data.PlaceCal.Events.eventsWithPartners (Data.PlaceCal.Events.eventsFromDate app.sharedData.events posix) app.sharedData.partners
}
, Effect.none
)

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


head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
head static =
head _ =
Theme.PageTemplate.pageMetaTags
{ title = EventsTitle
, description = EventsMetaDescription
Expand All @@ -170,7 +169,7 @@ view :
-> Shared.Model
-> Model
-> View (PagesMsg.PagesMsg Msg)
view app shared model =
view _ _ model =
{ title = t (PageMetaTitle (t EventsTitle))
, body =
[ Theme.PageTemplate.view
Expand All @@ -184,8 +183,3 @@ 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
6 changes: 2 additions & 4 deletions app/Route/Events/Event_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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
Expand All @@ -25,7 +24,6 @@ import Task
import Theme.EventPage
import Theme.PageTemplate
import Theme.TransMarkdown
import Time
import View


Expand Down Expand Up @@ -94,15 +92,15 @@ view :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> View.View (PagesMsg.PagesMsg Msg)
view app shared =
view app _ =
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 }
{ event | partner = Data.PlaceCal.Events.eventPartnerFromId app.sharedData.partners event.partner.id }
in
{ title = t (PageMetaTitle event.name)
, body =
Expand Down
59 changes: 17 additions & 42 deletions app/Route/Index.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,36 @@ module Route.Index exposing (Model, Msg, RouteParams, route, Data, ActionData)
-}

import BackendTask
import Effect
import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import FatalError
import Head
import Html.Styled
import PagesMsg
import RouteBuilder
import Shared
import UrlPath
import Theme.IndexPage
import Theme.PageTemplate
import View


type alias Model =
{}


type Msg
= NoOp
type alias Msg =
()


type alias RouteParams =
{}


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


init :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> ( Model, Effect.Effect Msg )
init app shared =
( {}, Effect.none )


update :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> Msg
-> Model
-> ( Model, Effect.Effect Msg )
update app shared msg model =
case msg of
NoOp ->
( model, Effect.none )


subscriptions : RouteParams -> UrlPath.UrlPath -> Shared.Model -> Model -> Sub Msg
subscriptions routeParams path shared model =
Sub.none
|> RouteBuilder.buildNoState
{ view = view }


type alias Data =
Expand All @@ -82,15 +54,18 @@ data =

head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
head app =
[]
Theme.PageTemplate.pageMetaTags
{ title = SiteTitle
, description = IndexMetaDescription
, imageSrc = Nothing
}


view :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> Model
-> View.View (PagesMsg.PagesMsg Msg)
view app shared model =
{ title = "Temporary index"
, body = [ Html.Styled.h2 [] [ Html.Styled.text "Temporary index" ] ]
view app shared =
{ title = t SiteTitle
, body = [ Theme.IndexPage.view app.sharedData ]
}
35 changes: 27 additions & 8 deletions src/Data/PlaceCal/Events.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Data.PlaceCal.Events exposing (Event, EventPartner, Realm(..), afterDate, allEventsQuery, emptyEvent, eventFromSlug, eventsData, eventsDecoder, eventsFromDate, eventsFromPartnerId, next4Events, onOrBeforeDate)
module Data.PlaceCal.Events exposing (Event, EventPartner, afterDate, allEventsQuery, eventFromSlug, eventPartnerFromId, eventsData, eventsDecoder, eventsFromDate, eventsWithPartners, next4Events, onOrBeforeDate)

import BackendTask
import BackendTask.Custom
import Data.PlaceCal.Api
import Data.PlaceCal.Partners
import FatalError
import Helpers.TransDate as TransDate
import Json.Decode
Expand Down Expand Up @@ -74,8 +75,9 @@ emptyEvent =
}


type Realm
= Online

--type Realm
-- = Online


eventFromSlug : String -> List Event -> Event
Expand All @@ -85,11 +87,6 @@ eventFromSlug eventId eventsList =
|> Maybe.withDefault emptyEvent


eventsFromPartnerId : List Event -> String -> List Event
eventsFromPartnerId eventsList id =
List.filter (\event -> event.partner.id == id) eventsList


eventsFromDate : List Event -> Time.Posix -> List Event
eventsFromDate eventsList fromDate =
List.filter
Expand Down Expand Up @@ -122,6 +119,28 @@ next4Events allEvents fromTime =
List.take 4 (eventsFromDate allEvents fromTime)


eventPartnerFromId : List Data.PlaceCal.Partners.Partner -> String -> EventPartner
eventPartnerFromId partnerList partnerId =
List.filter (\partner -> partner.id == partnerId) partnerList
|> List.map
(\partner ->
{ name = Just partner.name
, maybeContactDetails = partner.maybeContactDetails
, id = partner.id
, maybeUrl = partner.maybeUrl
}
)
|> List.head
|> Maybe.withDefault { name = Nothing, maybeContactDetails = Nothing, maybeUrl = Nothing, id = partnerId }


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



----------------------------
-- DataSource query & decode
Expand Down
32 changes: 1 addition & 31 deletions src/Data/PlaceCal/Partners.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, addPartnerToEvents, allPartnersQuery, eventPartnerFromId, partnerFromSlug, partnerNameFromId, partnerNamesFromIds, partnersData, partnersDecoder)
module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, allPartnersQuery, partnerFromSlug, partnerNamesFromIds, partnersData, partnersDecoder)

import BackendTask
import BackendTask.Custom
import Data.PlaceCal.Api
import Data.PlaceCal.Events exposing (EventPartner)
import FatalError
import Json.Decode
import Json.Decode.Pipeline
Expand Down Expand Up @@ -168,37 +167,8 @@ partnerFromSlug partnerList id =
|> Maybe.withDefault emptyPartner


partnerNameFromId : List Partner -> String -> Maybe String
partnerNameFromId partnerList id =
List.filter (\partner -> partner.id == id) partnerList
|> List.map (\partner -> partner.name)
|> List.head


partnerNamesFromIds : List Partner -> List String -> List String
partnerNamesFromIds partnerList idList =
-- If the partner isn't in our sites partners, it won't be in the list
List.filter (\partner -> List.member partner.id idList) partnerList
|> List.map (\partner -> partner.name)


eventPartnerFromId : List Partner -> String -> EventPartner
eventPartnerFromId partnerList partnerId =
List.filter (\partner -> partner.id == partnerId) partnerList
|> List.map
(\partner ->
{ name = Just partner.name
, maybeContactDetails = partner.maybeContactDetails
, id = partner.id
, maybeUrl = partner.maybeUrl
}
)
|> 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
3 changes: 1 addition & 2 deletions src/Theme/EventPage.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import Helpers.TransDate
import Helpers.TransRoutes
import Html.Styled exposing (Html, a, div, h4, hr, p, section, text, time)
import Html.Styled.Attributes exposing (css, href, target)
import Theme.Global exposing (darkBlue, linkStyle, normalFirstParagraphStyle, pink, smallInlineTitleStyle, withMediaMediumDesktopUp, withMediaSmallDesktopUp, withMediaTabletLandscapeUp, withMediaTabletPortraitUp)
import Theme.PageTemplate
import Theme.Global exposing (linkStyle, normalFirstParagraphStyle, pink, smallInlineTitleStyle, withMediaMediumDesktopUp, withMediaTabletLandscapeUp, withMediaTabletPortraitUp)
import Theme.TransMarkdown


Expand Down
14 changes: 7 additions & 7 deletions src/Theme/EventsPage.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import Css exposing (Style, alignItems, batch, block, borderBottomColor, borderB
import Css.Global exposing (descendants, typeSelector)
import Css.Transitions exposing (transition)
import Data.PlaceCal.Events
import Data.PlaceCal.Partners
import Effect
import Helpers.TransDate as TransDate
import Helpers.TransRoutes as TransRoutes exposing (Route(..))
import Html.Styled exposing (Html, a, article, div, h4, li, p, section, span, text, time, ul)
import Html.Styled.Attributes exposing (css, href)
import RouteBuilder
import Shared
import Task
import Theme.Global exposing (borderTransition, colorTransition, introTextLargeStyle, pink, white, withMediaSmallDesktopUp, withMediaTabletLandscapeUp, withMediaTabletPortraitUp)
import Theme.PageTemplate
import Theme.Paginator
import Theme.PartnersPage
import Time


viewEvents :
{ localModel
| filterBy : Theme.Paginator.Filter
, nowTime : Time.Posix
, visibleEvents : List Data.PlaceCal.Events.Event
}
-> Html Theme.Paginator.Msg
viewEvents model =
section [ css [ eventsContainerStyle ] ]
[ Theme.Paginator.viewPagination model
Expand Down
Loading

0 comments on commit c2fe91e

Please sign in to comment.