Skip to content

Commit

Permalink
Course creation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliV committed Oct 29, 2023
1 parent caa0df5 commit 0abaec1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
26 changes: 19 additions & 7 deletions components/CreateCourse.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useState, useRef } from 'react';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import InputLabel from '@mui/material/InputLabel';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';

export default function CreateCourseDialog({ newCourse }: { newCourse: (name: string, file: File) => void }) {
const uploadInputRef = useRef<HTMLInputElement | null>(null);
Expand All @@ -30,12 +31,23 @@ export default function CreateCourseDialog({ newCourse }: { newCourse: (name: st
<Dialog open={open} onClose={handleCancel}>
<DialogTitle>New Course</DialogTitle>
<DialogContent>
<DialogContentText>To create a new course, please complete this form.</DialogContentText>
<TextField autoFocus margin="dense" id="name" label="Course Name" fullWidth variant="standard" />
<InputLabel htmlFor="import-file" hidden>
<input ref={uploadInputRef} id="import-file" name="import-file" type="file" />
GPX
</InputLabel>
<DialogContentText sx={{ width: '25em' }}>
Course name can be read from the imported file by leaving the name field blank.
</DialogContentText>
<Stack spacing={3}>
<TextField
autoFocus
margin="dense"
id="name"
label="Course Name"
fullWidth
variant="standard"
/>
<InputLabel htmlFor="import-file" hidden>
<input ref={uploadInputRef} id="import-file" name="import-file" type="file" />
GPX
</InputLabel>
</Stack>
</DialogContent>
<DialogActions>
<Button color="secondary" onClick={handleCancel}>
Expand Down
12 changes: 9 additions & 3 deletions pages/ride/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const DynamicMapEditCourse = dynamic<MapEditCourseArg>(() => import('../../../co
ssr: false,
});

const DEFAULT_COURSE_NAME = 'Untitled';

function MyLocationButton({ map, setPosition }) {
const getMyLocation = () => {
if (navigator.geolocation) {
Expand Down Expand Up @@ -67,7 +69,7 @@ export default function RideMap() {
const [editMode, setEditMode] = useState(false);
const [coord, setCoord] = useState<[number, number]>([51.505, -0.09]);
const [course, setCourse] = useState<CourseData | null>(null);
const [courseName, setCourseName] = useState<string>();
const [courseName, setCourseName] = useState<string>(DEFAULT_COURSE_NAME);
const bounds = useMemo(() => course && getMapBounds(course), [course]);
const mapSize = {
width: '70vw',
Expand All @@ -87,6 +89,7 @@ export default function RideMap() {
}
}, [map, bounds]);

const clearCourseName = () => setCourseName(DEFAULT_COURSE_NAME);
const importGpx = async (file: File) => {
let data: CourseData | null;

Expand Down Expand Up @@ -115,7 +118,7 @@ export default function RideMap() {
} else if (data && data.tracks.length && data.tracks[0].name) {
setCourseName(data.tracks[0].name);
} else {
setCourseName('Untitled');
clearCourseName();
}
})();
};
Expand All @@ -141,7 +144,10 @@ export default function RideMap() {
<Button
variant="contained"
color="secondary"
onClick={() => setCourse(null)}
onClick={() => {
setCourse(null);
clearCourseName();
}}
disabled={editMode}
>
Clear Map
Expand Down

0 comments on commit 0abaec1

Please sign in to comment.