diff --git a/components/EditActionButtons.tsx b/components/EditActionButtons.tsx index 9aaefa6..73ca8fa 100644 --- a/components/EditActionButtons.tsx +++ b/components/EditActionButtons.tsx @@ -16,7 +16,7 @@ export default function EditActionButtons({ const actionsStyle = { '> *': { boxShadow: 'none', - margin: '2pt', + margin: '3pt', marginBottom: '1.5ex', marginTop: '1.5ex', }, diff --git a/components/EditRideModal.tsx b/components/EditRideModal.tsx new file mode 100644 index 0000000..567aac2 --- /dev/null +++ b/components/EditRideModal.tsx @@ -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; +}) { + 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 ( + + {open ? ( + +
+ +
+ + + +
+ ) : ( + '' + )} +
+ ); +} diff --git a/pages/history.tsx b/pages/history.tsx index b9374df..2c4667a 100644 --- a/pages/history.tsx +++ b/pages/history.tsx @@ -15,7 +15,6 @@ import IconDownload from '@mui/icons-material/GetApp'; import IconMoreVert from '@mui/icons-material/MoreVert'; import Menu from '@mui/material/Menu'; import MenuItem from '@mui/material/MenuItem'; -import TextField from '@mui/material/TextField'; import Typography from '@mui/material/Typography'; import useMediaQuery from '@mui/material/useMediaQuery'; import { red } from '@mui/material/colors'; @@ -24,11 +23,10 @@ import { useRouter } from 'next/router'; import { useState, useEffect, useRef, MutableRefObject } from 'react'; import BottomNavi from '../components/BottomNavi'; import MyHead from '../components/MyHead'; -import MyModal from '../components/MyModal'; import Title from '../components/Title'; -import EditActionButtons from '../components/EditActionButtons'; +import EditRideModal from '../components/EditRideModal'; import downloadBlob from '../lib/download_blob'; -import { createActivityLog, deleteActivityLog, getActivityLogs, saveActivityLog } from '../lib/activity_log'; +import { deleteActivityLog, getActivityLogs } from '../lib/activity_log'; const PREFIX = 'history'; const classes = { @@ -38,7 +36,6 @@ const classes = { expand: `${PREFIX}-expand`, expandOpen: `${PREFIX}-expandOpen`, avatar: `${PREFIX}-avatar`, - nameField: `${PREFIX}-nameField`, }; const StyledContainer = styled(Container)(({ theme }) => ({ @@ -75,84 +72,9 @@ const StyledContainer = styled(Container)(({ theme }) => ({ [`& .${classes.avatar}`]: { backgroundColor: red[500], }, - - [`& .${classes.nameField}`]: { - paddingBottom: '2.5em', - }, })); -const editModalStyle = { - width: '20em', - height: '30em', -}; - -function EditModal({ - open, - onClose, - logger, -}: { - open: boolean; - onClose: () => void; - logger: ReturnType; -}) { - 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 ( - - {open ? ( - -
- - - - -
- ) : ( - '' - )} -
- ); -} - type Log = ReturnType[1]; -type WeakLogMap = MutableRefObject>; function RideCard({ log, onChange, onSelect }: { log: Log; onChange: () => void; onSelect: (v: boolean) => void }) { const [anchorEl, setAnchorEl] = useState(null); @@ -225,7 +147,7 @@ function RideCard({ log, onChange, onSelect }: { log: Log; onChange: () => void; /> - setShowEditModal(false)} logger={log.logger} /> + setShowEditModal(false)} logger={log.logger} /> ); }