-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
945 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ npm-debug.log* | |
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
.vscode | ||
.vscode | ||
.idea |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
Button, Typography, Box, styled, | ||
} from '@mui/material'; | ||
import React, { useState } from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
|
||
import CreateSimulationDialog from './dialogs/CreateSimulationDialog'; | ||
|
||
const MainContainer = styled(Box)(() => ({ | ||
width: '100%', | ||
height: '100%', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
flexDirection: 'column', | ||
textAlign: 'center', | ||
})); | ||
|
||
const SectionBox = styled(Box)(() => ({ | ||
margin: '10px', | ||
})); | ||
|
||
const ActionButton = styled(Button)(() => ({ | ||
padding: '10px', | ||
margin: '10px', | ||
})); | ||
|
||
export default function HomePage(): JSX.Element{ | ||
|
||
const [newSimulationDialogOpened, setNewSimulationDialogOpened] = useState(false); | ||
const history = useHistory(); | ||
|
||
const onViewSimulationsClicked = () => { | ||
history.push('/simulations/all'); | ||
}; | ||
|
||
return ( | ||
<MainContainer> | ||
<SectionBox> | ||
<Typography variant="h1"> | ||
Kraksim v2 | ||
</Typography> | ||
<Typography variant="h4"> | ||
Traffic Simulator | ||
</Typography> | ||
</SectionBox> | ||
<SectionBox> | ||
<ActionButton variant='contained' onClick={() => setNewSimulationDialogOpened(true)}> | ||
Create new simulation | ||
</ActionButton> | ||
<CreateSimulationDialog | ||
open={newSimulationDialogOpened} | ||
onClose={() => setNewSimulationDialogOpened(false)} | ||
/> | ||
<ActionButton variant='contained' onClick={onViewSimulationsClicked}> | ||
View simulation statistics | ||
</ActionButton> | ||
<ActionButton variant='contained'> | ||
Compare simulations | ||
</ActionButton> | ||
</SectionBox> | ||
</MainContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
Dialog, | ||
DialogTitle, | ||
DialogContent, | ||
DialogContentText, | ||
DialogActions, | ||
Button, | ||
DialogProps, | ||
Select, | ||
MenuItem, | ||
} from '@mui/material'; | ||
import React, { useState } from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
import { useGetAllMapsBasicInfoQuery } from '../../../map/mapApi'; | ||
|
||
export default function CreateSimulationDialog({ open, onClose }: DialogProps): JSX.Element{ | ||
|
||
const { data } = useGetAllMapsBasicInfoQuery(); | ||
const [mapId, setMapId] = useState(''); | ||
const history = useHistory(); | ||
|
||
const handleClick = () => { | ||
history.push(`/simulations/create?mapId=${mapId}`); | ||
}; | ||
|
||
return ( | ||
<Dialog open={open} onClose={onClose}> | ||
<DialogTitle>Select Map</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
To create a simulation, select a map for it | ||
</DialogContentText> | ||
<Select | ||
id="select-map" | ||
value={mapId} | ||
label="Map" | ||
onChange={(e) => setMapId(e.target.value)} | ||
> | ||
{data?.map(({ id, name }) => <MenuItem key={id} value={id}>{name}</MenuItem>)} | ||
</Select> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={handleClick} disabled={mapId.length === 0}>Confirm</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
TableContainer, Paper, Table, TableHead, TableRow, TableCell, TableBody, | ||
} from '@mui/material'; | ||
import React from 'react'; | ||
|
||
import { useGetAllSimulationsQuery } from '../../simulation/simulationApi'; | ||
|
||
export default function SimulationList() : JSX.Element { | ||
|
||
const { data } = useGetAllSimulationsQuery(); | ||
|
||
return ( | ||
<TableContainer component={Paper}> | ||
<Table sx={{ minWidth: 650 }} aria-label="simple table"> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>ID</TableCell> | ||
<TableCell>Name</TableCell> | ||
<TableCell>Map ID</TableCell> | ||
<TableCell>Type</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{data?.map((row) => ( | ||
<TableRow | ||
key={row.id} | ||
sx={{ '&:last-child td, &:last-child th': { border: 0 } }} | ||
> | ||
<TableCell>{row.id}</TableCell> | ||
<TableCell>{row.name}</TableCell> | ||
<TableCell>{row.mapId}</TableCell> | ||
<TableCell>{row.type}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
); | ||
} |
28 changes: 7 additions & 21 deletions
28
src/features/simulation/components/form/SimulationFormWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,19 @@ | ||
import { InputLabel, MenuItem } from '@mui/material'; | ||
import React, { useState } from 'react'; | ||
import React from 'react'; | ||
|
||
import { useGetAllMapsBasicInfoQuery } from '../../../map/mapApi'; | ||
import { useUrlParamsQuery } from '../../../common/hooks'; | ||
|
||
import { FormSelect } from './common'; | ||
import CreateSimulationForm from './CreateSimulationForm'; | ||
|
||
|
||
export default function SimulationFormWrapper(): JSX.Element{ | ||
|
||
const { data } = useGetAllMapsBasicInfoQuery(); | ||
const [selectedMapId, setSelectedMapId] = useState(''); | ||
const parsedId = selectedMapId === '' ? null : parseInt(selectedMapId); | ||
const selectedMapId = useUrlParamsQuery().get('mapId'); | ||
const parsedId = selectedMapId === null ? null : parseInt(selectedMapId); | ||
return ( | ||
<div> | ||
{ data && | ||
<div> | ||
<h1>Select Map for a new Simulation</h1> | ||
<InputLabel htmlFor="mapId">Map</InputLabel> | ||
<FormSelect | ||
name="mapId" | ||
value={selectedMapId} | ||
onChange={(e) => setSelectedMapId(e.target.value as string)} | ||
label="Map"> | ||
{data.map(({ id, name }) => <MenuItem value={id}>{name}</MenuItem>)} | ||
</FormSelect> | ||
</div> | ||
} | ||
{parsedId && <CreateSimulationForm mapId={parsedId}/>} | ||
{parsedId ? | ||
<CreateSimulationForm mapId={parsedId}/> : | ||
<div>Sorry, no valid mapId found in querystring</div>} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.