refactor: move dashboard screens into shell routes

This commit is contained in:
2026-04-17 13:20:00 +01:00
parent e97a54ac8d
commit fac6409ec4
16 changed files with 113 additions and 21 deletions

View File

@@ -2,12 +2,12 @@
// @ts-nocheck
const PAGE_PATHS = {
auth: '/',
onboarding: '/onboarding',
camera: '/camera',
client: '/client',
activity: '/activity',
settings: '/settings'
auth: '/auth/login',
onboarding: '/app/onboarding',
camera: '/app/camera',
client: '/app/client',
activity: '/app/activity',
settings: '/app/settings'
};
const DEVICE_STORAGE_KEY = 'mobileSimDevice';
@@ -66,15 +66,21 @@ const normalizePath = (path) => path.replace(/\/+$/, '') || '/';
export const pageFromPath = (path) => {
switch (normalizePath(path)) {
case '/onboarding':
case '/auth':
case '/auth/login':
case '/auth/signup':
return 'auth';
case '/app':
return 'app';
case '/app/onboarding':
return 'onboarding';
case '/camera':
case '/app/camera':
return 'camera';
case '/client':
case '/app/client':
return 'client';
case '/activity':
case '/app/activity':
return 'activity';
case '/settings':
case '/app/settings':
return 'settings';
default:
return 'auth';

View File

@@ -55,6 +55,9 @@ let initPromise = null;
let socket = null;
let pollInterval = null;
let socketHeartbeatInterval = null;
const handleBeforeUnload = () => {
void cleanupConnectionState();
};
let clientVideoElement = null;
@@ -839,7 +842,13 @@ const invalidateSavedDevice = async (message, options = {}) => {
const enforceRouteForSession = () => {
const state = getAppState();
const page = pageFromPath(window.location.pathname);
setAppState({ page });
const initialPage =
page === 'app'
? state.deviceToken
? getHomePageKeyForRole(state.device?.role)
: 'onboarding'
: page;
setAppState({ page: initialPage });
if (!state.session) {
if (page !== 'auth') {
@@ -856,7 +865,7 @@ const enforceRouteForSession = () => {
}
const expectedHome = getHomePageKeyForRole(state.device?.role);
if ((page === 'auth' || page === 'onboarding') && expectedHome) {
if ((page === 'auth' || page === 'onboarding' || page === 'app') && expectedHome) {
navigateToScreen('home', { replace: true, role: state.device?.role });
return;
}
@@ -903,9 +912,7 @@ const init = async () => {
void refreshCameraInputDevices();
applyMotionDetectionReadiness();
window.addEventListener('beforeunload', () => {
void cleanupConnectionState();
});
window.addEventListener('beforeunload', handleBeforeUnload);
initialized = true;
})().finally(() => {
@@ -923,6 +930,7 @@ const destroy = async () => {
if (typeof document !== 'undefined') {
document.removeEventListener('visibilitychange', onVisibilityChange);
}
window.removeEventListener('beforeunload', handleBeforeUnload);
initialized = false;
await cleanupConnectionState();
};
@@ -955,6 +963,10 @@ const actions = {
patchAppState((state) => ({ isRegistering: !state.isRegistering }));
},
setAuthMode(isRegistering) {
setAppState({ isRegistering });
},
async submitAuth() {
const state = getAppState();
const { email, password, name } = state.authForm;