From ec2c8916e0698fbbcd200395c908b6cdb0543d9b Mon Sep 17 00:00:00 2001 From: TreetopFlyer Date: Tue, 26 Apr 2022 12:04:39 -0400 Subject: [PATCH] alert toggling --- app.js | 87 ++++++++++++++++++++++++------------------------ testdata-03.json | 30 +++++++++++++++++ 2 files changed, 74 insertions(+), 43 deletions(-) create mode 100644 testdata-03.json diff --git a/app.js b/app.js index 513166c..5d3cd36 100644 --- a/app.js +++ b/app.js @@ -6,6 +6,7 @@ import { h, html, render } from "https://esm.sh/htm/preact"; import { useReducer, useState, useEffect, useLayoutEffect, useMemo, useRef } from 'https://esm.sh/preact/hooks'; import State01 from "./testdata-01.json" assert { type: "json" }; import State02 from "./testdata-02.json" assert { type: "json" }; +import State03 from "./testdata-03.json" assert { type: "json" }; const Styles = { @@ -41,6 +42,7 @@ const Styles = borderRadius: "5px", transition: "all 0.4s", color: "#fff", + textAlign: "center", } }; const PlayerID = "boxcast-player" @@ -55,7 +57,10 @@ const App = props => const [SelectedGet, SelectedSet] = useState(null); /** @type {Boxcast.StateBinding} */ - const [LiveGet, LiveSet] = useState(null); + const [LeadingGet, LeadingSet] = useState(null); + + /** @type {Boxcast.StateBinding} */ + const [AlertGet, AlertSet] = useState(false); /** @type {(inList:Array)=>Array} */ const SortStart = (inList) => { @@ -70,21 +75,6 @@ const App = props => useEffect(()=> { Player.current = boxcast(`#${PlayerID}`); - /* - Player.current.loadChannel(props.channel, - { - showTitle: true, - showDescription: true, - showCountdown: true, - - //selectedBroadcastId: "yo8sefnnejvw3cx3vhup", - showRelated: false, - onLoadBroadcast: console.log, - - autoplay: true, - defaultVideo: "next" - }); - */ return; /** @type {()=>Promise} */ @@ -105,40 +95,41 @@ const App = props => // on new list useEffect(()=> { - let live; + let leading; for(let i=0; i - { - // alert("New session is starting.") - - } - , [LiveGet]); // on new video selected useEffect(()=> { - Player.current.loadChannel(props.channel, - { + const settings = { selectedBroadcastId: SelectedGet?.id, showTitle: true, showDescription: true, @@ -146,7 +137,9 @@ const App = props => showRelated: false, autoplay: true, defaultVideo: "next" - }); + }; + + Player.current.loadChannel(props.channel, settings); } , [SelectedGet]) @@ -155,7 +148,8 @@ const App = props =>
- + +
${ @@ -164,14 +158,19 @@ const App = props => { item: item, previous: ListGet[index-1], - priority: item.id == LiveGet?.id, + priority: item.id == LeadingGet?.id, selected: item.id == SelectedGet?.id, select: ()=>SelectedSet(item) } )) }
- <${BroadcastAlert}> + ${ AlertGet ? h(BroadcastAlert, + { + broadcast: LeadingGet, + clickWatch: ()=>{ SelectedSet(LeadingGet); AlertSet(false); }, + clickDismiss: ()=>{ AlertSet(false) } + }) : null } `; } @@ -223,13 +222,15 @@ const BroadcastItem = ({item, previous, priority, selected, select}) => `; }; -const BroadcastAlert = () => +/** @type { (props:{broadcast:Boxcast.Broadcast, clickWatch:()=>void, clickDismiss:()=>void})=>any } */ +const BroadcastAlert = ({broadcast, clickWatch, clickDismiss}) => { return html`
- X -

A new session is starting.

- + X +

A new session is starting:

+

${broadcast.name}

+
`; } diff --git a/testdata-03.json b/testdata-03.json new file mode 100644 index 0000000..9d79f01 --- /dev/null +++ b/testdata-03.json @@ -0,0 +1,30 @@ +[ + { + "id": "a3fvb7xs5yrl7xr50lyr", + "name": "Welcome and Main Session 1", + "starts_at": "2022-05-02T18:55:00Z", + "stops_at": "2022-05-02T20:20:00Z", + "timeframe": "past", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "welcome-and-main-session-1-sfry0q5zi5fpjtxzsnih", + "tags": [] + }, + { + "id": "ur7p1uqz6rl3dx7drvgf", + "name": "Breakout Session - Alistair Begg", + "starts_at": "2022-05-02T20:25:00Z", + "stops_at": "2022-05-02T21:45:00Z", + "timeframe": "past", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "breakout-session---alistair-begg-gkkr1jga58geasofpnmd", + "tags": [] + } +] \ No newline at end of file