Skip to content

Commit aa9fdcb

Browse files
committed
feat(web): Add move to next/prev week/month shortcuts for someday event
1 parent 0224528 commit aa9fdcb

File tree

2 files changed

+94
-7
lines changed

2 files changed

+94
-7
lines changed

packages/web/src/common/utils/web.date.util.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,48 @@ export const setEventStartEndDatesToCurrentMonth = (
375375
endDate: monthEnd.format(),
376376
};
377377
};
378+
379+
export const setEventStartEndDates = (
380+
to: {
381+
direction: "prev" | "next" | "current";
382+
duration: "week" | "month";
383+
},
384+
event: Schema_Event,
385+
): Schema_Event => {
386+
const reference =
387+
to.direction === "current" ? dayjs(new Date()) : dayjs(event.startDate);
388+
389+
let start: Dayjs;
390+
let end: Dayjs;
391+
392+
if (to.duration === "week") {
393+
start = reference.startOf("week");
394+
end = reference.endOf("week");
395+
396+
if (to.direction === "prev") {
397+
start = start.subtract(1, "week");
398+
end = end.subtract(1, "week");
399+
} else if (to.direction === "next") {
400+
start = start.add(1, "week");
401+
end = end.add(1, "week");
402+
}
403+
} else {
404+
// duration is month
405+
start = reference.startOf("month");
406+
end = reference.endOf("month");
407+
408+
if (to.direction === "prev") {
409+
start = start.subtract(1, "month");
410+
end = end.subtract(1, "month");
411+
} else if (to.direction === "next") {
412+
start = start.add(1, "month");
413+
end = end.add(1, "month");
414+
}
415+
}
416+
417+
return {
418+
...event,
419+
startDate: start.format(),
420+
endDate: end.format(),
421+
};
422+
};

packages/web/src/views/Forms/SomedayEventForm/SomedayEventForm.tsx

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import { Key } from "ts-key-enum";
77
import { Categories_Event } from "@core/types/event.types";
88
import { ID_SOMEDAY_EVENT_FORM } from "@web/common/constants/web.constants";
99
import { colorByPriority } from "@web/common/styles/theme.util";
10-
import {
11-
setEventStartEndDatesToCurrentMonth,
12-
setEventStartEndDatesToCurrentWeek,
13-
} from "@web/common/utils/web.date.util";
10+
import { setEventStartEndDates } from "@web/common/utils/web.date.util";
1411
import { getSomedayEventsSlice } from "@web/ducks/events/slices/someday.slice";
1512
import { useAppDispatch } from "@web/store/store.hooks";
1613
import { useDraftContext } from "@web/views/Calendar/components/Draft/context/useDraftContext";
@@ -105,7 +102,6 @@ export const SomedayEventForm: React.FC<FormProps> = ({
105102
useHotkeys(
106103
"delete",
107104
() => {
108-
console.log("delete");
109105
const confirmed = window.confirm(
110106
`Delete ${event.title || "this event"}?`,
111107
);
@@ -140,7 +136,13 @@ export const SomedayEventForm: React.FC<FormProps> = ({
140136
"ctrl+meta+up",
141137
(e) => {
142138
e.preventDefault();
143-
const updatedEvent = setEventStartEndDatesToCurrentWeek(event);
139+
const updatedEvent = setEventStartEndDates(
140+
{
141+
direction: "current",
142+
duration: "week",
143+
},
144+
event,
145+
);
144146
onSubmit(updatedEvent);
145147
},
146148
hotkeysOptions,
@@ -151,7 +153,47 @@ export const SomedayEventForm: React.FC<FormProps> = ({
151153
"ctrl+meta+down",
152154
async (e) => {
153155
e.preventDefault();
154-
const updatedEvent = setEventStartEndDatesToCurrentMonth(event);
156+
const updatedEvent = setEventStartEndDates(
157+
{
158+
direction: "current",
159+
duration: "month",
160+
},
161+
event,
162+
);
163+
onSubmit(updatedEvent);
164+
},
165+
hotkeysOptions,
166+
[event],
167+
);
168+
169+
useHotkeys(
170+
"ctrl+meta+right",
171+
async (e) => {
172+
e.preventDefault();
173+
const updatedEvent = setEventStartEndDates(
174+
{
175+
direction: "next",
176+
duration: target,
177+
},
178+
event,
179+
);
180+
onSubmit(updatedEvent);
181+
},
182+
hotkeysOptions,
183+
[event],
184+
);
185+
186+
useHotkeys(
187+
"ctrl+meta+left",
188+
async (e) => {
189+
e.preventDefault();
190+
const updatedEvent = setEventStartEndDates(
191+
{
192+
direction: "prev",
193+
duration: target,
194+
},
195+
event,
196+
);
155197
onSubmit(updatedEvent);
156198
},
157199
hotkeysOptions,

0 commit comments

Comments
 (0)