Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike/share data #437

Merged
merged 8 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/Route/About.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import FatalError
import Head
import Html.Styled
import Json.Decode as Decode
import Markdown.Block
import PagesMsg
Expand Down
191 changes: 191 additions & 0 deletions app/Route/Events.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
module Route.Events exposing (Model, Msg, RouteParams, route, Data, ActionData)

{-|

@docs Model, Msg, RouteParams, route, Data, ActionData

-}

import BackendTask
import Browser.Dom
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
import Html.Styled
import PagesMsg
import RouteBuilder
import Shared
import Task
import Theme.EventsPage
import Theme.PageTemplate
import Theme.Paginator exposing (Msg(..))
import Time
import UrlPath
import View exposing (View)


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


type alias Msg =
Theme.Paginator.Msg


type alias RouteParams =
{}


init :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> ( Model, Effect.Effect Msg )
init app shared =
( { filterBy = Theme.Paginator.None
, visibleEvents = app.sharedData.events
, nowTime = Time.millisToPosix 0
, viewportWidth = 320
}
, Effect.batch
[ Task.perform GetTime Time.now |> Effect.fromCmd
, Task.perform GotViewport Browser.Dom.getViewport |> Effect.fromCmd
]
)


update :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> Msg
-> Model
-> ( Model, Effect.Effect Msg )
update app shared msg model =
case msg of
ClickedDay posix ->
( { model
| filterBy = Theme.Paginator.Day posix
, visibleEvents =
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)
}
, Effect.none
)

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

GetTime newTime ->
( { model
| filterBy = Theme.Paginator.Day newTime
, nowTime = newTime
, visibleEvents =
Data.PlaceCal.Events.eventsFromDate app.sharedData.events newTime
}
, 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 )


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.buildWithLocalState
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}


type alias Data =
()


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


data : BackendTask.BackendTask FatalError.FatalError Data
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
{ title = EventsTitle
, description = EventsMetaDescription
, imageSrc = Nothing
}


view :
RouteBuilder.App Data ActionData RouteParams
-> Shared.Model
-> Model
-> View (PagesMsg.PagesMsg Msg)
view app shared 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.EventsPage.viewEvents model)
, outerContent = Nothing
}
|> Html.Styled.map PagesMsg.fromMsg
]
}
22 changes: 7 additions & 15 deletions app/Route/News.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import BackendTask
import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import Data.PlaceCal.Articles
import Data.PlaceCal.Partners
import FatalError
import Head
import Html.Styled
import PagesMsg
import RouteBuilder
import Shared
Expand Down Expand Up @@ -43,7 +41,7 @@ route =


type alias Data =
List Data.PlaceCal.Articles.Article
()


type alias ActionData =
Expand All @@ -52,17 +50,7 @@ type alias ActionData =

data : BackendTask.BackendTask FatalError.FatalError Data
data =
BackendTask.map2
(\articleData partnerData ->
List.map
(\article ->
{ article | partnerIds = Data.PlaceCal.Partners.partnerNamesFromIds partnerData article.partnerIds }
)
articleData.allArticles
)
Data.PlaceCal.Articles.articlesData
(BackendTask.map (\partnersData -> partnersData.allPartners) Data.PlaceCal.Partners.partnersData)
|> BackendTask.allowFatal
BackendTask.succeed ()


head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
Expand All @@ -87,7 +75,11 @@ view app shared =
, bigText = { text = t NewsDescription, node = "h3" }
, smallText = Nothing
, innerContent = Nothing
, outerContent = Just (Theme.NewsPage.viewNewsList app.data)
, outerContent =
Just
(Theme.NewsPage.viewNewsList
(Data.PlaceCal.Articles.replacePartnerIdWithName app.sharedData.articles app.sharedData.partners)
)
}
]
}
47 changes: 17 additions & 30 deletions app/Route/News/NewsItem_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import BackendTask
import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import Data.PlaceCal.Articles
import Data.PlaceCal.Partners
import FatalError
import Head
import Helpers.TransRoutes
import Html.Styled
import PagesMsg
import RouteBuilder
import Shared
Expand Down Expand Up @@ -44,43 +42,28 @@ route =


type alias Data =
Data.PlaceCal.Articles.Article
()


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


data : RouteParams -> BackendTask.BackendTask FatalError.FatalError Data
data routeParams =
BackendTask.map2
(\articlesData partnersData ->
Maybe.withDefault Data.PlaceCal.Articles.emptyArticle
((articlesData.allArticles
|> List.filter (\newsItem -> Helpers.TransRoutes.stringToSlug newsItem.title == routeParams.newsItem)
)
|> List.head
)
|> partnerIdsToNames partnersData
)
Data.PlaceCal.Articles.articlesData
(BackendTask.map (\partnersData -> partnersData.allPartners) Data.PlaceCal.Partners.partnersData)
|> BackendTask.allowFatal


partnerIdsToNames :
List Data.PlaceCal.Partners.Partner
-> Data.PlaceCal.Articles.Article
-> Data.PlaceCal.Articles.Article
partnerIdsToNames partnersData newsItem =
{ newsItem | partnerIds = Data.PlaceCal.Partners.partnerNamesFromIds partnersData newsItem.partnerIds }
data _ =
BackendTask.succeed ()


head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
head app =
let
article =
Data.PlaceCal.Articles.articleFromSlug app.routeParams.newsItem app.sharedData.articles app.sharedData.partners
in
Theme.PageTemplate.pageMetaTags
{ title = NewsItemTitle app.data.title
, description = NewsItemMetaDescription app.data.title (String.join " & " app.data.partnerIds)
{ title = NewsItemTitle article.title
, description =
NewsItemMetaDescription article.title (String.join " & " article.partnerIds)
, imageSrc = Nothing
}

Expand All @@ -90,14 +73,18 @@ view :
-> Shared.Model
-> View.View (PagesMsg.PagesMsg Msg)
view app shared =
{ title = t (NewsItemTitle app.data.title)
let
article =
Data.PlaceCal.Articles.articleFromSlug app.routeParams.newsItem app.sharedData.articles app.sharedData.partners
in
{ title = t (NewsItemTitle article.title)
, body =
[ Theme.PageTemplate.view
{ headerType = Just "invisible"
, title = t NewsTitle
, bigText = { text = app.data.title, node = "h3" }
, bigText = { text = article.title, node = "h3" }
, smallText = Nothing
, innerContent = Just (Theme.NewsItemPage.viewArticle app.data)
, innerContent = Just (Theme.NewsItemPage.viewArticle article)
, outerContent = Nothing
}
]
Expand Down
9 changes: 3 additions & 6 deletions app/Route/Partners.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ module Route.Partners exposing (Model, Msg, RouteParams, route, Data, ActionData
import BackendTask
import Copy.Keys exposing (Key(..))
import Copy.Text exposing (t)
import Data.PlaceCal.Partners
import FatalError
import Head
import Html.Styled
import PagesMsg
import RouteBuilder
import Shared
Expand Down Expand Up @@ -42,7 +40,7 @@ route =


type alias Data =
List Data.PlaceCal.Partners.Partner
()


type alias ActionData =
Expand All @@ -51,8 +49,7 @@ type alias ActionData =

data : BackendTask.BackendTask FatalError.FatalError Data
data =
BackendTask.map (\sharedData -> sharedData.allPartners) Data.PlaceCal.Partners.partnersData
|> BackendTask.allowFatal
BackendTask.succeed ()


head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
Expand All @@ -76,7 +73,7 @@ view app shared =
, title = t PartnersTitle
, bigText = { text = t PartnersIntroSummary, node = "p" }
, smallText = Just [ t PartnersIntroDescription ]
, innerContent = Just (Theme.PartnersPage.viewPartners app.data)
, innerContent = Just (Theme.PartnersPage.viewPartners app.sharedData.partners)
, outerContent = Nothing
}
]
Expand Down
Loading