Skip to content

Commit

Permalink
fix: fixed events erroring when triggering deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustChew committed Sep 28, 2024
1 parent 53e066b commit 1a83f62
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/components/Calendar/EventPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ const ConfirmDeleteEvent: FC<{ event: DisplayCalendarEvent }> = ({ event }) => {
<DialogContent>
<DialogHeader>
<DialogTitle>確認刪除</DialogTitle>
<DialogDescription>
<p>確定要刪除這個事件嗎?</p>
</DialogDescription>
<DialogDescription>確定要刪除這個事件嗎?</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose asChild>
Expand Down Expand Up @@ -67,7 +65,7 @@ const UpdateRepeatedEventDialog: FC<{
<DialogHeader>
<DialogTitle>更新重複事件</DialogTitle>
<DialogDescription>
<p>您要更新所有重複事件還是只更新這個事件?</p>
您要更新所有重複事件還是只更新這個事件?
</DialogDescription>
</DialogHeader>
<DialogFooter>
Expand Down Expand Up @@ -103,7 +101,7 @@ const DeleteRepeatedEventDialog: FC<{
<DialogHeader>
<DialogTitle>刪除重複事件</DialogTitle>
<DialogDescription>
<p>您要刪除所有重複事件還是只刪除這個事件</p>
您要刪除所有重複事件還是只刪除這個事件
</DialogDescription>
</DialogHeader>
<DialogFooter>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Calendar/UpcomingEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const UpcomingEvents = () => {
brightness > 186 ? 0.2 : 0.95,
);
return (
<EventPopover event={event} key={event.id}>
<EventPopover event={event} key={event.id + index}>
<div
className="self-stretch px-2 pt-2 pb-6 rounded-md flex-col justify-start items-start gap-2 flex"
style={{ background: event.color, color: textColor }}
Expand Down
19 changes: 11 additions & 8 deletions src/components/Calendar/calendar_hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import useUserTimetable from "@/hooks/contexts/useUserTimetable";
import { useRxCollection, useRxDB, useRxQuery } from "rxdb-hooks";
import { getDiffFunction, getActualEndDate } from "./calendar_utils";
import { subDays } from "date-fns";
import { serializeEvent } from "@/components/Calendar/calendar_utils";
import {
serializeEvent,
getDisplayEndDate,
} from "@/components/Calendar/calendar_utils";
import { EventDocType } from "@/config/rxdb";
import { useAuthState } from "react-firebase-hooks/auth";
import { auth, firebaseConfig, db as firebaseDb } from "@/config/firebase";
Expand Down Expand Up @@ -137,23 +140,23 @@ export const useCalendarProvider = () => {
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({
Expand Down

0 comments on commit 1a83f62

Please sign in to comment.