0
owncast/web/pages/index2.tsx
2020-10-10 18:48:29 -07:00

41 lines
1.0 KiB
TypeScript

import React, { useState, useEffect } from 'react';
import { BROADCASTER, fetchData, FETCH_INTERVAL } from './utils/apis';
import Main from './home';
export default function Admin() {
const [broadcasterStatus, setBroadcasterStatus] = useState({});
const [count, setCount] = useState(0);
const getBroadcastStatus = async () => {
try {
const result = await fetchData(BROADCASTER);
const broadcastActive = !!result.broadcaster;
console.log("====",{count, result})
setBroadcasterStatus({ ...result, broadcastActive });
setCount(c => c + 1);
} catch (error) {
setBroadcasterStatus({ ...broadcasterStatus, message: error.message });
}
};
useEffect(() => {
let getStatusIntervalId = null;
getBroadcastStatus();
getStatusIntervalId = setInterval(getBroadcastStatus, FETCH_INTERVAL);
// returned function will be called on component unmount
return () => {
clearInterval(getStatusIntervalId);
}
}, [])
return (
<Main {...broadcasterStatus} />
);
}