Fix #4014: auto-deselect task removed from current list

Ensure the detail panel closes when a scheduled (or removed) task
no longer appears in today's list by automatically deselecting it.
This resolves the issue where the detail panel remains stuck open
after scheduling a task into the future.
This commit is contained in:
Rafael Garcia 2025-03-25 21:41:21 +00:00 committed by Johannes Millan
parent 25047f31ed
commit 7972d4e1db

View file

@ -6,8 +6,10 @@ import {
ElementRef,
inject,
input,
OnChanges,
OnDestroy,
OnInit,
SimpleChanges,
ViewChild,
} from '@angular/core';
import { TaskService } from '../tasks/task.service';
@ -25,7 +27,7 @@ import {
zip,
} from 'rxjs';
import { TaskWithSubTasks } from '../tasks/task.model';
import { delay, filter, map, switchMap } from 'rxjs/operators';
import { delay, filter, map, switchMap, take } from 'rxjs/operators';
import { fadeAnimation } from '../../ui/animations/fade.ani';
import { PlanningModeService } from '../planning-mode/planning-mode.service';
import { T } from '../../t.const';
@ -85,7 +87,7 @@ import { TranslatePipe } from '@ngx-translate/core';
TranslatePipe,
],
})
export class WorkViewComponent implements OnInit, OnDestroy, AfterContentInit {
export class WorkViewComponent implements OnInit, OnChanges, OnDestroy, AfterContentInit {
taskService = inject(TaskService);
takeABreakService = inject(TakeABreakService);
planningModeService = inject(PlanningModeService);
@ -179,6 +181,26 @@ export class WorkViewComponent implements OnInit, OnDestroy, AfterContentInit {
);
}
ngOnChanges(changes: SimpleChanges): void {
const undoneChanges = changes['undoneTasks'];
const doneChanges = changes['doneTasks'];
if ((undoneChanges || doneChanges) && this.taskService.selectedTaskId$) {
const undoneArr = this.undoneTasks();
const doneArr = this.doneTasks();
const allTasks = [...undoneArr, ...doneArr];
this.taskService.selectedTaskId$.pipe(take(1)).subscribe((selectedTaskId) => {
if (selectedTaskId) {
const isSelectedStillPresent = allTasks.some((t) => t.id === selectedTaskId);
if (!isSelectedStillPresent) {
this.taskService.setSelectedId(null);
}
}
});
}
}
ngOnDestroy(): void {
if (this._switchListAnimationTimeout) {
window.clearTimeout(this._switchListAnimationTimeout);