2021-05-02 12:29:43 +00:00
|
|
|
import { Link, Redirect, Router, useLocation } from '@reach/router';
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2021-09-17 09:55:15 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
2021-05-02 12:29:43 +00:00
|
|
|
import { RootState } from '../store';
|
|
|
|
import { createWSClient } from '../store/api/reducer';
|
|
|
|
import Home from './pages/Home';
|
|
|
|
import HTTPPage from './pages/HTTP';
|
2021-05-14 11:15:38 +00:00
|
|
|
import TwitchPage from './pages/twitch/Main';
|
2021-05-02 12:29:43 +00:00
|
|
|
import StulbePage from './pages/Stulbe';
|
|
|
|
import LoyaltyPage from './pages/loyalty/Main';
|
|
|
|
import DebugPage from './pages/Debug';
|
|
|
|
import LoyaltySettingPage from './pages/loyalty/Settings';
|
|
|
|
import LoyaltyRewardsPage from './pages/loyalty/Rewards';
|
|
|
|
import LoyaltyUserListPage from './pages/loyalty/UserList';
|
|
|
|
import LoyaltyGoalsPage from './pages/loyalty/Goals';
|
|
|
|
import LoyaltyRedeemQueuePage from './pages/loyalty/Queue';
|
2021-05-14 11:15:38 +00:00
|
|
|
import TwitchSettingsPage from './pages/twitch/APISettings';
|
|
|
|
import TwitchBotSettingsPage from './pages/twitch/BotSettings';
|
2021-09-16 15:11:35 +00:00
|
|
|
import TwitchBotCommandsPage from './pages/twitch/Commands';
|
|
|
|
import TwitchBotModulesPage from './pages/twitch/Modules';
|
2021-05-02 12:29:43 +00:00
|
|
|
|
|
|
|
interface RouteItem {
|
2021-09-17 09:55:15 +00:00
|
|
|
name?: string;
|
2021-05-02 12:29:43 +00:00
|
|
|
route: string;
|
|
|
|
subroutes?: RouteItem[];
|
|
|
|
}
|
|
|
|
|
|
|
|
const menu: RouteItem[] = [
|
2021-09-17 09:55:15 +00:00
|
|
|
{ route: '/' },
|
|
|
|
{ route: '/http' },
|
2021-05-02 12:29:43 +00:00
|
|
|
{
|
2021-09-17 09:55:15 +00:00
|
|
|
route: '/twitch',
|
2021-05-02 12:29:43 +00:00
|
|
|
subroutes: [
|
2021-09-17 09:55:15 +00:00
|
|
|
{ route: '/twitch/settings' },
|
|
|
|
{ route: '/twitch/bot/settings' },
|
|
|
|
{ route: '/twitch/bot/commands' },
|
|
|
|
{ route: '/twitch/bot/modules' },
|
2021-05-02 12:29:43 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2021-09-17 09:55:15 +00:00
|
|
|
route: '/loyalty',
|
2021-05-02 12:29:43 +00:00
|
|
|
subroutes: [
|
2021-09-17 09:55:15 +00:00
|
|
|
{ route: '/loyalty/settings' },
|
|
|
|
{ route: '/loyalty/users' },
|
|
|
|
{ route: '/loyalty/queue' },
|
|
|
|
{ route: '/loyalty/rewards' },
|
|
|
|
{ route: '/loyalty/goals' },
|
2021-05-02 12:29:43 +00:00
|
|
|
],
|
|
|
|
},
|
2021-09-17 09:55:15 +00:00
|
|
|
{ route: '/stulbe' },
|
2021-05-02 12:29:43 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
export default function App(): React.ReactElement {
|
|
|
|
const loc = useLocation();
|
2021-09-17 09:55:15 +00:00
|
|
|
const { t } = useTranslation();
|
2021-05-02 12:29:43 +00:00
|
|
|
|
|
|
|
const client = useSelector((state: RootState) => state.api.client);
|
2021-05-07 16:36:23 +00:00
|
|
|
const connected = useSelector((state: RootState) => state.api.connected);
|
2021-05-02 12:29:43 +00:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
// Create WS client
|
|
|
|
useEffect(() => {
|
|
|
|
if (!client) {
|
|
|
|
dispatch(
|
|
|
|
createWSClient(
|
|
|
|
process.env.NODE_ENV === 'development'
|
|
|
|
? 'ws://localhost:4337/ws'
|
|
|
|
: `ws://${loc.host}/ws`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!client) {
|
2021-09-17 09:55:15 +00:00
|
|
|
return <div className="container">{t('system.loading')}</div>;
|
2021-05-02 12:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const basepath = process.env.NODE_ENV === 'development' ? '/' : '/ui/';
|
|
|
|
|
|
|
|
const routeItem = ({ route, name, subroutes }: RouteItem) => (
|
|
|
|
<li key={route}>
|
|
|
|
<Link
|
|
|
|
getProps={({ isPartiallyCurrent, isCurrent }) => {
|
|
|
|
const active = isCurrent || (subroutes && isPartiallyCurrent);
|
|
|
|
return {
|
|
|
|
className: active ? 'is-active' : '',
|
|
|
|
};
|
|
|
|
}}
|
|
|
|
to={`${basepath}${route}`.replace(/\/\//gi, '/')}
|
|
|
|
>
|
2021-09-17 09:55:15 +00:00
|
|
|
{name ?? t(`pages.${route}`)}
|
2021-05-02 12:29:43 +00:00
|
|
|
</Link>
|
|
|
|
{subroutes ? (
|
|
|
|
<ul className="subroute">{subroutes.map(routeItem)}</ul>
|
|
|
|
) : null}
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="main-content columns is-fullheight">
|
2021-05-07 16:36:23 +00:00
|
|
|
<section className="notifications">
|
|
|
|
{!connected ? (
|
|
|
|
<div className="notification is-danger">
|
2021-09-17 09:55:15 +00:00
|
|
|
{t('system.connection-lost')}
|
2021-05-07 16:36:23 +00:00
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</section>
|
2021-05-02 12:29:43 +00:00
|
|
|
<aside className="menu sidebar column is-3 is-fullheight section">
|
2021-09-17 09:55:15 +00:00
|
|
|
<p className="menu-label is-hidden-touch">{t('system.menu-header')}</p>
|
2021-05-02 12:29:43 +00:00
|
|
|
<ul className="menu-list">{menu.map(routeItem)}</ul>
|
|
|
|
</aside>
|
|
|
|
|
|
|
|
<div className="app-content column is-9">
|
|
|
|
<div className="content-pad">
|
|
|
|
<Router basepath={basepath}>
|
|
|
|
<Home path="/" />
|
|
|
|
<HTTPPage path="http" />
|
2021-05-14 11:15:38 +00:00
|
|
|
<TwitchPage path="twitch">
|
2021-05-02 12:29:43 +00:00
|
|
|
<Redirect from="/" to="settings" noThrow />
|
2021-05-14 11:15:38 +00:00
|
|
|
<TwitchSettingsPage path="settings" />
|
|
|
|
<TwitchBotSettingsPage path="bot/settings" />
|
2021-09-16 15:11:35 +00:00
|
|
|
<TwitchBotCommandsPage path="bot/commands" />
|
|
|
|
<TwitchBotModulesPage path="bot/modules" />
|
2021-05-14 11:15:38 +00:00
|
|
|
</TwitchPage>
|
2021-05-02 12:29:43 +00:00
|
|
|
<LoyaltyPage path="loyalty">
|
|
|
|
<Redirect from="/" to="settings" noThrow />
|
|
|
|
<LoyaltySettingPage path="settings" />
|
|
|
|
<LoyaltyUserListPage path="users" />
|
|
|
|
<LoyaltyRedeemQueuePage path="queue" />
|
|
|
|
<LoyaltyRewardsPage path="rewards" />
|
|
|
|
<LoyaltyGoalsPage path="goals" />
|
|
|
|
</LoyaltyPage>
|
|
|
|
<StulbePage path="stulbe" />
|
|
|
|
<DebugPage path="debug" />
|
|
|
|
</Router>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|