alert toggling
This commit is contained in:
parent
d3e7e3152f
commit
ec2c8916e0
87
app.js
87
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 { useReducer, useState, useEffect, useLayoutEffect, useMemo, useRef } from 'https://esm.sh/preact/hooks';
|
||||||
import State01 from "./testdata-01.json" assert { type: "json" };
|
import State01 from "./testdata-01.json" assert { type: "json" };
|
||||||
import State02 from "./testdata-02.json" assert { type: "json" };
|
import State02 from "./testdata-02.json" assert { type: "json" };
|
||||||
|
import State03 from "./testdata-03.json" assert { type: "json" };
|
||||||
|
|
||||||
const Styles =
|
const Styles =
|
||||||
{
|
{
|
||||||
@ -41,6 +42,7 @@ const Styles =
|
|||||||
borderRadius: "5px",
|
borderRadius: "5px",
|
||||||
transition: "all 0.4s",
|
transition: "all 0.4s",
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
|
textAlign: "center",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const PlayerID = "boxcast-player"
|
const PlayerID = "boxcast-player"
|
||||||
@ -55,7 +57,10 @@ const App = props =>
|
|||||||
const [SelectedGet, SelectedSet] = useState(null);
|
const [SelectedGet, SelectedSet] = useState(null);
|
||||||
|
|
||||||
/** @type {Boxcast.StateBinding<Boxcast.Broadcast|null>} */
|
/** @type {Boxcast.StateBinding<Boxcast.Broadcast|null>} */
|
||||||
const [LiveGet, LiveSet] = useState(null);
|
const [LeadingGet, LeadingSet] = useState(null);
|
||||||
|
|
||||||
|
/** @type {Boxcast.StateBinding<boolean>} */
|
||||||
|
const [AlertGet, AlertSet] = useState(false);
|
||||||
|
|
||||||
/** @type {(inList:Array<Boxcast.Broadcast>)=>Array<Boxcast.Broadcast>} */
|
/** @type {(inList:Array<Boxcast.Broadcast>)=>Array<Boxcast.Broadcast>} */
|
||||||
const SortStart = (inList) => {
|
const SortStart = (inList) => {
|
||||||
@ -70,21 +75,6 @@ const App = props =>
|
|||||||
useEffect(()=>
|
useEffect(()=>
|
||||||
{
|
{
|
||||||
Player.current = boxcast(`#${PlayerID}`);
|
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;
|
return;
|
||||||
/** @type {()=>Promise} */
|
/** @type {()=>Promise} */
|
||||||
@ -105,40 +95,41 @@ const App = props =>
|
|||||||
// on new list
|
// on new list
|
||||||
useEffect(()=>
|
useEffect(()=>
|
||||||
{
|
{
|
||||||
let live;
|
let leading;
|
||||||
for(let i=0; i<ListGet.length; i++)
|
for(let i=0; i<ListGet.length; i++)
|
||||||
{
|
{
|
||||||
if(ListGet[i].timeframe != "past")
|
if(ListGet[i].timeframe != "past")
|
||||||
{
|
{
|
||||||
live = ListGet[i];
|
leading = ListGet[i];
|
||||||
break;
|
LeadingSet(leading);
|
||||||
}
|
|
||||||
}
|
if(SelectedGet == null) // if nothing is selected select the leading event
|
||||||
if(LiveGet?.id != live?.id)
|
|
||||||
{
|
{
|
||||||
console.log("new video starting")
|
SelectedSet(leading);
|
||||||
}
|
}
|
||||||
if(SelectedGet?.id != live?.id)
|
else if(SelectedGet?.id != leading?.id) // if something is selected other than the leading event, alert the user
|
||||||
{
|
{
|
||||||
console.log("would you like to switch?");
|
AlertSet(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ListGet.length) // if there are events but theres no leading event, clear leading and select the first event
|
||||||
|
{
|
||||||
|
LeadingSet(null);
|
||||||
|
SelectedSet(ListGet[0]);
|
||||||
|
AlertSet(false);
|
||||||
}
|
}
|
||||||
LiveSet(live);
|
|
||||||
}
|
}
|
||||||
, [ListGet]);
|
, [ListGet]);
|
||||||
|
|
||||||
// on new event started
|
|
||||||
useEffect(()=>
|
|
||||||
{
|
|
||||||
// alert("New session is starting.")
|
|
||||||
|
|
||||||
}
|
|
||||||
, [LiveGet]);
|
|
||||||
|
|
||||||
// on new video selected
|
// on new video selected
|
||||||
useEffect(()=>
|
useEffect(()=>
|
||||||
{
|
{
|
||||||
Player.current.loadChannel(props.channel,
|
const settings = {
|
||||||
{
|
|
||||||
selectedBroadcastId: SelectedGet?.id,
|
selectedBroadcastId: SelectedGet?.id,
|
||||||
showTitle: true,
|
showTitle: true,
|
||||||
showDescription: true,
|
showDescription: true,
|
||||||
@ -146,7 +137,9 @@ const App = props =>
|
|||||||
showRelated: false,
|
showRelated: false,
|
||||||
autoplay: true,
|
autoplay: true,
|
||||||
defaultVideo: "next"
|
defaultVideo: "next"
|
||||||
});
|
};
|
||||||
|
|
||||||
|
Player.current.loadChannel(props.channel, settings);
|
||||||
}
|
}
|
||||||
, [SelectedGet])
|
, [SelectedGet])
|
||||||
|
|
||||||
@ -155,7 +148,8 @@ const App = props =>
|
|||||||
<div id=${PlayerID}></div>
|
<div id=${PlayerID}></div>
|
||||||
<div>
|
<div>
|
||||||
<button onClick=${()=>ListSet(SortStart(State01))}>testdata-01</button>
|
<button onClick=${()=>ListSet(SortStart(State01))}>testdata-01</button>
|
||||||
<button onClick=${()=>ListSet(SortStart(State02))}>testdata-01</button>
|
<button onClick=${()=>ListSet(SortStart(State02))}>testdata-02</button>
|
||||||
|
<button onClick=${()=>ListSet(SortStart(State03))}>testdata-03</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="Boxcast-Playlist">
|
<div class="Boxcast-Playlist">
|
||||||
${
|
${
|
||||||
@ -164,14 +158,19 @@ const App = props =>
|
|||||||
{
|
{
|
||||||
item: item,
|
item: item,
|
||||||
previous: ListGet[index-1],
|
previous: ListGet[index-1],
|
||||||
priority: item.id == LiveGet?.id,
|
priority: item.id == LeadingGet?.id,
|
||||||
selected: item.id == SelectedGet?.id,
|
selected: item.id == SelectedGet?.id,
|
||||||
select: ()=>SelectedSet(item)
|
select: ()=>SelectedSet(item)
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<${BroadcastAlert}><//>
|
${ AlertGet ? h(BroadcastAlert,
|
||||||
|
{
|
||||||
|
broadcast: LeadingGet,
|
||||||
|
clickWatch: ()=>{ SelectedSet(LeadingGet); AlertSet(false); },
|
||||||
|
clickDismiss: ()=>{ AlertSet(false) }
|
||||||
|
}) : null }
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -223,13 +222,15 @@ const BroadcastItem = ({item, previous, priority, selected, select}) =>
|
|||||||
</div>`;
|
</div>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BroadcastAlert = () =>
|
/** @type { (props:{broadcast:Boxcast.Broadcast, clickWatch:()=>void, clickDismiss:()=>void})=>any } */
|
||||||
|
const BroadcastAlert = ({broadcast, clickWatch, clickDismiss}) =>
|
||||||
{
|
{
|
||||||
return html`
|
return html`
|
||||||
<div style=${Styles.Alert}>
|
<div style=${Styles.Alert}>
|
||||||
<span>X</span>
|
<span onClick=${clickDismiss}>X</span>
|
||||||
<h4>A new session is starting.</h4>
|
<h4>A new session is starting:</h4>
|
||||||
<button>Watch Now</button>
|
<p>${broadcast.name}</p>
|
||||||
|
<button onClick=${clickWatch}>Watch Now</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
30
testdata-03.json
Normal file
30
testdata-03.json
Normal file
@ -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": []
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user