refactor: replace subtasksTitle & subtasksStatus with subtasks in Task interface

This commit is contained in:
Chneemann 2025-04-03 04:34:09 +02:00
parent 94049f889d
commit eeb9f4303c
4 changed files with 25 additions and 35 deletions

View file

@ -226,15 +226,15 @@
</div> </div>
} @else { } @else {
<img class="add" src="./../../../assets/img/add.svg" alt="" /> <img class="add" src="./../../../assets/img/add.svg" alt="" />
} @if (taskData.subtasksTitle) { } @if (taskData.subtasks.length > 0) {
<div class="subtasks"> <div class="subtasks">
@for (task of taskData.subtasksTitle.reverse(); track task) { @for (subtask of taskData.subtasks.reverse(); track subtask.title) {
<div class="single-subtask"> <div class="single-subtask">
<p>- {{ task }}</p> <p>- {{ subtask.title }}</p>
<img <img
src="./../../../assets/img/close.svg" src="./../../../assets/img/close.svg"
alt="" alt=""
(click)="deleteSubtask(task)" (click)="deleteSubtask(subtask)"
/> />
</div> </div>
} }

View file

@ -2,7 +2,7 @@ import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { FormsModule, NgForm } from '@angular/forms'; import { FormsModule, NgForm } from '@angular/forms';
import { AssignedComponent } from './assigned/assigned.component'; import { AssignedComponent } from './assigned/assigned.component';
import { Task } from '../../interfaces/task.interface'; import { Subtask, Task } from '../../interfaces/task.interface';
import { OverlayService } from '../../services/overlay.service'; import { OverlayService } from '../../services/overlay.service';
import { FormBtnComponent } from '../../shared/components/buttons/form-btn/form-btn.component'; import { FormBtnComponent } from '../../shared/components/buttons/form-btn/form-btn.component';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
@ -54,8 +54,6 @@ export class AddTaskComponent implements OnInit {
status: this.taskService.getStatuses()[0], status: this.taskService.getStatuses()[0],
priority: this.taskService.getPriorities()[0], priority: this.taskService.getPriorities()[0],
subtasks: [], subtasks: [],
subtasksTitle: [],
subtasksStatus: [],
assigned: [], assigned: [],
assignees: [], assignees: [],
userData: [], userData: [],
@ -143,28 +141,21 @@ export class AddTaskComponent implements OnInit {
return this.apiService.getTaskById(taskId); return this.apiService.getTaskById(taskId);
} }
/**
* Adds a new subtask to the task data
* @param subtaskName the name of the new subtask
*/
addSubtask(subtaskName: string) { addSubtask(subtaskName: string) {
this.taskData.subtasksTitle.unshift(subtaskName); const newSubtask: Subtask = {
this.taskData.subtasksStatus.push(false); title: subtaskName,
status: false,
};
this.taskData.subtasks.push(newSubtask);
this.saveTaskData(); this.saveTaskData();
} }
/** deleteSubtask(subtaskToDelete: Subtask) {
* Deletes a subtask from the task data. this.taskData.subtasks = this.taskData.subtasks.filter(
* @param subtaskName the name of the subtask to delete (subtask) => subtask !== subtaskToDelete
*/ );
deleteSubtask(subtaskName: string) {
const index = this.taskData.subtasksTitle.indexOf(subtaskName);
if (index !== -1) {
this.taskData.subtasksTitle.splice(index, 1);
this.taskData.subtasksStatus.splice(index, 1);
this.saveTaskData(); this.saveTaskData();
} }
}
/** /**
* Updates the subtask value by removing any potential XSS characters. * Updates the subtask value by removing any potential XSS characters.
@ -269,8 +260,7 @@ export class AddTaskComponent implements OnInit {
this.taskData.date = this.currentDate; this.taskData.date = this.currentDate;
this.taskData.category = ''; this.taskData.category = '';
this.taskData.assigned = []; this.taskData.assigned = [];
this.taskData.subtasksTitle = []; this.taskData.subtasks = [];
this.taskData.subtasksStatus = [];
} }
/** /**
@ -318,12 +308,13 @@ export class AddTaskComponent implements OnInit {
* This ensures that the task data is safe to be stored in the Firebase Realtime Database. * This ensures that the task data is safe to be stored in the Firebase Realtime Database.
* @returns {void} * @returns {void}
*/ */
checkCrossSiteScripting() { checkCrossSiteScripting(): void {
this.taskData.title = this.replaceXSSChars(this.taskData.title); this.taskData.title = this.replaceXSSChars(this.taskData.title);
this.taskData.description = this.replaceXSSChars(this.taskData.description); this.taskData.description = this.replaceXSSChars(this.taskData.description);
this.taskData.subtasksTitle = this.taskData.subtasksTitle.map((title) => this.taskData.subtasks = this.taskData.subtasks.map((subtask) => ({
this.replaceXSSChars(title) ...subtask,
); title: this.replaceXSSChars(subtask.title),
}));
} }
/** /**

View file

@ -8,8 +8,6 @@ export interface Task {
status: string; status: string;
priority: string; priority: string;
subtasks: Subtask[]; subtasks: Subtask[];
subtasksTitle: string[];
subtasksStatus: boolean[];
assigned: string[]; assigned: string[];
assignees: Assignee[]; assignees: Assignee[];
userData: UserSummary[]; userData: UserSummary[];
@ -18,7 +16,7 @@ export interface Task {
} }
export interface Subtask { export interface Subtask {
id: string; id?: string;
title: string; title: string;
status: boolean; status: boolean;
} }

View file

@ -100,7 +100,8 @@
} @if (task.subtasks.length > 0) { } @if (task.subtasks.length > 0) {
<div class="subtasks"> <div class="subtasks">
<p>{{ "addTask.subtask" | translate }}:</p> <p>{{ "addTask.subtask" | translate }}:</p>
@for (subtask of task.subtasks; track subtask; let i = $index) { @for (subtask of task.subtasks; track subtask; let i = $index) { @if
(subtask.id) {
<div <div
class="single-subtask" class="single-subtask"
(click)=" (click)="
@ -122,7 +123,7 @@
/> />
<p>{{ subtask.title }}</p> <p>{{ subtask.title }}</p>
</div> </div>
} } }
</div> </div>
} }
</div> </div>