Skip to content

Commit

Permalink
šŸ› Fix: All day event doesn't disappear after changing the week - Atteā€¦
Browse files Browse the repository at this point in the history
ā€¦mpt #2 (#185)

* fix: remove updated events outside of current view

* refactor(web): reduce eventEntitiesSlice calls

use shouldRemove prop to determine whether to delete or edit (was previously calling both)

* 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)

* chore(web): cleanup useDraftUtil's submit

* refactor: simplify shouldRemove variable

---------

Co-authored-by: Tyler Dane <[email protected]>
  • Loading branch information
murilo9 and tyler-dane authored Dec 14, 2024
1 parent 92850d7 commit 4865fad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/web/src/ducks/events/event.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ interface Payload_DeleteEvent {
}

export interface Payload_EditEvent {
applyTo?: Categories_Recur;
_id: string;
event: Schema_Event;
applyTo?: Categories_Recur;
shouldRemove?: boolean;
}

export interface Payload_GetPaginatedEvents extends Filters_Pagination {
Expand Down
11 changes: 8 additions & 3 deletions packages/web/src/ducks/events/sagas/event.sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +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));
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) {
Expand Down
15 changes: 8 additions & 7 deletions packages/web/src/views/Calendar/hooks/draft/useDraftUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,17 @@ export const useDraftUtil = (

const submit = (draft: Schema_GridEvent) => {
const event = prepEvtBeforeSubmit(draft);
const { startOfView, endOfView } = weekProps.component;

const isExisting = event._id;
// include param for how to handle recurrences
if (isExisting) {
dispatch(
editEventSlice.actions.request({
_id: event._id,
event,
})
);
const isOutsideView =
!dayjs(event.startDate).isBetween(startOfView, endOfView, null, "[]") &&
!dayjs(event.endDate).isBetween(startOfView, endOfView, null, "[]");

const shouldRemove = isOutsideView ? true : false;
const payload = { _id: event._id, event, shouldRemove };
dispatch(editEventSlice.actions.request(payload));
} else {
dispatch(createEventSlice.actions.request(event));
}
Expand Down

0 comments on commit 4865fad

Please sign in to comment.