From db242700e024e39878f551a454c7e74b909fa7b7 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Sun, 30 Mar 2025 19:29:24 +0200 Subject: [PATCH] refactor: SharedService refactored and dissolved, created ButtonStateService, renamed ContactEditDialog to ContactOverlay and moved to Overlays --- src/app/app.component.html | 2 +- src/app/app.component.ts | 3 +- .../components/add-task/add-task.component.ts | 2 - .../contact-delete.component.html | 19 --- .../contact-delete.component.scss | 109 ------------------ .../contact-delete.component.spec.ts | 23 ---- .../contact-delete.component.ts | 69 ----------- .../contact-detail.component.html | 15 +-- .../contact-detail.component.ts | 69 ++--------- .../contact-nav/contact-nav.component.html | 12 -- .../contact-nav/contact-nav.component.scss | 37 ------ .../contact-nav/contact-nav.component.spec.ts | 23 ---- .../contact-nav/contact-nav.component.ts | 17 --- .../contacts/contacts.component.html | 2 +- .../components/contacts/contacts.component.ts | 17 +-- .../login/forgot-pw/forgot-pw.component.html | 2 +- .../login/forgot-pw/forgot-pw.component.ts | 10 +- .../pw-reset/pw-reset.component.html | 2 +- .../forgot-pw/pw-reset/pw-reset.component.ts | 17 +-- .../loading-dialog.component.html | 2 +- .../loading-dialog.component.ts | 8 +- src/app/components/login/login.component.html | 15 ++- src/app/components/login/login.component.ts | 17 +-- .../login/register/register.component.html | 24 ++-- .../login/register/register.component.ts | 12 +- .../main-layout/main-layout.component.html | 27 +---- .../main-layout/main-layout.component.ts | 89 +++----------- src/app/services/button-state.service.ts | 16 +++ src/app/services/color.service.ts | 34 ------ src/app/services/login.service.ts | 24 ++-- src/app/services/shared.service.ts | 14 --- .../btn-close/btn-close.component.html | 2 +- .../buttons/btn-close/btn-close.component.ts | 17 +-- .../contact-form/contact-form.component.html | 5 +- .../contact-form/contact-form.component.scss | 0 .../contact-form.component.spec.ts | 0 .../contact-form/contact-form.component.ts | 90 ++++----------- .../contact-overlay.component.html} | 20 ++-- .../contact-overlay.component.scss} | 0 .../contact-overlay.component.spec.ts} | 12 +- .../contact-overlay.component.ts} | 44 ++++--- .../dialog-overlay.component.ts | 3 +- .../components/overlay/overlay.component.html | 8 +- .../components/overlay/overlay.component.ts | 2 + 44 files changed, 209 insertions(+), 726 deletions(-) delete mode 100644 src/app/components/contacts/contact-delete/contact-delete.component.html delete mode 100644 src/app/components/contacts/contact-delete/contact-delete.component.scss delete mode 100644 src/app/components/contacts/contact-delete/contact-delete.component.spec.ts delete mode 100644 src/app/components/contacts/contact-delete/contact-delete.component.ts delete mode 100644 src/app/components/contacts/contact-nav/contact-nav.component.html delete mode 100644 src/app/components/contacts/contact-nav/contact-nav.component.scss delete mode 100644 src/app/components/contacts/contact-nav/contact-nav.component.spec.ts delete mode 100644 src/app/components/contacts/contact-nav/contact-nav.component.ts create mode 100644 src/app/services/button-state.service.ts delete mode 100644 src/app/services/color.service.ts delete mode 100644 src/app/services/shared.service.ts rename src/app/{components/contacts/contact-edit-new => shared/components/overlay/contact-overlay}/contact-form/contact-form.component.html (97%) rename src/app/{components/contacts/contact-edit-new => shared/components/overlay/contact-overlay}/contact-form/contact-form.component.scss (100%) rename src/app/{components/contacts/contact-edit-new => shared/components/overlay/contact-overlay}/contact-form/contact-form.component.spec.ts (100%) rename src/app/{components/contacts/contact-edit-new => shared/components/overlay/contact-overlay}/contact-form/contact-form.component.ts (69%) rename src/app/{components/contacts/contact-edit-new/contact-edit-new.component.html => shared/components/overlay/contact-overlay/contact-overlay.component.html} (76%) rename src/app/{components/contacts/contact-edit-new/contact-edit-new.component.scss => shared/components/overlay/contact-overlay/contact-overlay.component.scss} (100%) rename src/app/{components/contacts/contact-edit-new/contact-edit-new.component.spec.ts => shared/components/overlay/contact-overlay/contact-overlay.component.spec.ts} (50%) rename src/app/{components/contacts/contact-edit-new/contact-edit-new.component.ts => shared/components/overlay/contact-overlay/contact-overlay.component.ts} (56%) diff --git a/src/app/app.component.html b/src/app/app.component.html index d324a65..0680b43 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1 +1 @@ - + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 05cffae..73f36da 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,11 +1,10 @@ import { Component } from '@angular/core'; import { RouterOutlet } from '@angular/router'; -import { OverlayComponent } from './shared/components/overlay/overlay.component'; @Component({ selector: 'app-root', standalone: true, - imports: [RouterOutlet, OverlayComponent], + imports: [RouterOutlet], templateUrl: './app.component.html', styleUrl: './app.component.scss', }) diff --git a/src/app/components/add-task/add-task.component.ts b/src/app/components/add-task/add-task.component.ts index 400bf81..58231df 100644 --- a/src/app/components/add-task/add-task.component.ts +++ b/src/app/components/add-task/add-task.component.ts @@ -9,7 +9,6 @@ import { OverlayService } from '../../services/overlay.service'; import { FormBtnComponent } from '../../shared/components/buttons/form-btn/form-btn.component'; import { ActivatedRoute, Router } from '@angular/router'; import { TranslateModule } from '@ngx-translate/core'; -import { SharedService } from '../../services/shared.service'; import { AuthService } from '../../services/auth.service'; import { firstValueFrom, map } from 'rxjs'; import { TaskService } from '../../services/task.service'; @@ -49,7 +48,6 @@ export class AddTaskComponent implements OnInit { constructor( public firebaseService: FirebaseService, private overlayService: OverlayService, - private sharedService: SharedService, private taskService: TaskService, private apiService: ApiService, private authService: AuthService, diff --git a/src/app/components/contacts/contact-delete/contact-delete.component.html b/src/app/components/contacts/contact-delete/contact-delete.component.html deleted file mode 100644 index e36ea35..0000000 --- a/src/app/components/contacts/contact-delete/contact-delete.component.html +++ /dev/null @@ -1,19 +0,0 @@ -
-
-

- {{ "contactDeleteDialog.deleteContact" | translate }} -

-
-
-
- {{ "contactDeleteDialog.btnCancel" | translate }} -
-
-
-
- {{ "contactDeleteDialog.btnDelete" | translate }} -
-
-
-
-
diff --git a/src/app/components/contacts/contact-delete/contact-delete.component.scss b/src/app/components/contacts/contact-delete/contact-delete.component.scss deleted file mode 100644 index 6245622..0000000 --- a/src/app/components/contacts/contact-delete/contact-delete.component.scss +++ /dev/null @@ -1,109 +0,0 @@ -section { - width: 100vw; - height: 100vh; - position: fixed; - top: 0; - left: 0; - right: 0; - bottom: 0; - display: flex; - justify-content: center; - align-items: center; -} - -.dialog { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - background-color: var(--white); - width: 600px; - height: 200px; - border-radius: 26px; - margin: 24px; - border: 2px solid rgba($color: #000000, $alpha: 0.1); - p { - text-align: center; - font-size: 27px; - font-weight: 500; - margin-bottom: 12px; - padding: 0 12px; - } -} - -.btns { - display: flex; - justify-content: center; - align-items: center; -} - -.btn { - display: flex; - flex-direction: column; - align-items: center; - width: 111px; - height: 57px; - margin: 0 24px; -} - -.btn-cancel { - padding: 12px; - margin: 12px 12px; - border-radius: 10px; - border-color: var(--black); - background-color: var(--dark-blue); - color: var(--white); - font-size: 23px; - font-weight: 400; - transition: 125ms ease-in-out; - cursor: pointer; - &:hover { - background-color: var(--light-blue); - box-shadow: 2px 2px 2px 0px rgba(0, 0, 0, 0.3); - } -} - -.btn-delete-contact { - padding: 12px; - margin: 12px 12px; - border-radius: 10px; - color: var(--red); - background-color: var(--white); - border: 1px solid var(--red); - font-size: 23px; - font-weight: 400; - transition: 125ms ease-in-out; - cursor: pointer; - &:hover { - color: var(--white); - background-color: var(--red); - border-color: var(--black); - box-shadow: 2px 2px 2px 0px rgba(0, 0, 0, 0.3); - } -} - -@media screen and (max-width: 450px) { - .dialog { - p { - font-size: 22px; - } - } -} - -@media screen and (max-width: 350px) { - .dialog { - width: 280px; - p { - font-size: 22px; - } - } - - .btn { - width: 100px; - } - - .btn-delete-contact, - .btn-cancel { - font-size: 18px; - } -} diff --git a/src/app/components/contacts/contact-delete/contact-delete.component.spec.ts b/src/app/components/contacts/contact-delete/contact-delete.component.spec.ts deleted file mode 100644 index 3516c68..0000000 --- a/src/app/components/contacts/contact-delete/contact-delete.component.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { ContactDeleteComponent } from './contact-delete.component'; - -describe('ContactDeleteComponent', () => { - let component: ContactDeleteComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [ContactDeleteComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(ContactDeleteComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/components/contacts/contact-delete/contact-delete.component.ts b/src/app/components/contacts/contact-delete/contact-delete.component.ts deleted file mode 100644 index e36f391..0000000 --- a/src/app/components/contacts/contact-delete/contact-delete.component.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { Component, Input } from '@angular/core'; -import { SharedService } from '../../../services/shared.service'; -import { TranslateModule } from '@ngx-translate/core'; -import { Router } from '@angular/router'; -import { FirebaseService } from '../../../services/firebase.service'; - -@Component({ - selector: 'app-contact-delete', - standalone: true, - imports: [TranslateModule], - templateUrl: './contact-delete.component.html', - styleUrl: './contact-delete.component.scss', -}) -export class ContactDeleteComponent { - @Input() currentUserId: string = ''; - - constructor( - private sharedService: SharedService, - private firebaseService: FirebaseService, - private router: Router - ) {} - - /** - * Deletes the current user and performs cleanup operations. - * This method deletes the user with the current user ID from the database, - * navigates to the contacts page, and closes any open dialog flags in the shared service. - * It also checks if the deleted contact was assigned to any tasks and removes them. - */ - deleteContact() { - this.firebaseService.deleteUser(this.currentUserId); - this.router.navigate(['contacts']); - this.sharedService.isDeleteContactDialogOpen = false; - this.sharedService.isAnyDialogOpen = false; - this.checkIfContactAnAssigned(); - } - - /** - * Checks if the deleted contact was assigned to any tasks and removes them. - * This method retrieves all tasks from the database, iterates over them, - * and checks if the current user ID is in the task's assigned array. - * If the ID is found, it is removed from the array and the modified task - * is updated in the database. - */ - checkIfContactAnAssigned() { - const tasks = this.firebaseService.getAllTasks(); - - tasks.forEach((task) => { - const index = task.assigned.indexOf(this.currentUserId); - if (index !== -1) { - task.assigned.splice(index, 1); - const { id, ...taskWithoutIds } = task; - if (task.id) { - this.firebaseService.replaceTaskData(task.id, taskWithoutIds); - } - } - }); - } - - /** - * Closes the delete contact dialog by setting the appropriate flags in the shared service. - * If the edit contact dialog is not open, it also closes any open dialog flags in the shared service. - */ - cancelDeleteContact() { - this.sharedService.isDeleteContactDialogOpen = false; - if (!this.sharedService.isEditContactDialogOpen) { - this.sharedService.isAnyDialogOpen = false; - } - } -} diff --git a/src/app/components/contacts/contact-detail/contact-detail.component.html b/src/app/components/contacts/contact-detail/contact-detail.component.html index b0b01fd..68fffbf 100644 --- a/src/app/components/contacts/contact-detail/contact-detail.component.html +++ b/src/app/components/contacts/contact-detail/contact-detail.component.html @@ -49,17 +49,17 @@ @if(selectedUser.isContactOnly || currentUser && selectedUser.id === currentUser.id) {
-
+
-

+

{{ "contacts.btnEdit0" | translate }}

@if (selectedUser.isContactOnly || currentUser && selectedUser.id !== currentUser.id) { -
+
-

+

{{ "contacts.btnDelete0" | translate }}

@@ -96,10 +96,7 @@
- } @if (sharedService.isMobileNavbarOpen) { - + } @if (isMobileNavbarOpen) { + } diff --git a/src/app/components/contacts/contact-detail/contact-detail.component.ts b/src/app/components/contacts/contact-detail/contact-detail.component.ts index 8cc59e9..b5cd883 100644 --- a/src/app/components/contacts/contact-detail/contact-detail.component.ts +++ b/src/app/components/contacts/contact-detail/contact-detail.component.ts @@ -1,26 +1,22 @@ import { Component, EventEmitter, - HostListener, Input, Output, SimpleChanges, } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { Router } from '@angular/router'; -import { SharedService } from '../../../services/shared.service'; -import { ContactNavComponent } from '../contact-nav/contact-nav.component'; import { FirebaseService } from '../../../services/firebase.service'; -import { LanguageService } from '../../../services/language.service'; import { TranslateModule } from '@ngx-translate/core'; import { UserService } from '../../../services/user.service'; import { finalize } from 'rxjs'; import { User } from '../../../interfaces/user.interface'; +import { OverlayService } from '../../../services/overlay.service'; @Component({ selector: 'app-contact-detail', standalone: true, - imports: [CommonModule, TranslateModule, ContactNavComponent], + imports: [CommonModule, TranslateModule], templateUrl: './contact-detail.component.html', styleUrl: './contact-detail.component.scss', }) @@ -31,10 +27,11 @@ export class ContactDetailComponent { isLoading: boolean = false; selectedUser: User | null = null; + isMobileNavbarOpen: boolean = false; constructor( - public sharedService: SharedService, public firebaseService: FirebaseService, + private overlayService: OverlayService, private userService: UserService ) {} @@ -84,68 +81,24 @@ export class ContactDetailComponent { * the mobile navigation bar when the user clicks the three points icon. */ toggleNav() { - this.sharedService.isMobileNavbarOpen = - !this.sharedService.isMobileNavbarOpen; + this.isMobileNavbarOpen = !this.isMobileNavbarOpen; } /** * Opens the edit contact dialog by setting the appropriate flags in the shared service. * This method is used by the contact details component to open the edit contact dialog when the user clicks the edit button. */ - openEditDialog() { - this.sharedService.isAnyDialogOpen = true; - this.sharedService.isEditContactDialogOpen = true; - this.sharedService.isMobileNavbarOpen = false; + editContact(userData: User) { + this.overlayService.setOverlayData('contactOverlay', userData); + this.isMobileNavbarOpen = false; } /** * Opens the delete contact dialog by setting the appropriate flags in the shared service. * This method is used by the contact details component to open the delete contact dialog when the user clicks the delete button. */ - deleteContact() { - this.sharedService.isAnyDialogOpen = true; - this.sharedService.isDeleteContactDialogOpen = true; - this.sharedService.isMobileNavbarOpen = false; - } - - @HostListener('document:click', ['$event']) - /** - * Handles the opening of the contact edit, new contact, and delete contact - * dialogs when the respective buttons are clicked. - * - * @param event The MouseEvent that was triggered. - */ - checkOpenContactEdit(event: MouseEvent) { - const targetElement = event.target as HTMLElement; - - if (targetElement.closest('.btn-edit')) { - this.setDialogStatus(true, true, false, false); - } else if (targetElement.closest('.btn-new')) { - this.setDialogStatus(true, false, true, false); - } else if (targetElement.closest('.btn-delete')) { - this.setDialogStatus(true, false, false, true); - } else if (!targetElement.closest('.dialog')) { - this.setDialogStatus(false, false, false, false); - } - } - - /** - * Updates the dialog status flags in the shared service. - * - * @param anyOpen - Indicates if any dialog is open. - * @param editOpen - Indicates if the edit contact dialog is open. - * @param newOpen - Indicates if the new contact dialog is open. - * @param deleteOpen - Indicates if the delete contact dialog is open. - */ - private setDialogStatus( - anyOpen: boolean, - editOpen: boolean, - newOpen: boolean, - deleteOpen: boolean - ) { - this.sharedService.isAnyDialogOpen = anyOpen; - this.sharedService.isEditContactDialogOpen = editOpen; - this.sharedService.isNewContactDialogOpen = newOpen; - this.sharedService.isDeleteContactDialogOpen = deleteOpen; + openDeleteContactDialog() { + // TODO + this.isMobileNavbarOpen = false; } } diff --git a/src/app/components/contacts/contact-nav/contact-nav.component.html b/src/app/components/contacts/contact-nav/contact-nav.component.html deleted file mode 100644 index 87744c2..0000000 --- a/src/app/components/contacts/contact-nav/contact-nav.component.html +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/src/app/components/contacts/contact-nav/contact-nav.component.scss b/src/app/components/contacts/contact-nav/contact-nav.component.scss deleted file mode 100644 index cda465e..0000000 --- a/src/app/components/contacts/contact-nav/contact-nav.component.scss +++ /dev/null @@ -1,37 +0,0 @@ -.navbar { - position: fixed; - display: flex; - flex-direction: column; - bottom: 146px; - right: 80px; - width: 110px; - height: 108px; - background-color: var(--bgSidebar); - border-radius: 20px 20px 0 20px; - box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.1); - padding: 10px; - z-index: 5; -} - -.link { - display: flex; - align-items: center; - height: 46px; - padding: 8px 16px; - border-radius: 8px; - color: var(--white); - cursor: pointer; - span { - text-align: center; - width: 118px; - word-wrap: break-word; - overflow-wrap: break-word; - white-space: normal; - } - &:hover { - background-color: var(--very-dark-blue); - span { - color: var(--light-blue); - } - } -} diff --git a/src/app/components/contacts/contact-nav/contact-nav.component.spec.ts b/src/app/components/contacts/contact-nav/contact-nav.component.spec.ts deleted file mode 100644 index 19227f5..0000000 --- a/src/app/components/contacts/contact-nav/contact-nav.component.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { ContactNavComponent } from './contact-nav.component'; - -describe('ContactNavComponent', () => { - let component: ContactNavComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [ContactNavComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(ContactNavComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/components/contacts/contact-nav/contact-nav.component.ts b/src/app/components/contacts/contact-nav/contact-nav.component.ts deleted file mode 100644 index 5386ee7..0000000 --- a/src/app/components/contacts/contact-nav/contact-nav.component.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Component, Input } from '@angular/core'; -import { SharedService } from '../../../services/shared.service'; -import { TranslateModule } from '@ngx-translate/core'; - -@Component({ - selector: 'app-contact-nav', - standalone: true, - imports: [TranslateModule], - templateUrl: './contact-nav.component.html', - styleUrl: './contact-nav.component.scss', -}) -export class ContactNavComponent { - @Input() deleteContact!: () => any; - @Input() openEditDialog!: () => any; - - constructor(public sharedService: SharedService) {} -} diff --git a/src/app/components/contacts/contacts.component.html b/src/app/components/contacts/contacts.component.html index c4d704d..a677a6a 100644 --- a/src/app/components/contacts/contacts.component.html +++ b/src/app/components/contacts/contacts.component.html @@ -5,7 +5,7 @@ 'd-none': !showAllUsers && selectedUserId != null }" > -