From 67ce9077b63d516cc678e1b5a3553573e8aa50d8 Mon Sep 17 00:00:00 2001 From: jude Date: Sun, 19 Nov 2023 10:38:25 +0000 Subject: [PATCH] Improve time inputs Split into multiple inputs. Intercept pastes to fill out all fields. --- src/components/Reminder/TimeInput.tsx | 162 +++++++++++++++++++++++--- 1 file changed, 143 insertions(+), 19 deletions(-) diff --git a/src/components/Reminder/TimeInput.tsx b/src/components/Reminder/TimeInput.tsx index df16a7d..a3ce591 100644 --- a/src/components/Reminder/TimeInput.tsx +++ b/src/components/Reminder/TimeInput.tsx @@ -1,8 +1,8 @@ import { useEffect, useRef, useState } from "preact/hooks"; import { DateTime } from "luxon"; +import { useFlash } from "../App/FlashContext"; export const TimeInput = ({ defaultValue, onInput }) => { - const format = "yyyy-LL-dd, HH:mm:ss"; const ref = useRef(null); const [time, setTime] = useState(defaultValue); @@ -11,23 +11,144 @@ export const TimeInput = ({ defaultValue, onInput }) => { onInput(time); }, [time]); + const flash = useFlash(); + return ( <> -
- { - const dt = DateTime.fromFormat(ev.currentTarget.value, format); - if (dt.isValid) { - setTime(dt); - } - }} - > +
{ + ev.preventDefault(); + const pasteValue = ev.clipboardData.getData("text/plain"); + let dt = DateTime.fromISO(pasteValue); + + if (dt.isValid) { + setTime(dt); + return; + } + + dt = DateTime.fromSQL(pasteValue); + + if (dt.isValid) { + setTime(dt); + return; + } + + flash({ + message: `Couldn't parse your clipboard data as a valid date-time`, + type: "error", + }); + }} + > +
+ + - + + - + + + : + + : + +