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