diff --git a/apps/client/src/app/components/admin-tag/admin-tag.component.html b/apps/client/src/app/components/admin-tag/admin-tag.component.html index 463a817ff..3c125d5c0 100644 --- a/apps/client/src/app/components/admin-tag/admin-tag.component.html +++ b/apps/client/src/app/components/admin-tag/admin-tag.component.html @@ -47,7 +47,7 @@ diff --git a/apps/client/src/app/components/admin-tag/admin-tag.component.ts b/apps/client/src/app/components/admin-tag/admin-tag.component.ts index 56544f784..c00fe3a61 100644 --- a/apps/client/src/app/components/admin-tag/admin-tag.component.ts +++ b/apps/client/src/app/components/admin-tag/admin-tag.component.ts @@ -10,10 +10,12 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, + computed, DestroyRef, - Input, + inject, + input, OnInit, - ViewChild + viewChild } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { MatButtonModule } from '@angular/material/button'; @@ -52,26 +54,33 @@ import { CreateOrUpdateTagDialogParams } from './create-or-update-tag-dialog/int templateUrl: './admin-tag.component.html' }) export class GfAdminTagComponent implements OnInit { - @Input() locale = getLocale(); - - @ViewChild(MatSort) sort: MatSort; - - public dataSource = new MatTableDataSource(); - public deviceType: string; - public displayedColumns = ['name', 'userId', 'activities', 'actions']; - public tags: Tag[]; - - public constructor( - private changeDetectorRef: ChangeDetectorRef, - private dataService: DataService, - private destroyRef: DestroyRef, - private deviceDetectorService: DeviceDetectorService, - private dialog: MatDialog, - private notificationService: NotificationService, - private route: ActivatedRoute, - private router: Router, - private userService: UserService - ) { + public readonly locale = input(getLocale()); + + protected dataSource = new MatTableDataSource(); + protected readonly displayedColumns = [ + 'name', + 'userId', + 'activities', + 'actions' + ]; + protected tags: Tag[]; + + private readonly deviceType = computed( + () => this.deviceDetectorService.deviceInfo().deviceType + ); + private readonly sort = viewChild.required(MatSort); + + private readonly changeDetectorRef = inject(ChangeDetectorRef); + private readonly dataService = inject(DataService); + private readonly destroyRef = inject(DestroyRef); + private readonly deviceDetectorService = inject(DeviceDetectorService); + private readonly dialog = inject(MatDialog); + private readonly notificationService = inject(NotificationService); + private readonly route = inject(ActivatedRoute); + private readonly router = inject(Router); + private readonly userService = inject(UserService); + + public constructor() { this.route.queryParams .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe((params) => { @@ -83,7 +92,9 @@ export class GfAdminTagComponent implements OnInit { return id === params['tagId']; }); - this.openUpdateTagDialog(tag); + if (tag) { + this.openUpdateTagDialog(tag); + } } else { this.router.navigate(['.'], { relativeTo: this.route }); } @@ -94,12 +105,10 @@ export class GfAdminTagComponent implements OnInit { } public ngOnInit() { - this.deviceType = this.deviceDetectorService.getDeviceInfo().deviceType; - this.fetchTags(); } - public onDeleteTag(aId: string) { + protected onDeleteTag(aId: string) { this.notificationService.confirm({ confirmFn: () => { this.deleteTag(aId); @@ -109,7 +118,7 @@ export class GfAdminTagComponent implements OnInit { }); } - public onUpdateTag({ id }: Tag) { + protected onUpdateTag({ id }: Tag) { this.router.navigate([], { queryParams: { editTagDialog: true, tagId: id } }); @@ -139,7 +148,7 @@ export class GfAdminTagComponent implements OnInit { this.tags = tags; this.dataSource = new MatTableDataSource(this.tags); - this.dataSource.sort = this.sort; + this.dataSource.sort = this.sort(); this.dataSource.sortingDataAccessor = get; this.dataService.updateInfo(); @@ -153,14 +162,9 @@ export class GfAdminTagComponent implements OnInit { GfCreateOrUpdateTagDialogComponent, CreateOrUpdateTagDialogParams >(GfCreateOrUpdateTagDialogComponent, { - data: { - tag: { - id: null, - name: null - } - }, - height: this.deviceType === 'mobile' ? '98vh' : undefined, - width: this.deviceType === 'mobile' ? '100vw' : '50rem' + data: {} satisfies CreateOrUpdateTagDialogParams, + height: this.deviceType() === 'mobile' ? '98vh' : undefined, + width: this.deviceType() === 'mobile' ? '100vw' : '50rem' }); dialogRef @@ -197,9 +201,9 @@ export class GfAdminTagComponent implements OnInit { id, name } - }, - height: this.deviceType === 'mobile' ? '98vh' : undefined, - width: this.deviceType === 'mobile' ? '100vw' : '50rem' + } satisfies CreateOrUpdateTagDialogParams, + height: this.deviceType() === 'mobile' ? '98vh' : undefined, + width: this.deviceType() === 'mobile' ? '100vw' : '50rem' }); dialogRef diff --git a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts index e22c73478..dac4ea412 100644 --- a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts +++ b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts @@ -43,7 +43,7 @@ export class GfCreateOrUpdateTagDialogComponent { private formBuilder: FormBuilder ) { this.tagForm = this.formBuilder.group({ - name: [this.data.tag.name] + name: [this.data.tag?.name] }); } @@ -57,7 +57,7 @@ export class GfCreateOrUpdateTagDialogComponent { name: this.tagForm.get('name')?.value }; - if (this.data.tag.id) { + if (this.data.tag?.id) { (tag as UpdateTagDto).id = this.data.tag.id; await validateObjectForForm({ classDto: UpdateTagDto, diff --git a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html index d2fdad30e..876db206c 100644 --- a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html +++ b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html @@ -4,7 +4,7 @@ (keyup.enter)="tagForm.valid && onSubmit()" (ngSubmit)="onSubmit()" > - @if (data.tag.id) { + @if (data.tag?.id) {

Update tag

} @else {

Add tag

diff --git a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts index 4b7f83e93..f4b1104d0 100644 --- a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts +++ b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/interfaces/interfaces.ts @@ -1,5 +1,5 @@ import { Tag } from '@prisma/client'; export interface CreateOrUpdateTagDialogParams { - tag: Pick; + tag?: Pick; }