From 677ec4972665519e16fbae0c0d46be3210590672 Mon Sep 17 00:00:00 2001 From: Michael Huynh Date: Sun, 6 Oct 2024 15:53:18 +0800 Subject: [PATCH] fix: follow setting when quick scheduling next week (#3373) --- .../dialog-schedule-task.component.ts | 13 ++++++++++--- .../task-context-menu-inner.component.ts | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/app/features/planner/dialog-schedule-task/dialog-schedule-task.component.ts b/src/app/features/planner/dialog-schedule-task/dialog-schedule-task.component.ts index 4b7579a1537..306809ae8c9 100644 --- a/src/app/features/planner/dialog-schedule-task/dialog-schedule-task.component.ts +++ b/src/app/features/planner/dialog-schedule-task/dialog-schedule-task.component.ts @@ -37,6 +37,7 @@ import { PlannerService } from '../planner.service'; import { first } from 'rxjs/operators'; import { fadeAnimation } from '../../../ui/animations/fade.ani'; import { dateStrToUtcDate } from '../../../util/date-str-to-utc-date'; +import { DateAdapter } from '@angular/material/core'; @Component({ selector: 'dialog-schedule-task', @@ -78,6 +79,7 @@ export class DialogScheduleTaskComponent implements AfterViewInit { private _taskService: TaskService, private _reminderService: ReminderService, private _plannerService: PlannerService, + private readonly _dateAdapter: DateAdapter, ) {} async ngAfterViewInit(): Promise { @@ -327,9 +329,14 @@ export class DialogScheduleTaskComponent implements AfterViewInit { this.selectedDate = tomorrow; break; case 2: - const nextMonday = tDate; - nextMonday.setDate(nextMonday.getDate() + ((1 + 7 - nextMonday.getDay()) % 7)); - this.selectedDate = nextMonday; + const nextFirstDayOfWeek = tDate; + const dayOffset = + (this._dateAdapter.getFirstDayOfWeek() - + this._dateAdapter.getDayOfWeek(nextFirstDayOfWeek) + + 7) % + 7 || 7; + nextFirstDayOfWeek.setDate(nextFirstDayOfWeek.getDate() + dayOffset); + this.selectedDate = nextFirstDayOfWeek; break; case 3: const nextMonth = tDate; diff --git a/src/app/features/tasks/task-context-menu/task-context-menu-inner/task-context-menu-inner.component.ts b/src/app/features/tasks/task-context-menu/task-context-menu-inner/task-context-menu-inner.component.ts index cbc3b1b8155..1c69e83c6bb 100644 --- a/src/app/features/tasks/task-context-menu/task-context-menu-inner/task-context-menu-inner.component.ts +++ b/src/app/features/tasks/task-context-menu/task-context-menu-inner/task-context-menu-inner.component.ts @@ -63,6 +63,7 @@ import { PlannerActions } from '../../../planner/store/planner.actions'; import { combineDateAndTime } from '../../../../util/combine-date-and-time'; import { FocusModeService } from '../../../focus-mode/focus-mode.service'; import { isToday } from '../../../../util/is-today.util'; +import { DateAdapter } from '@angular/material/core'; @Component({ selector: 'task-context-menu-inner', @@ -159,6 +160,7 @@ export class TaskContextMenuInnerComponent implements AfterViewInit { private readonly _globalConfigService: GlobalConfigService, private readonly _store: Store, private readonly _focusModeService: FocusModeService, + private readonly _dateAdapter: DateAdapter, ) {} ngAfterViewInit(): void { @@ -495,9 +497,14 @@ export class TaskContextMenuInnerComponent implements AfterViewInit { this._schedule(tomorrow); break; case 2: - const nextMonday = tDate; - nextMonday.setDate(nextMonday.getDate() + ((1 + 7 - nextMonday.getDay()) % 7)); - this._schedule(nextMonday); + const nextFirstDayOfWeek = tDate; + const dayOffset = + (this._dateAdapter.getFirstDayOfWeek() - + this._dateAdapter.getDayOfWeek(nextFirstDayOfWeek) + + 7) % + 7 || 7; + nextFirstDayOfWeek.setDate(nextFirstDayOfWeek.getDate() + dayOffset); + this._schedule(nextFirstDayOfWeek); break; case 3: const nextMonth = tDate;