diff --git a/projects/cobbler-frontend/src/app/actions/hardlink/hardlink.component.ts b/projects/cobbler-frontend/src/app/actions/hardlink/hardlink.component.ts index 4bb6bcb2..66d8a01f 100644 --- a/projects/cobbler-frontend/src/app/actions/hardlink/hardlink.component.ts +++ b/projects/cobbler-frontend/src/app/actions/hardlink/hardlink.component.ts @@ -1,41 +1,49 @@ -import { Component } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; import { MatButton } from '@angular/material/button'; import { MatSnackBar } from '@angular/material/snack-bar'; import { CobblerApiService } from 'cobbler-api'; import { UserService } from '../../services/user.service'; +import { Subscription } from 'rxjs'; @Component({ selector: 'cobbler-hardlink', standalone: true, - imports: [ - MatButton - ], + imports: [MatButton], templateUrl: './hardlink.component.html', - styleUrl: './hardlink.component.scss' + styleUrl: './hardlink.component.scss', }) -export class HardlinkComponent { +export class HardlinkComponent implements OnDestroy { + private subs: Subscription = new Subscription(); constructor( public userService: UserService, private cobblerApiService: CobblerApiService, private _snackBar: MatSnackBar - ) { + ) {} + + ngOnDestroy(): void { + this.subs.unsubscribe(); } runHardlink(): void { - this.cobblerApiService.background_hardlink(this.userService.token).subscribe( - value => { - // TODO - }, - error => { - // HTML encode the error message since it originates from XML - this._snackBar.open(this.toHTML(error.message), 'Close'); - }); + this.subs.add( + this.cobblerApiService + .background_hardlink(this.userService.token) + .subscribe({ + next: (value) => { + // TODO + }, + error: (error) => { + // HTML encode the error message since it originates from XML + this._snackBar.open(this.toHTML(error.message), 'Close'); + }, + }) + ); } toHTML(input: string): any { // FIXME: Deduplicate method - return new DOMParser().parseFromString(input, 'text/html').documentElement.textContent; + return new DOMParser().parseFromString(input, 'text/html').documentElement + .textContent; } - }