From 5719fd39ea4438cb3b69b065b51009bf02af1d7b Mon Sep 17 00:00:00 2001 From: murilo9 Date: Wed, 11 Dec 2024 21:47:34 -0300 Subject: [PATCH 1/5] fix: remove updated events outside of current view --- packages/web/src/ducks/events/event.types.ts | 1 + .../web/src/ducks/events/sagas/event.sagas.ts | 3 +++ .../Calendar/hooks/draft/useDraftUtil.ts | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/web/src/ducks/events/event.types.ts b/packages/web/src/ducks/events/event.types.ts index 480f02e5..05bbcf12 100644 --- a/packages/web/src/ducks/events/event.types.ts +++ b/packages/web/src/ducks/events/event.types.ts @@ -77,6 +77,7 @@ export interface Payload_EditEvent { applyTo?: Categories_Recur; _id: string; event: Schema_Event; + shouldRemove: boolean; } export interface Payload_GetPaginatedEvents extends Filters_Pagination { diff --git a/packages/web/src/ducks/events/sagas/event.sagas.ts b/packages/web/src/ducks/events/sagas/event.sagas.ts index be33bd0e..a0c7ef11 100644 --- a/packages/web/src/ducks/events/sagas/event.sagas.ts +++ b/packages/web/src/ducks/events/sagas/event.sagas.ts @@ -166,6 +166,9 @@ export function* deleteSomedayEvent({ payload }: Action_DeleteEvent) { export function* editEvent({ payload }: Action_EditEvent) { try { yield put(eventsEntitiesSlice.actions.edit(payload)); + if (payload.shouldRemove) { + yield put(eventsEntitiesSlice.actions.delete({ _id: payload._id })); + } yield call(EventApi.edit, payload._id, payload.event, { applyTo: payload.applyTo, }); diff --git a/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts b/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts index eb75b98c..4d374d9e 100644 --- a/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts +++ b/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts @@ -377,16 +377,21 @@ export const useDraftUtil = ( const submit = (draft: Schema_GridEvent) => { const event = prepEvtBeforeSubmit(draft); - + const { startOfView, endOfView } = weekProps.component; + const eventEndsBeforeCurrentViewStart = dayjs(event.endDate).isBefore( + startOfView + ); + const eventBeginsAfterCurrentViewEnd = dayjs(event.startDate).isAfter( + endOfView + ); + // If the event will be rendered outside of view, marks it to be removed from store + const shouldRemove = + eventEndsBeforeCurrentViewStart || eventBeginsAfterCurrentViewEnd; + const payload = { _id: event._id, event, shouldRemove }; const isExisting = event._id; // include param for how to handle recurrences if (isExisting) { - dispatch( - editEventSlice.actions.request({ - _id: event._id, - event, - }) - ); + dispatch(editEventSlice.actions.request(payload)); } else { dispatch(createEventSlice.actions.request(event)); } From a5d3b471a486f219deafa47839ce2493af4cf4fc Mon Sep 17 00:00:00 2001 From: Tyler Dane Date: Thu, 12 Dec 2024 07:00:11 -0600 Subject: [PATCH 2/5] refactor(web): reduce eventEntitiesSlice calls use shouldRemove prop to determine whether to delete or edit (was previously calling both) --- packages/web/src/ducks/events/sagas/event.sagas.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/web/src/ducks/events/sagas/event.sagas.ts b/packages/web/src/ducks/events/sagas/event.sagas.ts index a0c7ef11..4765559a 100644 --- a/packages/web/src/ducks/events/sagas/event.sagas.ts +++ b/packages/web/src/ducks/events/sagas/event.sagas.ts @@ -164,13 +164,15 @@ export function* deleteSomedayEvent({ payload }: Action_DeleteEvent) { } export function* editEvent({ payload }: Action_EditEvent) { + const { _id, applyTo, event, shouldRemove } = payload; + try { - yield put(eventsEntitiesSlice.actions.edit(payload)); - if (payload.shouldRemove) { - yield put(eventsEntitiesSlice.actions.delete({ _id: payload._id })); - } - yield call(EventApi.edit, payload._id, payload.event, { - applyTo: payload.applyTo, + shouldRemove + ? yield put(eventsEntitiesSlice.actions.delete({ _id })) + : yield put(eventsEntitiesSlice.actions.edit(payload)); + + yield call(EventApi.edit, _id, event, { + applyTo: applyTo, }); yield put(editEventSlice.actions.success()); } catch (error) { From 335e00e538f201da60f36b21f11d25ca8624ea4c Mon Sep 17 00:00:00 2001 From: Tyler Dane Date: Thu, 12 Dec 2024 07:01:23 -0600 Subject: [PATCH 3/5] refactor(web): make shouldRemove prop optional this'll reduce the payload needed for when the sidebar calls this action (which doesn't need to use this concept of removing) --- packages/web/src/ducks/events/event.types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web/src/ducks/events/event.types.ts b/packages/web/src/ducks/events/event.types.ts index 05bbcf12..58f1a8b9 100644 --- a/packages/web/src/ducks/events/event.types.ts +++ b/packages/web/src/ducks/events/event.types.ts @@ -74,10 +74,10 @@ interface Payload_DeleteEvent { } export interface Payload_EditEvent { - applyTo?: Categories_Recur; _id: string; event: Schema_Event; - shouldRemove: boolean; + applyTo?: Categories_Recur; + shouldRemove?: boolean; } export interface Payload_GetPaginatedEvents extends Filters_Pagination { From 13442a9209febcc8f1ca3abd2c609c8012a666d5 Mon Sep 17 00:00:00 2001 From: Tyler Dane Date: Thu, 12 Dec 2024 07:02:06 -0600 Subject: [PATCH 4/5] chore(web): cleanup useDraftUtil's submit --- .../Calendar/hooks/draft/useDraftUtil.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts b/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts index 4d374d9e..8aac9aa1 100644 --- a/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts +++ b/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts @@ -378,19 +378,17 @@ export const useDraftUtil = ( const submit = (draft: Schema_GridEvent) => { const event = prepEvtBeforeSubmit(draft); const { startOfView, endOfView } = weekProps.component; - const eventEndsBeforeCurrentViewStart = dayjs(event.endDate).isBefore( - startOfView - ); - const eventBeginsAfterCurrentViewEnd = dayjs(event.startDate).isAfter( - endOfView - ); - // If the event will be rendered outside of view, marks it to be removed from store - const shouldRemove = - eventEndsBeforeCurrentViewStart || eventBeginsAfterCurrentViewEnd; - const payload = { _id: event._id, event, shouldRemove }; + const isExisting = event._id; - // include param for how to handle recurrences if (isExisting) { + const isOutsideView = + !dayjs(event.startDate).isBetween(startOfView, endOfView, null, "[]") && + !dayjs(event.endDate).isBetween(startOfView, endOfView, null, "[]"); + + const _payload = { _id: event._id, event }; + const payload = isOutsideView + ? { ..._payload, shouldRemove: true } + : _payload; dispatch(editEventSlice.actions.request(payload)); } else { dispatch(createEventSlice.actions.request(event)); From 6e20ac31657ddbe4a5a32aa0e611ce16b88ec17d Mon Sep 17 00:00:00 2001 From: Tyler Dane Date: Sat, 14 Dec 2024 06:14:46 -0600 Subject: [PATCH 5/5] refactor: simplify shouldRemove variable --- packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts b/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts index 8aac9aa1..6fe688dc 100644 --- a/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts +++ b/packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts @@ -385,10 +385,8 @@ export const useDraftUtil = ( !dayjs(event.startDate).isBetween(startOfView, endOfView, null, "[]") && !dayjs(event.endDate).isBetween(startOfView, endOfView, null, "[]"); - const _payload = { _id: event._id, event }; - const payload = isOutsideView - ? { ..._payload, shouldRemove: true } - : _payload; + const shouldRemove = isOutsideView ? true : false; + const payload = { _id: event._id, event, shouldRemove }; dispatch(editEventSlice.actions.request(payload)); } else { dispatch(createEventSlice.actions.request(event));