refactor: simplify routing

This commit is contained in:
Carlos Valente
2025-07-23 21:37:11 +02:00
committed by Carlos Valente
parent e204f671be
commit 78184b23b7
2 changed files with 46 additions and 50 deletions
+40 -50
View File
@@ -1,38 +1,30 @@
import React from 'react'; import { ComponentType, lazy, Suspense, useMemo } from 'react';
import { Navigate, Route, useLocation } from 'react-router'; import { Navigate, Route, useLocation } from 'react-router';
import { OntimeView, OntimeViewPresettable } from 'ontime-types';
import { useClientPath } from './common/hooks/useClientPath'; import { useClientPath } from './common/hooks/useClientPath';
import useUrlPresets from './common/hooks-query/useUrlPresets';
import Log from './features/log/Log'; import Log from './features/log/Log';
import withPreset from './features/PresetWrapper'; import Loader from './views/common/loader/Loader';
import withData from './features/viewers/ViewWrapper'; import NotFound from './views/common/not-found/NotFound';
import ViewLoader from './views/ViewLoader'; import ViewLoader from './views/ViewLoader';
import { initializeSentry } from './sentry.config'; import { initializeSentry } from './sentry.config';
const Editor = React.lazy(() => import('./views/editor/ProtectedEditor')); const Timer = lazy(() => import('./views/timer/Timer'));
const Cuesheet = React.lazy(() => import('./views/cuesheet/ProtectedCuesheet')); const Countdown = lazy(() => import('./views/countdown/Countdown'));
const Operator = React.lazy(() => import('./features/operator/OperatorExport')); const Backstage = lazy(() => import('./views/backstage/Backstage'));
const StudioClock = lazy(() => import('./views/studio/Studio'));
const Timeline = lazy(() => import('./views/timeline/TimelinePage'));
const ProjectInfo = lazy(() => import('./views/project-info/ProjectInfo'));
const TimerView = React.lazy(() => import('./views/timer/Timer')); const Editor = lazy(() => import('./views/editor/ProtectedEditor'));
const Countdown = React.lazy(() => import('./views/countdown/Countdown')); const Cuesheet = lazy(() => import('./views/cuesheet/ProtectedCuesheet'));
const Operator = lazy(() => import('./features/operator/OperatorExport'));
const Backstage = React.lazy(() => import('./views/backstage/Backstage')); const EditorFeatureWrapper = lazy(() => import('./features/EditorFeatureWrapper'));
const Timeline = React.lazy(() => import('./views/timeline/TimelinePage')); const RundownPanel = lazy(() => import('./features/rundown/RundownExport'));
const StudioClock = React.lazy(() => import('./views/studio/Studio')); const TimerControl = lazy(() => import('./features/control/playback/TimerControlExport'));
const ProjectInfo = React.lazy(() => import('./views/project-info/ProjectInfo')); const MessageControl = lazy(() => import('./features/control/message/MessageControlExport'));
const STimer = withPreset(withData(TimerView));
const SCountdown = withPreset(withData(Countdown));
const SBackstage = withPreset(withData(Backstage));
const SProjectInfo = withPreset(ProjectInfo); // NOTE: ProjectInfo does not use the viewWrapper since it has no options
const SStudio = withPreset(withData(StudioClock));
const STimeline = withPreset(withData(Timeline));
const PCuesheet = withPreset(Cuesheet);
const POperator = withPreset(Operator);
const EditorFeatureWrapper = React.lazy(() => import('./features/EditorFeatureWrapper'));
const RundownPanel = React.lazy(() => import('./features/rundown/RundownExport'));
const TimerControl = React.lazy(() => import('./features/control/playback/TimerControlExport'));
const MessageControl = React.lazy(() => import('./features/control/message/MessageControlExport'));
// Initialize Sentry with our configuration // Initialize Sentry with our configuration
const SentryRouter = initializeSentry(); const SentryRouter = initializeSentry();
@@ -42,73 +34,73 @@ export default function AppRouter() {
useClientPath(); useClientPath();
return ( return (
<React.Suspense fallback={null}> <Suspense fallback={<Loader />}>
<SentryRouter> <SentryRouter>
<Route path='/' element={<Navigate to='/timer' />} /> <Route path='/' element={<Navigate to='/timer' />} />
<Route <Route
path='/timer' path='timer'
element={ element={
<ViewLoader> <ViewLoader>
<STimer /> <Timer />
</ViewLoader> </ViewLoader>
} }
/> />
<Route <Route
path='/countdown' path='countdown'
element={ element={
<ViewLoader> <ViewLoader>
<SCountdown /> <Countdown />
</ViewLoader> </ViewLoader>
} }
/> />
<Route <Route
path='/backstage' path='backstage'
element={ element={
<ViewLoader> <ViewLoader>
<SBackstage /> <Backstage />
</ViewLoader> </ViewLoader>
} }
/> />
<Route <Route
path='/studio' path='studio'
element={ element={
<ViewLoader> <ViewLoader>
<SStudio /> <StudioClock />
</ViewLoader> </ViewLoader>
} }
/> />
<Route <Route
path='/timeline' path='timeline'
element={ element={
<ViewLoader> <ViewLoader>
<STimeline /> <Timeline />
</ViewLoader> </ViewLoader>
} }
/> />
<Route <Route
path='/info' path='info'
element={ element={
<ViewLoader> <ViewLoader>
<SProjectInfo /> <ProjectInfo />
</ViewLoader> </ViewLoader>
} }
/> />
{/*/!* Protected Routes *!/*/} {/*/!* Protected Routes *!/*/}
<Route path='/editor' element={<Editor />} /> <Route path='editor' element={<Editor />} />
<Route path='/cuesheet' element={<PCuesheet />} /> <Route path='cuesheet' element={<Cuesheet />} />
<Route <Route
path='/op' path='op'
element={ element={
<ViewLoader> <ViewLoader>
<POperator /> <Operator />
</ViewLoader> </ViewLoader>
} }
/> />
{/*/!* Protected Routes - Elements *!/*/} {/*/!* Protected Routes - Elements *!/*/}
<Route <Route
path='/rundown' path='rundown'
element={ element={
<EditorFeatureWrapper> <EditorFeatureWrapper>
<RundownPanel /> <RundownPanel />
@@ -116,7 +108,7 @@ export default function AppRouter() {
} }
/> />
<Route <Route
path='/timercontrol' path='timercontrol'
element={ element={
<EditorFeatureWrapper> <EditorFeatureWrapper>
<TimerControl /> <TimerControl />
@@ -124,7 +116,7 @@ export default function AppRouter() {
} }
/> />
<Route <Route
path='/messagecontrol' path='messagecontrol'
element={ element={
<EditorFeatureWrapper> <EditorFeatureWrapper>
<MessageControl /> <MessageControl />
@@ -132,16 +124,14 @@ export default function AppRouter() {
} }
/> />
<Route <Route
path='/log' path='log'
element={ element={
<EditorFeatureWrapper> <EditorFeatureWrapper>
<Log /> <Log />
</EditorFeatureWrapper> </EditorFeatureWrapper>
} }
/> />
{/*/!* Send to default if nothing found *!/*/}
<Route path='*' element={<STimer />} />
</SentryRouter> </SentryRouter>
</React.Suspense> </Suspense>
); );
} }
@@ -0,0 +1,6 @@
import { QueryStatus } from '@tanstack/react-query';
export type ViewData<T> = {
data: T;
status: QueryStatus;
};