refactor: Rename TaskUpdateService to UpdateNotifierService and added notify for contacts
This commit is contained in:
parent
ce2f9ed228
commit
c57926b731
8 changed files with 49 additions and 32 deletions
|
|
@ -13,7 +13,7 @@ import { AuthService } from '../../services/auth.service';
|
||||||
import { firstValueFrom, map } from 'rxjs';
|
import { firstValueFrom, map } from 'rxjs';
|
||||||
import { TaskService } from '../../services/task.service';
|
import { TaskService } from '../../services/task.service';
|
||||||
import { ApiService } from '../../services/api.service';
|
import { ApiService } from '../../services/api.service';
|
||||||
import { TaskUpdateService } from '../../services/task-update.service';
|
import { UpdateNotifierService } from '../../services/update-notifier.service';
|
||||||
import { ToastNotificationService } from '../../services/toast-notification.servic';
|
import { ToastNotificationService } from '../../services/toast-notification.servic';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
@ -51,7 +51,7 @@ export class AddTaskComponent implements OnInit {
|
||||||
private taskService: TaskService,
|
private taskService: TaskService,
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private taskUpdateService: TaskUpdateService,
|
private updateNotifierService: UpdateNotifierService,
|
||||||
private toastNotificationService: ToastNotificationService,
|
private toastNotificationService: ToastNotificationService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router
|
private router: Router
|
||||||
|
|
@ -380,7 +380,7 @@ export class AddTaskComponent implements OnInit {
|
||||||
this.apiService.saveNewTask(taskWithoutId).subscribe({
|
this.apiService.saveNewTask(taskWithoutId).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.toastNotificationService.createTaskSuccessToast();
|
this.toastNotificationService.createTaskSuccessToast();
|
||||||
this.taskUpdateService.notifyTaskUpdate();
|
this.updateNotifierService.notifyUpdate('task');
|
||||||
this.removeTaskData(ngForm);
|
this.removeTaskData(ngForm);
|
||||||
this.closeOverlay();
|
this.closeOverlay();
|
||||||
this.router.navigate(['/board']);
|
this.router.navigate(['/board']);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { Task } from '../../interfaces/task.interface';
|
||||||
import { TaskService } from '../../services/task.service';
|
import { TaskService } from '../../services/task.service';
|
||||||
import { LoadingSpinnerComponent } from '../../shared/components/loading-spinner/loading-spinner.component';
|
import { LoadingSpinnerComponent } from '../../shared/components/loading-spinner/loading-spinner.component';
|
||||||
import { finalize, Subject, takeUntil } from 'rxjs';
|
import { finalize, Subject, takeUntil } from 'rxjs';
|
||||||
import { TaskUpdateService } from '../../services/task-update.service';
|
import { UpdateNotifierService } from '../../services/update-notifier.service';
|
||||||
import { ToastNotificationService } from '../../services/toast-notification.servic';
|
import { ToastNotificationService } from '../../services/toast-notification.servic';
|
||||||
import { ResizeService } from '../../services/resize.service';
|
import { ResizeService } from '../../services/resize.service';
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ export class BoardComponent {
|
||||||
private resizeService: ResizeService,
|
private resizeService: ResizeService,
|
||||||
private taskService: TaskService,
|
private taskService: TaskService,
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private taskUpdateService: TaskUpdateService,
|
private updateNotifierService: UpdateNotifierService,
|
||||||
private toastNotificationService: ToastNotificationService,
|
private toastNotificationService: ToastNotificationService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
@ -95,7 +95,7 @@ export class BoardComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
private subscribeToTaskUpdates() {
|
private subscribeToTaskUpdates() {
|
||||||
this.taskUpdateService.taskUpdated$
|
this.updateNotifierService.taskUpdated$
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
this.loadAllTasks();
|
this.loadAllTasks();
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { User } from '../../../interfaces/user.interface';
|
||||||
import { OverlayService } from '../../../services/overlay.service';
|
import { OverlayService } from '../../../services/overlay.service';
|
||||||
import { ApiService } from '../../../services/api.service';
|
import { ApiService } from '../../../services/api.service';
|
||||||
import { ToastNotificationService } from '../../../services/toast-notification.servic';
|
import { ToastNotificationService } from '../../../services/toast-notification.servic';
|
||||||
|
import { UpdateNotifierService } from '../../../services/update-notifier.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-contact-detail',
|
selector: 'app-contact-detail',
|
||||||
|
|
@ -36,7 +37,8 @@ export class ContactDetailComponent {
|
||||||
private overlayService: OverlayService,
|
private overlayService: OverlayService,
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private toastNotificationService: ToastNotificationService
|
private toastNotificationService: ToastNotificationService,
|
||||||
|
private updateNotifierService: UpdateNotifierService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
|
|
@ -97,14 +99,11 @@ export class ContactDetailComponent {
|
||||||
this.isMobileNavbarOpen = false;
|
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.
|
|
||||||
*/
|
|
||||||
async deleteContact(userId: string) {
|
async deleteContact(userId: string) {
|
||||||
try {
|
try {
|
||||||
await lastValueFrom(this.apiService.deleteUserById(userId));
|
await lastValueFrom(this.apiService.deleteUserById(userId));
|
||||||
this.toastNotificationService.deleteContactSuccessToast();
|
this.toastNotificationService.deleteContactSuccessToast();
|
||||||
|
this.updateNotifierService.notifyUpdate('contact');
|
||||||
this.closeUserDetails();
|
this.closeUserDetails();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@
|
||||||
@for (sortLetter of this.getUniqueFirstLetters(); track sortLetter) {
|
@for (sortLetter of this.getUniqueFirstLetters(); track sortLetter) {
|
||||||
<div class="first-letter">{{ sortLetter }}</div>
|
<div class="first-letter">{{ sortLetter }}</div>
|
||||||
<div class="line"></div>
|
<div class="line"></div>
|
||||||
@for (user of this.filterUsersByFirstLetter(sortLetter); track user; let
|
@for (user of this.filterUsersByFirstLetter(sortLetter); track user.id;
|
||||||
index = $index) {
|
let index = $index) {
|
||||||
<div
|
<div
|
||||||
class="contact"
|
class="contact"
|
||||||
(click)="openUserDetails(user.id)"
|
(click)="openUserDetails(user.id)"
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ import { ContactDetailComponent } from './contact-detail/contact-detail.componen
|
||||||
import { FirebaseService } from '../../services/firebase.service';
|
import { FirebaseService } from '../../services/firebase.service';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { UserService } from '../../services/user.service';
|
import { UserService } from '../../services/user.service';
|
||||||
import { finalize } from 'rxjs';
|
import { finalize, Subject, takeUntil } from 'rxjs';
|
||||||
import { OverlayService } from '../../services/overlay.service';
|
import { OverlayService } from '../../services/overlay.service';
|
||||||
|
import { UpdateNotifierService } from '../../services/update-notifier.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-contacts',
|
selector: 'app-contacts',
|
||||||
|
|
@ -16,6 +17,8 @@ import { OverlayService } from '../../services/overlay.service';
|
||||||
styleUrl: './contacts.component.scss',
|
styleUrl: './contacts.component.scss',
|
||||||
})
|
})
|
||||||
export class ContactsComponent {
|
export class ContactsComponent {
|
||||||
|
private destroy$ = new Subject<void>();
|
||||||
|
|
||||||
allUsers: User[] = [];
|
allUsers: User[] = [];
|
||||||
currentUser: User | null = null;
|
currentUser: User | null = null;
|
||||||
selectedUserId: string | null = null;
|
selectedUserId: string | null = null;
|
||||||
|
|
@ -25,7 +28,8 @@ export class ContactsComponent {
|
||||||
constructor(
|
constructor(
|
||||||
public firebaseService: FirebaseService,
|
public firebaseService: FirebaseService,
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
private overlayService: OverlayService
|
private overlayService: OverlayService,
|
||||||
|
private updateNotifierService: UpdateNotifierService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -35,6 +39,7 @@ export class ContactsComponent {
|
||||||
this.onResize();
|
this.onResize();
|
||||||
this.loadAllUsers();
|
this.loadAllUsers();
|
||||||
this.loadCurrentUser();
|
this.loadCurrentUser();
|
||||||
|
this.subscribeToUserUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAllUsers(): void {
|
loadAllUsers(): void {
|
||||||
|
|
@ -53,6 +58,14 @@ export class ContactsComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private subscribeToUserUpdates() {
|
||||||
|
this.updateNotifierService.contactUpdated$
|
||||||
|
.pipe(takeUntil(this.destroy$))
|
||||||
|
.subscribe(() => {
|
||||||
|
this.loadAllUsers();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
loadCurrentUser(): void {
|
loadCurrentUser(): void {
|
||||||
this.userService.getCurrentUser().subscribe((userData) => {
|
this.userService.getCurrentUser().subscribe((userData) => {
|
||||||
this.currentUser = userData;
|
this.currentUser = userData;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { Subject } from 'rxjs';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class TaskUpdateService {
|
|
||||||
private taskUpdatedSubject = new Subject<void>();
|
|
||||||
taskUpdated$ = this.taskUpdatedSubject.asObservable();
|
|
||||||
|
|
||||||
notifyTaskUpdate() {
|
|
||||||
this.taskUpdatedSubject.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
19
src/app/services/update-notifier.service.ts
Normal file
19
src/app/services/update-notifier.service.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class UpdateNotifierService {
|
||||||
|
private updateSubjects: Record<string, Subject<void>> = {
|
||||||
|
task: new Subject<void>(),
|
||||||
|
contact: new Subject<void>(),
|
||||||
|
};
|
||||||
|
|
||||||
|
taskUpdated$ = this.updateSubjects['task'].asObservable();
|
||||||
|
contactUpdated$ = this.updateSubjects['contact'].asObservable();
|
||||||
|
|
||||||
|
notifyUpdate(type: 'task' | 'contact') {
|
||||||
|
this.updateSubjects[type].next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ import { TaskService } from '../../../../services/task.service';
|
||||||
import { AuthService } from '../../../../services/auth.service';
|
import { AuthService } from '../../../../services/auth.service';
|
||||||
import { map } from 'rxjs';
|
import { map } from 'rxjs';
|
||||||
import { ApiService } from '../../../../services/api.service';
|
import { ApiService } from '../../../../services/api.service';
|
||||||
import { TaskUpdateService } from '../../../../services/task-update.service';
|
import { UpdateNotifierService } from '../../../../services/update-notifier.service';
|
||||||
import { ToastNotificationService } from '../../../../services/toast-notification.servic';
|
import { ToastNotificationService } from '../../../../services/toast-notification.servic';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
@ -35,7 +35,7 @@ export class TaskOverlayComponent implements OnInit {
|
||||||
private taskService: TaskService,
|
private taskService: TaskService,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private taskUpdateService: TaskUpdateService,
|
private updateNotifierService: UpdateNotifierService,
|
||||||
private toastNotificationService: ToastNotificationService,
|
private toastNotificationService: ToastNotificationService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private route: ActivatedRoute
|
private route: ActivatedRoute
|
||||||
|
|
@ -126,7 +126,7 @@ export class TaskOverlayComponent implements OnInit {
|
||||||
this.apiService.deleteTaskById(taskId).subscribe({
|
this.apiService.deleteTaskById(taskId).subscribe({
|
||||||
next: (task) => {
|
next: (task) => {
|
||||||
this.toastNotificationService.deleteTaskSuccessToast();
|
this.toastNotificationService.deleteTaskSuccessToast();
|
||||||
this.taskUpdateService.notifyTaskUpdate();
|
this.updateNotifierService.notifyUpdate('task');
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
console.error('Error deleting task', err);
|
console.error('Error deleting task', err);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue