From ef2b877b49f5a6efc4080f2edb2db25091900235 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 1 Sep 2022 13:59:06 +1200 Subject: [PATCH] Add date editing to Massive input --- MassiveInput.tsx | 2 +- SetForm.tsx | 75 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/MassiveInput.tsx b/MassiveInput.tsx index 92b0d17..4246180 100644 --- a/MassiveInput.tsx +++ b/MassiveInput.tsx @@ -14,7 +14,7 @@ export default function MassiveInput( (null); const repsRef = useRef(null); - const dark = useColorScheme() === 'dark'; const db = useContext(DatabaseContext); - const {toast} = useContext(SnackbarContext); + + useEffect(() => { + if (!set.created) return; + const matches = set.created.match(/\d+/g); + if (!matches) return; + setYear(matches[0]); + setMonth(matches[1]); + setDay(matches[2]); + setHour(matches[3]); + setMinute(matches[4]); + }, [set.created]); useEffect(() => { console.log('SetForm.useEffect:', {uri, name: set.name}); @@ -41,15 +54,10 @@ export default function SetForm({ const handleSubmit = () => { if (!name) return; - if (created && !created.match(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d$/)) - return toast( - 'Created must be of the format YYYY-mm-ddTHH:mm:ss. E.g. 1996-12-24T12:59:40', - 7000, - ); save({ name, reps: Number(reps), - created, + created: `${year}-${month}-${day}T${hour}:${minute}`, weight: Number(weight), id: set.id, unit, @@ -95,14 +103,43 @@ export default function SetForm({ onSubmitEditing={handleSubmit} /> {set.created && ( - + + + + + + + )} {workouts?.map((workout, index) => (