silphius/app/react/components/devtools.jsx

38 lines
1.0 KiB
React
Raw Normal View History

2024-11-09 21:15:52 -06:00
import {useEffect} from 'react';
2024-07-08 15:49:23 -05:00
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
import 'react-tabs/style/react-tabs.css';
2024-07-07 23:30:48 -05:00
import styles from './devtools.module.css';
2024-11-09 21:15:52 -06:00
import TabComponents from './devtools/components.js';
2024-07-08 15:49:23 -05:00
2024-07-07 23:30:48 -05:00
export default function Devtools({
2024-07-09 16:00:05 -05:00
eventsChannel,
2024-07-07 23:30:48 -05:00
}) {
2024-11-09 21:15:52 -06:00
useEffect(() => {
if (import.meta.hot) {
const updating = new Set(TabComponents.map(([path]) => path));
import.meta.hot.on('vite:afterUpdate', ({updates}) => {
if (updates.some(({path}) => updating.has(path))) {
import.meta.hot.invalidate();
}
});
2024-07-10 23:40:11 -05:00
}
2024-11-09 21:15:52 -06:00
}, []);
2024-07-07 23:30:48 -05:00
return (
<div className={styles.devtools}>
2024-07-08 15:49:23 -05:00
<Tabs>
<TabList>
2024-11-09 21:15:52 -06:00
{TabComponents.map(([path, {displayName}]) => <Tab key={path}>{displayName}</Tab>)}
2024-07-08 15:49:23 -05:00
</TabList>
2024-11-09 21:15:52 -06:00
{TabComponents.map(([path, TabComponent]) => (
<TabPanel key={path}>
<TabComponent
eventsChannel={eventsChannel}
/>
</TabPanel>
))}
2024-07-08 15:49:23 -05:00
</Tabs>
</div>
2024-07-07 23:30:48 -05:00
);
}