From 8659c16517d7b0c908e6a0eafb581001d2f7aee2 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Sun, 30 Mar 2025 10:43:36 +0200 Subject: [PATCH] refactor: Refactor SharedService, extract logic into smaller services (ResizeService and ColorService) --- .../components/add-task/add-task.component.ts | 18 +-- src/app/components/board/board.component.ts | 6 +- .../components/board/task/task.component.html | 2 +- .../components/board/task/task.component.ts | 6 +- .../contact-edit-new.component.ts | 6 +- .../contact-form/contact-form.component.html | 6 +- .../contact-form/contact-form.component.ts | 2 + src/app/services/color.service.ts | 34 +++++ src/app/services/login.service.ts | 6 +- src/app/services/resize.service.ts | 29 +++++ src/app/services/shared.service.ts | 116 ------------------ 11 files changed, 92 insertions(+), 139 deletions(-) create mode 100644 src/app/services/color.service.ts create mode 100644 src/app/services/resize.service.ts diff --git a/src/app/components/add-task/add-task.component.ts b/src/app/components/add-task/add-task.component.ts index 783e39e..400bf81 100644 --- a/src/app/components/add-task/add-task.component.ts +++ b/src/app/components/add-task/add-task.component.ts @@ -227,7 +227,7 @@ export class AddTaskComponent implements OnInit { * @returns The updated search input flag. */ updateSearchInput() { - this.searchValue = this.sharedService.replaceXSSChars(this.searchValue); + this.searchValue = this.replaceXSSChars(this.searchValue); if (this.searchValue) { this.searchInput = this.searchValue.toLowerCase().length > 0; } else { @@ -241,7 +241,7 @@ export class AddTaskComponent implements OnInit { * This ensures that the subtask value is sanitized before further processing or storage. */ updateSubtaskValue() { - this.subtaskValue = this.sharedService.replaceXSSChars(this.subtaskValue); + this.subtaskValue = this.replaceXSSChars(this.subtaskValue); } /** @@ -400,14 +400,10 @@ export class AddTaskComponent implements OnInit { * @returns {void} */ checkCrossSiteScripting() { - this.taskData.title = this.sharedService.replaceXSSChars( - this.taskData.title - ); - this.taskData.description = this.sharedService.replaceXSSChars( - this.taskData.description - ); + this.taskData.title = this.replaceXSSChars(this.taskData.title); + this.taskData.description = this.replaceXSSChars(this.taskData.description); this.taskData.subtasksTitle = this.taskData.subtasksTitle.map((title) => - this.sharedService.replaceXSSChars(title) + this.replaceXSSChars(title) ); } @@ -421,6 +417,10 @@ export class AddTaskComponent implements OnInit { this.closeDialog(); } + replaceXSSChars(input: string) { + return input.replace(//g, '>'); + } + @HostListener('document:click', ['$event']) /** * Closes the assigned dropdown menu if the user clicks anywhere outside of diff --git a/src/app/components/board/board.component.ts b/src/app/components/board/board.component.ts index 557739f..09dccb8 100644 --- a/src/app/components/board/board.component.ts +++ b/src/app/components/board/board.component.ts @@ -6,7 +6,6 @@ import { TaskEmptyComponent } from './task/task-empty/task-empty.component'; import { FormsModule } from '@angular/forms'; import { OverlayService } from '../../services/overlay.service'; import { Router } from '@angular/router'; -import { SharedService } from '../../services/shared.service'; import { TranslateModule } from '@ngx-translate/core'; import { TaskHighlightedComponent } from './task/task-highlighted/task-highlighted.component'; import { ApiService } from '../../services/api.service'; @@ -16,6 +15,7 @@ import { LoadingSpinnerComponent } from '../../shared/components/loading-spinner import { finalize, Subject, takeUntil } from 'rxjs'; import { TaskUpdateService } from '../../services/task-update.service'; import { ToastNotificationService } from '../../services/toast-notification.servic'; +import { ResizeService } from '../../services/resize.service'; @Component({ selector: 'app-board', @@ -43,7 +43,7 @@ export class BoardComponent { constructor( public dragDropService: DragDropService, public overlayService: OverlayService, - private sharedService: SharedService, + private resizeService: ResizeService, private taskService: TaskService, private apiService: ApiService, private taskUpdateService: TaskUpdateService, @@ -129,7 +129,7 @@ export class BoardComponent { * @param status The status to be used for the new task. */ addNewTaskOverlay(status: string) { - this.sharedService.isPageViewMedia + this.resizeService.isPageViewMedia ? this.router.navigate(['/add-task', status]) : this.overlayService.setOverlayData('newTaskOverlay', status); } diff --git a/src/app/components/board/task/task.component.html b/src/app/components/board/task/task.component.html index 77159d8..43a2351 100644 --- a/src/app/components/board/task/task.component.html +++ b/src/app/components/board/task/task.component.html @@ -13,7 +13,7 @@ > {{ task.category }} - @if (sharedService.isPageViewMedia) { + @if (resizeService.isPageViewMedia) {