Skip to content

Commit

Permalink
feat: add a switch
Browse files Browse the repository at this point in the history
refactor the code for readability
and make the iframe look better

Co-Authored-By: Dom Lander <[email protected]>
  • Loading branch information
mxdvl and domlander committed Jun 12, 2024
1 parent c8948ec commit 98fe4b9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
11 changes: 11 additions & 0 deletions common/app/conf/switches/JournalismSwitches.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package conf.switches

import conf.switches.Expiry.never
import java.time.LocalDate

trait JournalismSwitches {

Expand Down Expand Up @@ -73,4 +74,14 @@ trait JournalismSwitches {
sellByDate = never,
exposeClientSide = true,
)

val Euro2024Header = Switch(
SwitchGroup.Journalism,
name = "euro-2024-header",
description = "Show the Euro 2024 interactive atom header on football pages",
owners = Seq(Owner.withEmail("[email protected]")),
safeState = Off,
sellByDate = LocalDate.of(2024, 7, 15),
exposeClientSide = true,
)
}
2 changes: 1 addition & 1 deletion common/app/views/fragments/atoms/interactive.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@if(shouldFence) {
<iframe class="interactive-atom-fence" srcdoc="@iframeBody.toString"></iframe>
} else {
<figure class="interactive interactive-atom">
<figure class="interactive interactive-atom" style="margin: 0;">
<style>
@HtmlFormat.raw(interactive.css)
</style>
Expand Down
45 changes: 16 additions & 29 deletions sport/app/football/controllers/FixturesController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.time.LocalDate
import pa.FootballTeam
import play.api.mvc.{Action, AnyContent, ControllerComponents}
import scala.concurrent.Future
import conf.switches.Switches

class FixturesController(
val competitionsService: CompetitionsService,
Expand Down Expand Up @@ -86,35 +87,21 @@ class FixturesController(

private def renderTagFixtures(date: LocalDate, tag: String): Action[AnyContent] =
getTagFixtures(date, tag)
.map(result =>
Action.async { implicit request =>
tag match {
case "euro-2024" =>
val id = "/atom/interactive/interactives/2023/01/euros-2024/tables-euros-2024-header"
val edition = Edition(request)
contentApiClient
.getResponse(contentApiClient.item(id, edition))
.map(_.interactive.map(InteractiveAtom.make(_)))
.map(
renderMatchList(
result._1,
result._2,
filters,
_,
),
)
case _ =>
Future(
renderMatchList(
result._1,
result._2,
filters,
None,
),
)
.map {
case (page, fixtures) =>
Action.async { implicit request =>
tag match {
case "euro-2024" if Switches.Euro2024Header.isSwitchedOn =>
val id = "/atom/interactive/interactives/2023/01/euros-2024/tables-euros-2024-header"
val edition = Edition(request)
contentApiClient
.getResponse(contentApiClient.item(id, edition))
.map(_.interactive.map(InteractiveAtom.make(_)))
.map(renderMatchList(page, fixtures, filters, _))
case _ =>
Future.successful(renderMatchList(page, fixtures, filters, None))
}
}

},
)
}
.getOrElse(Action(NotFound))
}
15 changes: 9 additions & 6 deletions sport/app/football/controllers/MatchDayController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import contentapi.ContentApiClient
import model.content.InteractiveAtom
import common.ImplicitControllerExecutionContext
import scala.concurrent.Future
import conf.switches.Switches

class MatchDayController(
val competitionsService: CompetitionsService,
Expand Down Expand Up @@ -55,12 +56,14 @@ class MatchDayController(
else s" ${competition.fullName} matches"
val page = new FootballPage(s"football/$competitionTag/live", "football", webTitle)
val matches = CompetitionMatchDayList(competitionsService.competitions, competition.id, date)
val edition = Edition(request)
val id = "/atom/interactive/interactives/2023/01/euros-2024/match-centre-euros-2024-header"
contentApiClient
.getResponse(contentApiClient.item(id, edition))
.map(_.interactive.map(InteractiveAtom.make(_)))
.map(renderMatchList(page, matches, filters, _))
if (Switches.Euro2024Header.isSwitchedOn) {
val id = "/atom/interactive/interactives/2023/01/euros-2024/match-centre-euros-2024-header"
val edition = Edition(request)
contentApiClient
.getResponse(contentApiClient.item(id, edition))
.map(_.interactive.map(InteractiveAtom.make(_)))
.map(renderMatchList(page, matches, filters, _))
} else Future.successful(renderMatchList(page, matches, filters, None))
}
.getOrElse {
Future.successful(NotFound)
Expand Down
6 changes: 5 additions & 1 deletion sport/app/football/views/matchList/matchesPage.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
<div class="l-side-margins">
<article id="article" class="content content--footballfixtures" itemprop="mainContentOfPage" itemtype="http://schema.org/Article" role="main">
<div class="content__main">
@maybeAtom.map{ atom =>
<div class="gs-container">
@views.html.fragments.atoms.interactive(atom, shouldFence = false)
</div>
}
<div class="gs-container">
@maybeAtom.map(atom => views.html.fragments.atoms.interactive(atom, shouldFence = false))
<div class="content__main-column">
<h2 class="hide-on-mobile-if-localnav content__inline-section page-type--football">
@matchesList.getPageTitle(Edition(request))
Expand Down

0 comments on commit 98fe4b9

Please sign in to comment.