fix: crash when sub task is added via "planned-for-tomorrow" button

This commit is contained in:
Johannes Millan 2021-06-11 11:10:20 +02:00
parent 2dce5b04cf
commit bbb41c2ee1
3 changed files with 19 additions and 4 deletions

View file

@ -289,6 +289,13 @@ export class TaskService {
);
}
addTodayTag(t: Task) {
if (t.parentId) {
throw new Error('Sub task cannot be added a today tag');
}
this.updateTags(t, [TODAY_TAG.id, ...t.tagIds], t.tagIds);
}
updateTags(task: Task, newTagIds: string[], oldTagIds: string[]) {
if (task.parentId) {
throw new Error('Editing sub task tags should not be possible.');

View file

@ -400,7 +400,7 @@ export class TaskComponent implements OnInit, OnDestroy, AfterViewInit {
}
addToMyDay() {
this.onTagsUpdated([TODAY_TAG.id, ...this.task.tagIds]);
this._taskService.addTodayTag(this.task);
}
removeFromMyDay() {

View file

@ -31,7 +31,6 @@ import { T } from '../../t.const';
import { ImprovementService } from '../metric/improvement/improvement.service';
import { workViewProjectChangeAnimation } from '../../ui/animations/work-view-project-change.ani';
import { WorkContextService } from '../work-context/work-context.service';
import { TODAY_TAG } from '../tag/tag.const';
const SUB = 'SUB';
const PARENT = 'PARENT';
@ -163,8 +162,17 @@ export class WorkViewComponent implements OnInit, OnDestroy, AfterContentInit {
addAllPlannedToToday(plannedTasks: TaskPlanned[]) {
plannedTasks.forEach((t) => {
this.taskService.moveToProjectTodayList(t.id);
this.taskService.updateTags(t, [...t.tagIds, TODAY_TAG.id], t.tagIds);
if (t.parentId) {
this.taskService.moveToProjectTodayList(t.parentId);
this._subs.add(
this.taskService.getByIdOnce$(t.parentId).subscribe((parentTask) => {
this.taskService.addTodayTag(parentTask);
}),
);
} else {
this.taskService.moveToProjectTodayList(t.id);
this.taskService.addTodayTag(t);
}
});
}