2022-08-09 07:21:40 +00:00
|
|
|
import React, { useRef, useState, useEffect } from 'react';
|
|
|
|
import { useParams } from 'react-router-dom';
|
|
|
|
import moment from 'moment-timezone';
|
|
|
|
import { Button, Container, Header } from 'semantic-ui-react';
|
|
|
|
import { requester } from './utils.js';
|
|
|
|
import { TrotecUsage } from './Usage.js';
|
|
|
|
|
|
|
|
const deviceNames = {
|
|
|
|
'trotec': {title: 'Trotec', device: 'TROTECS300'},
|
|
|
|
};
|
|
|
|
|
|
|
|
export function LCARS1Display(props) {
|
|
|
|
const { token } = props;
|
|
|
|
const [fullElement, setFullElement] = useState(false);
|
2023-04-05 04:54:49 +00:00
|
|
|
const ref = useRef(null);
|
|
|
|
|
|
|
|
const goFullScreen = () => {
|
|
|
|
if ('wakeLock' in navigator) {
|
|
|
|
navigator.wakeLock.request('screen');
|
|
|
|
}
|
|
|
|
|
|
|
|
ref.current.requestFullscreen({ navigationUI: 'hide' }).then(() => {
|
|
|
|
setFullElement(true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<div className='display' ref={ref}>
|
|
|
|
|
|
|
|
{!fullElement &&
|
|
|
|
<p>
|
|
|
|
<Button onClick={goFullScreen}>Fullscreen</Button>
|
|
|
|
</p>
|
|
|
|
}
|
|
|
|
|
|
|
|
<div className='display-scores'>
|
|
|
|
<DisplayScores />
|
|
|
|
</div>
|
|
|
|
|
2023-05-02 06:09:58 +00:00
|
|
|
<div className='display-scores'>
|
|
|
|
<DisplayMonthlyScores />
|
|
|
|
</div>
|
|
|
|
|
2023-04-05 04:54:49 +00:00
|
|
|
<div className='display-scores'>
|
|
|
|
<DisplayHosting />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='display-usage'>
|
|
|
|
<DisplayUsage token={token} name={'trotec'} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export function LCARS2Display(props) {
|
|
|
|
const { token } = props;
|
|
|
|
const [fullElement, setFullElement] = useState(false);
|
2022-08-09 07:21:40 +00:00
|
|
|
const ref = useRef(null);
|
|
|
|
|
|
|
|
const goFullScreen = () => {
|
|
|
|
if ('wakeLock' in navigator) {
|
|
|
|
navigator.wakeLock.request('screen');
|
|
|
|
}
|
|
|
|
|
|
|
|
ref.current.requestFullscreen({ navigationUI: 'hide' }).then(() => {
|
|
|
|
setFullElement(true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<div className='display' ref={ref}>
|
|
|
|
|
|
|
|
{!fullElement &&
|
|
|
|
<p>
|
|
|
|
<Button onClick={goFullScreen}>Fullscreen</Button>
|
|
|
|
</p>
|
|
|
|
}
|
|
|
|
|
2023-01-18 01:01:27 +00:00
|
|
|
<div className='display-scores'>
|
|
|
|
<DisplayScores />
|
|
|
|
</div>
|
2022-08-09 07:21:40 +00:00
|
|
|
|
2023-03-09 17:34:08 +00:00
|
|
|
<div className='display-scores'>
|
|
|
|
<DisplayHosting />
|
|
|
|
</div>
|
2022-08-09 07:21:40 +00:00
|
|
|
</div>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export function DisplayUsage(props) {
|
|
|
|
const { token, name } = props;
|
|
|
|
const title = deviceNames[name].title;
|
|
|
|
const device = deviceNames[name].device;
|
|
|
|
const [usage, setUsage] = useState(false);
|
|
|
|
|
|
|
|
const getUsage = () => {
|
|
|
|
requester('/stats/usage_data/?device='+device, 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setUsage(res);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
setUsage(false);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
getUsage();
|
|
|
|
const interval = setInterval(getUsage, 60000);
|
|
|
|
return () => clearInterval(interval);
|
|
|
|
}, []);
|
|
|
|
|
2023-01-18 05:38:48 +00:00
|
|
|
const inUse = usage && moment().unix() - usage.track.time <= 60;
|
|
|
|
const showUsage = usage && inUse && usage.track.username === usage.username;
|
2022-08-09 07:21:40 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-01-18 01:01:27 +00:00
|
|
|
<Header size='large'>Trotec Usage</Header>
|
|
|
|
|
2022-08-09 07:21:40 +00:00
|
|
|
{showUsage ?
|
|
|
|
<TrotecUsage usage={usage} />
|
|
|
|
:
|
2023-01-18 01:01:27 +00:00
|
|
|
<p className='stat'>
|
|
|
|
Waiting for job
|
|
|
|
</p>
|
2022-08-09 07:21:40 +00:00
|
|
|
}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2023-01-18 01:01:27 +00:00
|
|
|
|
|
|
|
export function DisplayScores(props) {
|
|
|
|
const { token, name } = props;
|
|
|
|
const [scores, setScores] = useState(false);
|
|
|
|
|
|
|
|
const getScores = () => {
|
|
|
|
requester('/pinball/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'>Pinball High Scores</Header>
|
|
|
|
|
2023-02-15 00:18:30 +00:00
|
|
|
{scores && scores.slice(0, 5).map((x, i) =>
|
2023-01-18 01:01:27 +00:00
|
|
|
<div key={i}>
|
2023-01-24 03:43:25 +00:00
|
|
|
<Header size='medium'>#{i+1} — {x.name}. {i === 0 ? '👑' : ''}</Header>
|
2023-01-18 01:01:27 +00:00
|
|
|
<p>{x.score.toLocaleString()}</p>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2023-03-09 17:34:08 +00:00
|
|
|
|
2023-05-02 06:09:58 +00:00
|
|
|
export function DisplayMonthlyScores(props) {
|
|
|
|
const { token, name } = props;
|
|
|
|
const [scores, setScores] = useState(false);
|
|
|
|
|
|
|
|
const getScores = () => {
|
|
|
|
requester('/pinball/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 High Scores</Header>
|
|
|
|
|
|
|
|
{scores && scores.slice(0, 5).map((x, i) =>
|
|
|
|
<div key={i}>
|
|
|
|
<Header size='medium'>#{i+1} — {x.name}. {i === 0 ? '🧙' : ''}</Header>
|
|
|
|
<p>{x.score.toLocaleString()}</p>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-03-09 17:34:08 +00:00
|
|
|
export function DisplayHosting(props) {
|
|
|
|
const { token, name } = props;
|
|
|
|
const [scores, setScores] = useState(false);
|
|
|
|
|
|
|
|
const getScores = () => {
|
|
|
|
requester('/hosting/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'>Most Host</Header>
|
|
|
|
|
|
|
|
{scores && scores.slice(0, 5).map((x, i) =>
|
|
|
|
<div key={i}>
|
|
|
|
<Header size='medium'>#{i+1} — {x.name}. {i === 0 ? <img className='toast' src='/toast.png' /> : ''}</Header>
|
|
|
|
<p>{x.hours.toFixed(2)} hours</p>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|