-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a69638
commit 6adc8fb
Showing
12 changed files
with
313 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
dotcom-rendering/src/components/Football/LiveScoresPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { FELiveScoresType } from 'src/types/sports'; | ||
import { css } from '@emotion/react'; | ||
import { MatchList } from './MatchList'; | ||
|
||
interface Props { | ||
liveScores: FELiveScoresType; | ||
} | ||
|
||
const sportsPageStyles = css` | ||
padding-top: 0; | ||
padding-bottom: 2.25rem; | ||
`; | ||
|
||
const titleStyles = css` | ||
font-size: 1.25rem; | ||
line-height: 1.4375rem; | ||
font-family: 'Guardian Egyptian Web', Georgia, serif; | ||
font-weight: 900; | ||
box-sizing: border-box; | ||
padding: 0.375rem 0 0.75rem; | ||
border-top: 0.0625rem dotted; | ||
`; | ||
|
||
const matchContainerStyles = css` | ||
clear: both; | ||
`; | ||
|
||
export const LiveScoresPage = ({ liveScores }: Props) => { | ||
return ( | ||
<article id="article" css={[sportsPageStyles]} role="main"> | ||
<div> | ||
<h2 css={[titleStyles]}>{liveScores.pageTitle}</h2> | ||
<div | ||
css={[matchContainerStyles]} | ||
data-show-more-contains="football-matches" | ||
> | ||
{liveScores.matchesGroupedByDateAndCompetition.map( | ||
(item) => { | ||
return ( | ||
<MatchList dateCompetition={item}></MatchList> | ||
); | ||
}, | ||
)} | ||
</div> | ||
</div> | ||
</article> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { DateCompetitionMatch } from 'src/types/sports'; | ||
|
||
interface Props { | ||
dateCompetition: DateCompetitionMatch; | ||
} | ||
|
||
export const MatchList: React.FC<Props> = ({ dateCompetition }) => { | ||
return ( | ||
<> | ||
<div>{dateCompetition.date}</div> | ||
{dateCompetition.competitions.map((comp) => ( | ||
<div key={comp.competition.id}> | ||
<h3>{comp.competition.fullName}</h3> | ||
<table> | ||
<thead hidden> | ||
<tr> | ||
<th>Match status / kick off time</th> | ||
<th>Match details</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{comp.matches.map((match) => ( | ||
<tr key={match.id} id={match.id}> | ||
<td>{match.date.toString()}</td> | ||
<td> | ||
<strong>{match.homeTeam.name}</strong>{' '} | ||
vs{' '} | ||
<strong>{match.awayTeam.name}</strong> | ||
{match.type === 'MatchDay' && | ||
match.liveMatch && ( | ||
<span> (Live!)</span> | ||
)} | ||
{match.type === 'Fixture' && ( | ||
<span> (Fixture)</span> | ||
)} | ||
{match.type === 'Result' && ( | ||
<span> (Result)</span> | ||
)} | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
))} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"pageTitle": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"pageTitle" | ||
], | ||
"$schema": "http://json-schema.org/draft-07/schema#" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { RequestHandler } from 'express'; | ||
import { validateAsSports } from '../model/validate'; | ||
import { renderSportsHtml } from './render.sports.web'; | ||
import { makePrefetchHeader } from './lib/header'; | ||
|
||
export const handleSports: RequestHandler = ({ body }, res) => { | ||
console.log(`marji: `); | ||
const matchList = validateAsSports(body); | ||
console.log(matchList); | ||
|
||
const { html, prefetchScripts } = renderSportsHtml({ | ||
sports: matchList, | ||
}); | ||
|
||
res.status(200).set('Link', makePrefetchHeader(prefetchScripts)).send(html); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { FELiveScoresType } from '../types/sports'; | ||
import { LiveScoresPage } from '../components/Football/LiveScoresPage'; | ||
import { renderToStringWithEmotion } from '../lib/emotion'; | ||
import { getPathFromManifest } from '../lib/assets'; | ||
import { polyfillIO } from '../lib/polyfill.io'; | ||
import { isString } from '@guardian/libs'; | ||
|
||
interface Props { | ||
sports: FELiveScoresType; | ||
} | ||
|
||
export const renderSportsHtml = ({ | ||
sports, | ||
}: Props): { html: string; prefetchScripts: string[] } => { | ||
const { html } = renderToStringWithEmotion( | ||
<LiveScoresPage liveScores={sports} />, | ||
); | ||
|
||
/** | ||
* The highest priority scripts. | ||
* These scripts have a considerable impact on site performance. | ||
* Only scripts critical to application execution may go in here. | ||
* Please talk to the dotcom platform team before adding more. | ||
* Scripts will be executed in the order they appear in this array | ||
*/ | ||
const prefetchScripts = [ | ||
polyfillIO, | ||
getPathFromManifest('client.web', 'frameworks.js'), | ||
getPathFromManifest('client.web', 'index.js'), | ||
].filter(isString); | ||
|
||
return { html: html, prefetchScripts }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
type Round = { | ||
roundNumber: string; | ||
name?: string; | ||
}; | ||
type Stage = { | ||
stageNumber: String; | ||
}; | ||
|
||
type Venue = { | ||
id: string; | ||
name: string; | ||
}; | ||
|
||
type MatchDayTeam = { | ||
id: string; | ||
name: string; | ||
score?: number; | ||
htScore?: number; | ||
aggregateScore?: number; | ||
scorers?: string; | ||
}; | ||
|
||
type FootballMatch = { | ||
id: string; | ||
date: Date; | ||
stage: Stage; | ||
round: Round; | ||
leg: string; | ||
homeTeam: MatchDayTeam; | ||
awayTeam: MatchDayTeam; | ||
venue?: Venue; | ||
comments?: string; | ||
}; | ||
|
||
type Fixture = FootballMatch & { | ||
type: 'Fixture'; | ||
competition?: Competition; | ||
}; | ||
|
||
type MatchDay = FootballMatch & { | ||
type: 'MatchDay'; | ||
liveMatch: boolean; | ||
result: boolean; | ||
previewAvailable: boolean; | ||
reportAvailable: boolean; | ||
lineupsAvailable: boolean; | ||
matchStatus: string; | ||
attendance?: string; | ||
referee?: string; | ||
}; | ||
|
||
type Result = FootballMatch & { | ||
type: 'Result'; | ||
reportAvailable: boolean; | ||
attendance?: string; | ||
referee?: string; | ||
}; | ||
|
||
type LiveMatch = FootballMatch & { | ||
type: 'LiveMatch'; | ||
status: string; | ||
attendance?: string; | ||
referee?: string; | ||
}; | ||
|
||
type FootballMatchType = Fixture | MatchDay | Result | LiveMatch; | ||
|
||
type LeagueStats = { | ||
played: number; | ||
won: number; | ||
drawn: number; | ||
lost: number; | ||
goalsFor: number; | ||
goalsAgainst: number; | ||
}; | ||
|
||
type LeagueTeam = { | ||
id: string; | ||
name: string; | ||
rank: number; | ||
total: LeagueStats; | ||
home: LeagueStats; | ||
away: LeagueStats; | ||
goalDifference: number; | ||
points: number; | ||
}; | ||
|
||
type LeagueTableEntry = { stageNumber: string; round: Round; team: LeagueTeam }; | ||
|
||
type Competition = { | ||
id: string; | ||
url: string; | ||
fullName: string; | ||
shortName: string; | ||
nation: string; | ||
startDate?: string; | ||
matches: FootballMatch[]; | ||
leagueTable: LeagueTableEntry[]; | ||
showInTeamsList: boolean; | ||
tableDividers: number[]; | ||
finalMatchSVG?: string; | ||
}; | ||
|
||
type CompetitionMatch = { | ||
competition: Competition; | ||
matches: FootballMatchType[]; | ||
}; | ||
|
||
export type DateCompetitionMatch = { | ||
date: string; | ||
competitions: CompetitionMatch[]; | ||
}; | ||
|
||
export type FELiveScoresType = { | ||
pageTitle: string; | ||
type: string; | ||
matchesGroupedByDateAndCompetition: DateCompetitionMatch[]; | ||
}; |