53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import {useCallback, useState} from 'react';
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
|
|
import 'react-tabs/style/react-tabs.css';
|
|
|
|
import {useClient} from '@/react/context/client.js';
|
|
import {useEcsTick} from '@/react/context/ecs.js';
|
|
import {useMainEntity} from '@/react/context/main-entity.js';
|
|
|
|
import styles from './devtools.module.css';
|
|
|
|
import Tiles from './devtools/tiles.jsx';
|
|
|
|
export default function Devtools({
|
|
eventsChannel,
|
|
}) {
|
|
const client = useClient();
|
|
const mainEntityRef = useMainEntity();
|
|
const [mainEntityJson, setMainEntityJson] = useState('');
|
|
const onEcsTick = useCallback((payload, ecs) => {
|
|
if (!mainEntityRef.current) {
|
|
return;
|
|
}
|
|
setMainEntityJson(JSON.stringify(ecs.get(mainEntityRef.current), null, 2));
|
|
}, [mainEntityRef]);
|
|
useEcsTick(onEcsTick);
|
|
return (
|
|
<div className={styles.devtools}>
|
|
<Tabs>
|
|
<TabList>
|
|
<Tab>Dashboard</Tab>
|
|
<Tab>Tiles</Tab>
|
|
</TabList>
|
|
<TabPanel>
|
|
<div className={styles.dashboard}>
|
|
<form>
|
|
<div className={styles.engineBar}>
|
|
<div>{Math.round(client.rtt * 100) / 100}rtt</div>
|
|
<div>{Math.round(((client.throughput.down * 8) / 1024) * 10) / 10}kb/s down</div>
|
|
<div>{Math.round(((client.throughput.up * 8) / 1024) * 10) / 10}kb/s up</div>
|
|
</div>
|
|
</form>
|
|
<pre><code><small>{mainEntityJson}</small></code></pre>
|
|
</div>
|
|
</TabPanel>
|
|
<TabPanel>
|
|
<Tiles
|
|
eventsChannel={eventsChannel}
|
|
/>
|
|
</TabPanel>
|
|
</Tabs>
|
|
</div>
|
|
);
|
|
} |