fix: adding different icons inside dialog menu when the user adds the today tag

This commit is contained in:
panoramix360 2024-10-19 18:36:44 -03:00 committed by Johannes Millan
parent 2a05e32d05
commit 4943209d6b
2 changed files with 44 additions and 17 deletions

View file

@ -11,8 +11,13 @@
(click)="quickAccessBtnClick(0)"
[matTooltip]="(T.F.TASK.D_SCHEDULE_TASK.QA_TODAY|translate)"
>
<mat-icon>wb_sunny</mat-icon>
<mat-icon *ngIf="isTaskPlannedForToday()">wb_sunny</mat-icon>
<mat-icon
*ngIf="isTaskNotPlannedForToday()"
svgIcon="remove_today"
></mat-icon>
</button>
<button
mat-icon-button
(click)="quickAccessBtnClick(1)"

View file

@ -38,6 +38,11 @@ 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';
import {
isTaskNotPlannedForToday,
isTaskPlannedForToday,
} from '../../tasks/util/is-task-today';
import { WorkContextService } from '../../work-context/work-context.service';
@Component({
selector: 'dialog-schedule-task',
@ -77,6 +82,7 @@ export class DialogScheduleTaskComponent implements AfterViewInit {
private _snackService: SnackService,
private _datePipe: DatePipe,
private _taskService: TaskService,
private workContextService: WorkContextService,
private _reminderService: ReminderService,
private _plannerService: PlannerService,
private readonly _dateAdapter: DateAdapter<unknown>,
@ -175,6 +181,17 @@ export class DialogScheduleTaskComponent implements AfterViewInit {
}
}
addToMyDay(): void {
this._taskService.addTodayTag(this.data.task);
}
removeFromMyDay(): void {
this._taskService.updateTags(
this.data.task,
this.data.task.tagIds.filter((tid) => tid !== TODAY_TAG.id),
);
}
onTimeKeyDown(ev: KeyboardEvent): void {
// console.log('ev.key!', ev.key);
if (ev.key === 'Enter') {
@ -283,25 +300,22 @@ export class DialogScheduleTaskComponent implements AfterViewInit {
false,
);
if (isTodayI) {
this._taskService.updateTags(task, [TODAY_TAG.id, ...task.tagIds]);
this.addToMyDay();
} else {
this._taskService.updateTags(
task,
task.tagIds.filter((tid) => tid !== TODAY_TAG.id),
);
this.removeFromMyDay();
}
} else if (newDay === getWorklogStr()) {
this._store.dispatch(
updateTaskTags({
task: this.data.task,
newTagIds: [...this.data.task.tagIds, TODAY_TAG.id],
}),
);
this._snackService.open({
type: 'SUCCESS',
msg: T.F.PLANNER.S.TASK_PLANNED_FOR,
translateParams: { date: formattedDate },
});
if (this.isTaskPlannedForToday()) {
this.addToMyDay();
this._snackService.open({
type: 'SUCCESS',
msg: T.F.PLANNER.S.TASK_PLANNED_FOR,
translateParams: { date: formattedDate },
});
} else {
this.removeFromMyDay();
}
} else {
this._store.dispatch(
PlannerActions.planTaskForDay({ task: this.data.task, day: newDay }),
@ -347,4 +361,12 @@ export class DialogScheduleTaskComponent implements AfterViewInit {
this.submit();
}
isTaskNotPlannedForToday(): boolean {
return isTaskNotPlannedForToday(this.task);
}
isTaskPlannedForToday(): boolean {
return isTaskPlannedForToday(this.task, this.workContextService.isToday);
}
}