FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
MainLayout.tsx
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
3
4import React, { useState } from 'react';
5import { Box, Snackbar, Alert } from '@mui/material';
6import AppRail from '@/components/AppRail';
7import { ScenarioView } from '@/views/ScenarioView';
8import { AssetLibraryView } from '@/views/AssetLibraryView';
9import { SimulationView } from '@/views/SimulationView';
10import { ResultsView } from '@/views/ResultsView';
11import SettingsDialog from '@/components/SettingsDialog';
12import { useScenarioStore } from '@/stores/scenarioStore';
13
14export function MainLayout() {
15 const [activeView, setActiveView] = useState('scenario');
16 const [settingsOpen, setSettingsOpen] = useState(false);
17 const { open: errorOpen, message: errorMessage } = useScenarioStore(
18 (state) => state.errorSnackbar
19 );
20 const hideError = useScenarioStore((state) => state.hideError);
21
22 return (
23 <Box
24 sx={{
25 display: 'flex',
26 height: '100vh',
27 width: '100vw',
28 overflow: 'hidden',
29 position: 'fixed', // Ensure it stays in viewport
30 top: 0,
31 left: 0,
32 }}
33 >
34 <AppRail
35 activeView={activeView}
36 onViewChange={setActiveView}
37 onSettingsClick={() => setSettingsOpen(true)}
38 />
39 <Box
40 component="main"
41 sx={{
42 flexGrow: 1,
43 minWidth: 0, // Allow shrinking below content size
44 height: '100%',
45 overflow: 'hidden', // Prevent overflow
46 position: 'relative',
47 }}
48 >
49 {/* Render all views but only display the active one */}
50 <Box
51 sx={{
52 display: activeView === 'scenario' ? 'flex' : 'none',
53 height: '100%',
54 width: '100%',
55 }}
56 >
57 <ScenarioView />
58 </Box>
59 <Box
60 sx={{
61 display: activeView === 'assets' ? 'block' : 'none',
62 height: '100%',
63 width: '100%',
64 }}
65 >
66 <AssetLibraryView />
67 </Box>
68 <Box
69 sx={{
70 display: activeView === 'simulation' ? 'block' : 'none',
71 height: '100%',
72 width: '100%',
73 }}
74 >
75 <SimulationView />
76 </Box>
77 <Box
78 sx={{
79 display: activeView === 'results' ? 'block' : 'none',
80 height: '100%',
81 width: '100%',
82 }}
83 >
84 <ResultsView />
85 </Box>
86 </Box>
87 <SettingsDialog
88 open={settingsOpen}
89 onClose={() => setSettingsOpen(false)}
90 />
91 <Snackbar
92 open={errorOpen}
93 autoHideDuration={6000}
94 onClose={hideError}
95 anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
96 >
97 <Alert
98 onClose={hideError}
99 severity="error"
100 variant="filled"
101 sx={{ width: '100%' }}
102 >
103 {errorMessage}
104 </Alert>
105 </Snackbar>
106 </Box>
107 );
108}