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); const ref = useRef(null); const goFullScreen = () => { if ('wakeLock' in navigator) { navigator.wakeLock.request('screen'); } ref.current.requestFullscreen({ navigationUI: 'hide' }).then(() => { setFullElement(true); }); }; return (
{!fullElement &&

}
); }; export function LCARS2Display(props) { const { token } = props; const [fullElement, setFullElement] = useState(false); const ref = useRef(null); const goFullScreen = () => { if ('wakeLock' in navigator) { navigator.wakeLock.request('screen'); } ref.current.requestFullscreen({ navigationUI: 'hide' }).then(() => { setFullElement(true); }); }; return (
{!fullElement &&

}
); }; 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); }, []); const inUse = usage && moment().unix() - usage.track.time <= 60; const showUsage = usage && inUse && usage.track.username === usage.username; return ( <>
Trotec Usage
{showUsage ? :

Waiting for job

} ); }; 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 ( <>
Pinball High Scores
{scores && scores.slice(0, 5).map((x, i) =>
#{i+1} — {x.name}. {i === 0 ? '👑' : ''}

{x.score.toLocaleString()}

)} ); }; 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 ( <>
Monthly High Scores
{scores && scores.slice(0, 5).map((x, i) =>
#{i+1} — {x.name}. {i === 0 ? '🧙' : ''}

{x.score.toLocaleString()}

)} ); }; 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 ( <>
Most Host
{scores && scores.slice(0, 5).map((x, i) =>
#{i+1} — {x.name}. {i === 0 ? : ''}

{x.hours.toFixed(2)} hours

)} ); };