From e07fc8c5101181202d37e037ea014ceb01351a14 Mon Sep 17 00:00:00 2001 From: Benjamin Jones Date: Mon, 17 May 2021 01:08:25 +0200 Subject: [PATCH] added timezone adaptation, trailer etc --- package.json | 1 + src/components/Info/index.js | 14 ++++++++- src/components/Info/styles.js | 18 ++++++++---- src/components/Svg/Play.js | 1 + src/components/Video/index.js | 2 +- src/components/VideoEmbed/index.js | 44 +++++++++++++++++++++++++++++ src/components/VideoEmbed/styles.js | 41 +++++++++++++++++++++++++++ src/data/config.js | 12 ++------ src/data/strings.js | 2 ++ src/hooks/data.js | 13 ++++++++- 10 files changed, 131 insertions(+), 17 deletions(-) create mode 100644 src/components/VideoEmbed/index.js create mode 100644 src/components/VideoEmbed/styles.js diff --git a/package.json b/package.json index 93bde34..25b9893 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@peertube/embed-api": "^0.0.4", "axios": "^0.21.1", "date-fns": "^2.19.0", + "date-fns-tz": "^1.1.4", "ical": "^0.8.0", "ical.js": "^1.4.0", "markdown-to-jsx": "^7.1.2", diff --git a/src/components/Info/index.js b/src/components/Info/index.js index 901da88..4375d9a 100644 --- a/src/components/Info/index.js +++ b/src/components/Info/index.js @@ -1,11 +1,13 @@ /* eslint-disable react/prop-types */ import { h, Fragment } from 'preact' +import { useState, useEffect } from 'preact/hooks' import { isFuture, isPast } from 'date-fns' import { H1 } from '../Text' import Markdown from '../Markdown' import translations from '../../data/strings' import InfoLayout from '../InfoLayout' +import TrailerEmbed from '../VideoEmbed' import { VideoCard, Title, @@ -19,8 +21,12 @@ import credits from '../../data/credits.md' import Button from '../Button' import PlaySvg from '../Svg/Play' import { colours } from '../../assets/theme' +import config from '../../data/config' const Info = ({ data, loading, infoActive, setInfoActive, currentVideo }) => { + const [trailerActive, setTrailerActive] = useState(false) + const toggleTrailerActive = () => + setTrailerActive(trailerState => !trailerState) const pastStreams = data && data.length ? data.filter(feeditem => isPast(new Date(feeditem.end))) @@ -44,6 +50,12 @@ const Info = ({ data, loading, infoActive, setInfoActive, currentVideo }) => { return ( + {trailerActive && ( + + )} {infoActive && setInfoActive(false)} />} {!loading && ( @@ -51,7 +63,7 @@ const Info = ({ data, loading, infoActive, setInfoActive, currentVideo }) => {

The Para-Real:

Finding the Future in Unexpected Places

{intro} - diff --git a/src/components/Info/styles.js b/src/components/Info/styles.js index abf9c6d..729c073 100644 --- a/src/components/Info/styles.js +++ b/src/components/Info/styles.js @@ -1,5 +1,5 @@ -import { format } from 'date-fns' import { h, Fragment } from 'preact' +import { zonedTimeToUtc, utcToZonedTime, format } from 'date-fns-tz' import styled from 'styled-components' import { colours, textSizes } from '../../assets/theme' import config from '../../data/config' @@ -121,15 +121,19 @@ export const VideoCard = ({ hasPassed, videoUrl, }) => { - console.log('start', start) + const startDate = new Date(start) + const utcDate = zonedTimeToUtc(startDate, 'Europe/Berlin') + + const { timeZone } = Intl.DateTimeFormat().resolvedOptions() + const zonedDate = utcToZonedTime(utcDate, timeZone) return ( {`${hasPassed ? translations.en.streamDatePast : ''}`} {hasPassed - ? format(new Date(start), 'dd/MM/yy') - : format(new Date(start), 'do LLLL y // HH:mm')} + ? format(zonedDate, 'dd/MM/yy') + : format(zonedDate, 'do LLLL y // HH:mm')} {videoUrl && hasPassed ? ( @@ -144,7 +148,11 @@ export const VideoCard = ({
)}

{description}

- + + + ) } diff --git a/src/components/Svg/Play.js b/src/components/Svg/Play.js index 68264ab..410606a 100644 --- a/src/components/Svg/Play.js +++ b/src/components/Svg/Play.js @@ -4,6 +4,7 @@ import { number, string } from 'prop-types' const Play = ({ size = '24', colour = 'inherit', ...rest }) => ( { />