From 53e066b2b455316e642d6b52c8977e4cfc19a223 Mon Sep 17 00:00:00 2001 From: ImJustChew Date: Sun, 29 Sep 2024 00:30:13 +0900 Subject: [PATCH] fix: used html time picker instead for reliability --- src/components/Calendar/AddEventButton.tsx | 21 +++-- src/components/ui/custom_timeselect.tsx | 98 ++++++++++------------ 2 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/components/Calendar/AddEventButton.tsx b/src/components/Calendar/AddEventButton.tsx index d835940c..7386bde3 100644 --- a/src/components/Calendar/AddEventButton.tsx +++ b/src/components/Calendar/AddEventButton.tsx @@ -216,9 +216,14 @@ export const AddEventButton = ({ - { + { + const timesplits = e.target.value.split(":"); + const d = set(field.value, { + hours: parseInt(timesplits[0]), + minutes: parseInt(timesplits[1]), + }); const diff = form.getValues("end").getTime() - form.getValues("start").getTime(); @@ -231,7 +236,7 @@ export const AddEventButton = ({ form.trigger(["end"]); } }} - date={field.value} + value={format(field.value, "HH:mm")} /> )} @@ -241,10 +246,10 @@ export const AddEventButton = ({ name="end" render={({ field }) => ( - diff --git a/src/components/ui/custom_timeselect.tsx b/src/components/ui/custom_timeselect.tsx index cf3564d1..bb8015db 100644 --- a/src/components/ui/custom_timeselect.tsx +++ b/src/components/ui/custom_timeselect.tsx @@ -7,6 +7,7 @@ import { Command, CommandGroup, CommandItem } from "@/components/ui/command"; import { set } from "date-fns"; import { Popover, PopoverContent } from "./popover"; import { PopoverAnchor, PopoverPortal } from "@radix-ui/react-popover"; +import { Input } from "./input"; export const getNearestTime = (date: Date, minuteStep: number) => { const minutes = date.getMinutes(); @@ -136,60 +137,53 @@ export function TimeSelect({ className={clsx(label && "gap-1.5", parentClassName, "grid items-center")} > - -
-
- {/* Avoid having the "Search" Icon */} - setOpen(true)} - placeholder={placeholder} - className="ml-2 bg-transparent outline-none placeholder:text-muted-foreground flex-1 overflow-hidden w-full" - /> -
+
+
+ setInputValue(v.target.value)} + onKeyDown={handleKeyDown} + onBlur={handleInputBlur} + onFocus={() => setOpen(true)} + placeholder={placeholder} + className="ml-2 bg-transparent outline-none placeholder:text-muted-foreground flex-1 overflow-hidden w-full" + />
- - - - e.preventDefault()} - className="p-0 w-28 h-0 border-none" - > -
- {open && selectables.length > 0 ? ( -
- - {selectables.map((framework) => { - return ( - { - e.preventDefault(); - e.stopPropagation(); - }} - onSelect={(value) => { - setInputValue(framework.label); - setSelected(framework.value); - setOpen(false); - }} - > - {framework.label} - - ); - })} - -
- ) : null} +
+ + + e.preventDefault()} + className="p-0 w-28 h-0 border-none" + > +
+ {open && selectables.length > 0 ? ( +
+ {selectables.map((framework) => { + return ( +
{ + e.preventDefault(); + e.stopPropagation(); + }} + onSelect={(value) => { + setInputValue(framework.label); + setSelected(framework.value); + setOpen(false); + }} + > + {framework.label} +
+ ); + })}
- - - - + ) : null} +
+
+
);