} */
const Selected = useState(false);
useEffect(()=>
{
Ping();
const timer = setInterval(Ping, props.interval);
return ()=>clearInterval(timer);
}
, []);
/** @type {()=>Promise} */
const Ping = async () =>
{
const response = await fetch(`https://rest.boxcast.com/channels/${props.channel}/broadcasts?s=starts_at&l=1000`);
const json = await response.json();
ListSet(json);
};
return html`
${
ListGet.map(item => html`<${BroadcastItem} item=${item} active=${Selected} />`)
}
`;
}
/** @type {(props:{item:Boxcast.Broadcast, active:Boxcast.StateBinding})=>any} */
const BroadcastItem = ({item, active}) =>
{
const startDate = useMemo(()=>DateParse(item.starts_at), [item.starts_at]);
return html`
active[1](item)}>
${startDate.Month} ${startDate.Date}
${item.name}
${startDate.Hours}:${startDate.Minutes} ${startDate.M}
${
active[0]?.id == item.id ? html`
Active` : null
}
`;
};
/** @type {(inDate:string)=>Boxcast.Date} */
const DateParse = (inDateString) =>
{
let date = new Date(inDateString);
/** @type {Boxcast.Date} */
let obj = {
Zone: date.toString().match(/\(([A-Za-z\s].*)\)/),
Day: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][date.getDay()],
Month: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][date.getMonth()],
Date: date.getDate(),
Hours: date.getHours(),
Minutes: date.getMinutes(),
};
obj.Zone = obj.Zone ? obj.Zone[1] : "local time";
obj.M = obj.Hours >= 12 ? "PM" : "AM";
obj.Hours %= 12;
if(obj.Hours == 0){ obj.Hours = 12; }
if(obj.Minutes < 10){ obj.Minutes = "0"+obj.Minutes; }
return obj;
};
export default App;