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/Calendar/EventPopover.tsx b/src/components/Calendar/EventPopover.tsx index 8759ed5b..8eb03383 100644 --- a/src/components/Calendar/EventPopover.tsx +++ b/src/components/Calendar/EventPopover.tsx @@ -34,9 +34,7 @@ const ConfirmDeleteEvent: FC<{ event: DisplayCalendarEvent }> = ({ event }) => { 確認刪除 - -

確定要刪除這個事件嗎?

-
+ 確定要刪除這個事件嗎?
@@ -67,7 +65,7 @@ const UpdateRepeatedEventDialog: FC<{ 更新重複事件 -

您要更新所有重複事件還是只更新這個事件?

+ 您要更新所有重複事件還是只更新這個事件?
@@ -103,7 +101,7 @@ const DeleteRepeatedEventDialog: FC<{ 刪除重複事件 -

您要刪除所有重複事件還是只刪除這個事件?

+ 您要刪除所有重複事件還是只刪除這個事件
diff --git a/src/components/Calendar/UpcomingEvents.tsx b/src/components/Calendar/UpcomingEvents.tsx index 6ee5f8da..90bdd01a 100644 --- a/src/components/Calendar/UpcomingEvents.tsx +++ b/src/components/Calendar/UpcomingEvents.tsx @@ -59,7 +59,7 @@ const UpcomingEvents = () => { brightness > 186 ? 0.2 : 0.95, ); return ( - +
{ case UpdateType.THIS: // add this date to excluded dates await eventsCol!.findOne(event.id).update({ - $set: { - actualEnd: getActualEndDate(event), + $set: serializeEvent({ + actualEnd: getDisplayEndDate(event), excludedDates: [ ...(event.excludedDates || []), event.displayStart, ], - }, + }), }); break; case UpdateType.FOLLOWING: //set the repeat end date to the new event start date - const newEvent = { - ...event, + const { displayStart, displayEnd, ...originalEvent } = event; + const newEvent: CalendarEvent = { + ...originalEvent, repeat: { ...event.repeat!, - count: undefined, - date: subDays(event.displayStart, 1), + value: subDays(displayStart, 1).getTime(), }, }; await eventsCol!.findOne(event.id).update({ diff --git a/src/components/Calendar/eventFormSchema.tsx b/src/components/Calendar/eventFormSchema.tsx index 519a922c..4c1d7df5 100644 --- a/src/components/Calendar/eventFormSchema.tsx +++ b/src/components/Calendar/eventFormSchema.tsx @@ -15,14 +15,27 @@ const schemaDetails = z.object({ details: z.string().optional(), location: z.string().optional(), allDay: z.boolean(), - repeat: z.union([ + repeat: z.discriminatedUnion("type", [ z.object({ - type: z.union([ - z.literal("daily"), - z.literal("weekly"), - z.literal("monthly"), - z.literal("yearly"), - ]), + type: z.literal("daily"), + interval: z.number(), + mode: z.union([z.literal("count"), z.literal("date")]), + value: z.number(), + }), + z.object({ + type: z.literal("weekly"), + interval: z.number(), + mode: z.union([z.literal("count"), z.literal("date")]), + value: z.number(), + }), + z.object({ + type: z.literal("monthly"), + interval: z.number(), + mode: z.union([z.literal("count"), z.literal("date")]), + value: z.number(), + }), + z.object({ + type: z.literal("yearly"), interval: z.number(), mode: z.union([z.literal("count"), z.literal("date")]), value: z.number(), 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} +
+
+
);