Add monthly most host to LCARS display

This commit is contained in:
2023-07-15 19:04:14 +00:00
parent 8baf204516
commit 4b12ea0d6d
2 changed files with 61 additions and 4 deletions

View File

@@ -34,10 +34,6 @@ export function LCARS1Display(props) {
</p>
}
<div className='display-scores'>
<DisplayScores />
</div>
<div className='display-scores'>
<DisplayMonthlyScores />
</div>
@@ -46,6 +42,10 @@ export function LCARS1Display(props) {
<DisplayHosting />
</div>
<div className='display-scores'>
<DisplayMonthlyHosting />
</div>
<div className='display-usage'>
<DisplayUsage token={token} name={'trotec'} />
</div>
@@ -239,3 +239,39 @@ export function DisplayHosting(props) {
</>
);
};
export function DisplayMonthlyHosting(props) {
const { token, name } = props;
const [scores, setScores] = useState(false);
const getScores = () => {
requester('/hosting/monthly_high_scores/', 'GET')
.then(res => {
setScores(res);
})
.catch(err => {
console.log(err);
setScores(false);
});
};
useEffect(() => {
getScores();
const interval = setInterval(getScores, 60000);
return () => clearInterval(interval);
}, []);
return (
<>
<Header size='large'>Monthly Most Host</Header>
{scores && scores.slice(0, 5).map((x, i) =>
<div key={i}>
<Header size='medium'>#{i+1} {x.name}. {i === 0 ? '🚀' : ''}</Header>
<p>{x.hours.toFixed(2)} hours</p>
</div>
)}
</>
);
};