spacedrive/interface/app/$libraryId/index.tsx
Jamie Pine 1eb98cea67
Added Peer screen (#2484)
better peers
2024-05-15 00:48:06 +00:00

82 lines
2.5 KiB
TypeScript

import { redirect } from 'react-router';
import { type RouteObject } from 'react-router-dom';
import { guessOperatingSystem } from '~/hooks';
import { Platform } from '~/util/Platform';
import { debugRoutes } from './debug';
import settingsRoutes from './settings';
// Routes that should be contained within the standard Page layout
const pageRoutes: RouteObject = {
lazy: () => import('./PageLayout'),
children: [
{ path: 'overview', lazy: () => import('./overview') },
{ path: 'debug', children: debugRoutes }
]
};
// Routes that render the explorer and don't need padding and stuff
// provided by PageLayout
const explorerRoutes: RouteObject[] = [
{ path: 'recents', lazy: () => import('./recents') },
{ path: 'favorites', lazy: () => import('./favorites') },
// { path: 'labels', lazy: () => import('./labels') },
{ path: 'search', lazy: () => import('./search') },
{ path: 'ephemeral/:id', lazy: () => import('./ephemeral') },
{ path: 'location/:id', lazy: () => import('./location/$id') },
{ path: 'node/:id', lazy: () => import('./node/$id') },
{ path: 'peer/:id', lazy: () => import('./peer/$id') },
{ path: 'tag/:id', lazy: () => import('./tag/$id') },
{ path: 'network', lazy: () => import('./network') },
{ path: 'saved-search/:id', lazy: () => import('./saved-search/$id') }
];
function loadTopBarRoutes() {
const os = guessOperatingSystem();
if (os === 'windows') {
return [
...explorerRoutes,
pageRoutes,
{ path: 'settings', lazy: () => import('./settings/Layout'), children: settingsRoutes },
{ path: 'debug', children: debugRoutes }
];
} else return [...explorerRoutes, pageRoutes];
}
// Routes that should render with the top bar - pretty much everything except
// 404 and settings, which are rendered only for Windows with top bar
const topBarRoutes: RouteObject = {
lazy: () => import('./TopBar/Layout'),
children: loadTopBarRoutes()
};
export default (platform: Platform) =>
[
{
index: true,
loader: async () => {
try {
if (platform.userHomeDir) {
const homeDir = await platform.userHomeDir();
return redirect(`ephemeral/0?${new URLSearchParams({ path: homeDir })}`, {
replace: true
});
}
} catch (e) {
console.error('Failed to redirect to user home', e);
}
return redirect(`network`, {
replace: true
});
}
},
topBarRoutes,
{
path: 'settings',
lazy: () => import('./settings/Layout'),
children: settingsRoutes
},
{ path: '*', lazy: () => import('./404') }
] satisfies RouteObject[];