-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
216 additions
and
216 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react" | ||
import useSWR from "swr" | ||
import styles from "../styles/Home.module.css" | ||
import { TextCountdown } from "./text_countdown" | ||
|
||
const COUNTDOWN_FORMATS = { | ||
immediate: "", forFuture: "", forPast: `%@ without Fauna`, | ||
days: (days) => (days > 1 ? `${days} days` : `${days} day`), | ||
hours: (hours) => (hours > 1 ? `${hours} hours` : `${hours} hour`), | ||
minutes: (minutes) => (minutes > 1 ? `${minutes} minutes` : `${minutes} minute`), | ||
seconds: (seconds) => (seconds > 1 ? `${seconds} seconds` : `${seconds} second`), | ||
separator: ", " | ||
} | ||
|
||
async function fetchPastStream(url) { | ||
const response = await fetch(url) | ||
const apiJSON = await response.json() | ||
|
||
return { | ||
link: apiJSON.result.videoLink, | ||
title: apiJSON.result.title, | ||
date: new Date(apiJSON.result.endActual) | ||
} | ||
} | ||
|
||
export function PastStreamCounter(props) { | ||
const { data, isValidating } = useSWR("/api/past_stream", fetchPastStream, { | ||
revalidateOnFocus: false, | ||
revalidateOnMount: true, | ||
revalidateOnReconnect: false, | ||
revalidateIfStale: true, | ||
refreshInterval: 90000, | ||
}) | ||
|
||
if (isValidating) { | ||
return null | ||
} | ||
|
||
return <div className={`${styles.streamInfo} ${styles.pastStreamInfo}`}> | ||
<a href={data?.link}> | ||
<TextCountdown to={data?.date} formatStrings={COUNTDOWN_FORMATS} /> | ||
</a> | ||
</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,29 @@ | ||
import React from "react" | ||
import styles from "../styles/Home.module.css" | ||
import { TextCountdown } from "./text_countdown" | ||
|
||
const COUNTDOWN_FORMATS = { | ||
immediate: "(Now!)", | ||
forFuture: "(in %@)", | ||
forPast: "(%@ ago)", | ||
} | ||
|
||
export function VideoBox(props) { | ||
return <div className={`${styles.videoBox}`}> | ||
<div className={styles.vstack}> | ||
{props.caption? | ||
<p className={`${styles.videoBoxCaption}`}> | ||
{props.caption} {" "} | ||
{(props.showCountdown && props.info.startTime)? | ||
<span className={styles.countdown}><TextCountdown to={props.info.startTime} formatStrings={COUNTDOWN_FORMATS} /></span> | ||
: null | ||
} | ||
</p> | ||
: null | ||
} | ||
<p><a href={props.info.link}>{props.info.title}</a></p> | ||
{props.info.isMembersOnly ? <p>(for Faunatics only!)</p> : null} | ||
</div> | ||
{props.info.thumbnail ? <img src={props.info.thumbnail} alt="thumbnail" width={120} /> : null} | ||
</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,7 @@ | ||
import { STREAM_STATUS, STREAM_TYPE } from "../../common/enums" | ||
import { getPastStream } from "../../server/data_sources" | ||
|
||
export default async function handler(req, res) { | ||
const pastStream = await getPastStream() | ||
return res.status(200).json({ result: pastStream }) | ||
} |
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
Oops, something went wrong.