From 88516c82b20ca0ba1750aa22f360804eb3f9bef7 Mon Sep 17 00:00:00 2001 From: TreetopFlyer Date: Tue, 26 Apr 2022 16:00:04 -0400 Subject: [PATCH] revert selecteget to id --- app.js | 102 +++++++++++++++++++++++++++++++++++++++-------------- index.html | 2 +- 2 files changed, 77 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index f5fb873..270ab68 100644 --- a/app.js +++ b/app.js @@ -7,14 +7,11 @@ import styled, { css, keyframes } from 'https://esm.sh/styled-components'; import { createElement as h, useState, useEffect, useRef } from 'https://esm.sh/react'; import { createRoot } from "https://esm.sh/react-dom/client"; +/* 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 = -{ - -}; +*/ const StyledRoot = styled.div` .Partition @@ -26,6 +23,32 @@ const StyledRoot = styled.div` position: relative; display: flex; padding: 5px 0 5px 0; + + .Pointer + { + width: 75px; + .Badge + { + display: inline-block; + border-radius: 20px; + padding: 2px 8px; + font-size: 12px; + font-weight: 900; + font-family: sans-serif; + letter-spacing: 0.1em; + + &.Next + { + background: yellow; + color: black; + } + &.Live + { + background: limegreen; + color: white; + } + } + } .Time { width: 75px; @@ -33,9 +56,29 @@ const StyledRoot = styled.div` font-size: 16px; text-align: right; } - .Pointer + .Title { - width: 75px; + flex: 1; + } + .Control + { + button + { + appearance: none; + display: block; + width: 80px; + padding: 5px 10px 5px 10px; + background: black; + cursor: pointer; + border: none; + color: white; + font-size: 10px; + font-weight: 900; + } + button[disabled] + { + background: grey; + } } } .Alert @@ -79,7 +122,7 @@ const App = props => /** @type {Boxcast.StateBinding>} */ const [ListGet, ListSet] = useState([]); - /** @type {Boxcast.StateBinding} */ + /** @type {Boxcast.StateBinding} */ const [SelectedGet, SelectedSet] = useState(null); /** @type {Boxcast.StateBinding} */ @@ -102,7 +145,6 @@ const App = props => { Player.current = boxcast(`#${PlayerID}`); - return; /** @type {()=>Promise} */ const Ping = async () => { @@ -131,9 +173,9 @@ const App = props => if(SelectedGet == null) // if nothing is selected select the leading event { - SelectedSet(leading); + SelectedSet(leading.id); } - else if(SelectedGet?.id != leading?.id) // if something is selected other than the leading event, alert the user + else if(SelectedGet != leading?.id) // if something is selected other than the leading event, alert the user { AlertSet(true); } @@ -145,7 +187,10 @@ const App = props => if(ListGet.length) // if there are events but theres no leading event, clear leading and select the first event { LeadingSet(null); - SelectedSet(ListGet[0]); + if(SelectedGet == null) + { + SelectedSet(ListGet[0].id); + } AlertSet(false); } } @@ -156,7 +201,7 @@ const App = props => useEffect(()=> { const settings = { - selectedBroadcastId: SelectedGet?.id, + selectedBroadcastId: SelectedGet, showTitle: true, showDescription: true, showCountdown: true, @@ -167,35 +212,38 @@ const App = props => Player.current.loadChannel(props.channel, settings); } - , [SelectedGet]) + , [SelectedGet]); return html` <${StyledRoot}>
+
${ - ListGet.map( (item, index) => h( - BroadcastItem, + ListGet.map( (item, index) => + { + return h(BroadcastItem, { item: item, previous: ListGet[index-1], priority: item.id == LeadingGet?.id, - selected: item.id == SelectedGet?.id, - select: ()=>SelectedSet(item) - } - )) + selected: item.id == SelectedGet, + select: ()=>SelectedSet(item.id) + }); + }) }
{ AlertSet(false); }}>Dismiss ✕

A new session is starting:

${LeadingGet?.name}

- +
`; @@ -207,17 +255,19 @@ const BroadcastItem = ({item, previous, priority, selected, select}) => let pointerText; if(item.timeframe == "current" || item.timeframe == "preroll") { - pointerText = `Live:`; + pointerText = html`
Live
`; } else if (priority) { - pointerText = `Next:`; + pointerText = html``; } let partition; if(!previous || (previous.start.Date !== item.start.Date)) { - partition = html`

${item.start.Day}, ${item.start.Month} ${item.start.Date}

` + partition = html`

+ ${item.start.Day}, ${item.start.Month} ${item.start.Date} +

`; } let buttonText; @@ -240,7 +290,7 @@ const BroadcastItem = ({item, previous, priority, selected, select}) => return html` ${ partition } -
+
${ pointerText }
${item.start.Hours}:${item.start.Minutes} ${item.start.M}
${item.name} @@ -274,4 +324,4 @@ const DateParse = (inDateString) => }; /** @type {(inChannel:string, inSelector:string)=>void} */ -export default (inChannel, inSelector) => createRoot(document.querySelector(inSelector)).render(h(App, {channel:inChannel, interval:50000})); \ No newline at end of file +export default (inChannel, inSelector) => createRoot(document.querySelector(inSelector)).render(h(App, {channel:inChannel, interval:5000})); \ No newline at end of file diff --git a/index.html b/index.html index f12fdb7..192c493 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@