-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate edit modal from the rides page
- Loading branch information
Showing
3 changed files
with
88 additions
and
82 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
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,84 @@ | ||
import { useState } from 'react'; | ||
import Grid from '@mui/material/Grid'; | ||
import TextField from '@mui/material/TextField'; | ||
import { createActivityLog, saveActivityLog } from '../lib/activity_log'; | ||
import EditActionButtons from '../components/EditActionButtons'; | ||
import MyModal from '../components/MyModal'; | ||
|
||
const editModalStyle = { | ||
width: '40em', | ||
height: '30em', | ||
}; | ||
|
||
export default function EditModal({ | ||
open, | ||
onClose, | ||
logger, | ||
}: { | ||
open: boolean; | ||
onClose: () => void; | ||
logger: ReturnType<typeof createActivityLog>; | ||
}) { | ||
const [newName, setNewName] = useState(() => logger.getName()); | ||
const [newNotes, setNewNotes] = useState(() => logger.getNotes()); | ||
|
||
const handleNameChange = (e) => { | ||
setNewName(e.target.value); | ||
}; | ||
const handleNotesChange = (e) => { | ||
setNewNotes(e.target.value); | ||
}; | ||
const onClickSave = () => { | ||
logger.setName(newName); | ||
logger.setNotes(newNotes); | ||
saveActivityLog(logger); | ||
onClose(); | ||
}; | ||
const onClickDiscard = (e: any) => { | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<MyModal | ||
title="Edit Ride" | ||
description="Here you can edit the activity metadata." | ||
modalStyle={editModalStyle} | ||
open={open} | ||
onClose={onClose} | ||
> | ||
{open ? ( | ||
<Grid item> | ||
<form onSubmit={onClickSave}> | ||
<TextField | ||
id="act-name" | ||
label="Activity Name" | ||
defaultValue={logger.getName()} | ||
onChange={handleNameChange} | ||
sx={{ | ||
width: '40ch', | ||
pb: '2.5em' | ||
}} | ||
/> | ||
<br/> | ||
<TextField | ||
id="act-notes" | ||
label="Notes" | ||
multiline | ||
rows={4} | ||
defaultValue={logger.getNotes()} | ||
onChange={handleNotesChange} | ||
variant="outlined" | ||
fullWidth | ||
sx={{ | ||
pb: '2.5em' | ||
}} | ||
/> | ||
<EditActionButtons onClickSave={onClickSave} onClickDiscard={onClickDiscard} /> | ||
</form> | ||
</Grid> | ||
) : ( | ||
'' | ||
)} | ||
</MyModal> | ||
); | ||
} |
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
b6d8cff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
bfree – ./
bfree.vercel.app
bfree-olliv.vercel.app
bfree-git-master-olliv.vercel.app