Optimized code #133
This commit is contained in:
@@ -1,29 +1,27 @@
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { Component, OnDestroy, OnInit } from "@angular/core";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { PrimeNGConfig } from "primeng/api";
|
||||
import { AuthService } from "./services/auth/auth.service";
|
||||
import { SocketService } from "./services/socket/socket.service";
|
||||
import { ThemeService } from "./services/theme/theme.service";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { SpinnerService } from "./services/spinner/spinner.service";
|
||||
import { DataService } from "./services/data/data.service";
|
||||
import { SidebarService } from "./services/sidebar/sidebar.service";
|
||||
import { Server } from "./models/data/server.model";
|
||||
import { Queries } from "./models/graphql/queries.model";
|
||||
import { Query } from "./models/graphql/query.model";
|
||||
import { Subject } from "rxjs";
|
||||
import { Themes } from "./models/view/themes.enum";
|
||||
import { takeUntil } from "rxjs/operators";
|
||||
|
||||
@Component({
|
||||
selector: "app-root",
|
||||
templateUrl: "./app.component.html",
|
||||
styleUrls: ["./app.component.scss"]
|
||||
})
|
||||
export class AppComponent implements OnInit {
|
||||
export class AppComponent implements OnInit, OnDestroy {
|
||||
|
||||
themeName!: string;
|
||||
sidebarWidth!: string;
|
||||
themeName: string = Themes.Default;
|
||||
sidebarWidth: string = '175px';
|
||||
|
||||
isLoggedIn: boolean = false;
|
||||
|
||||
private unsubscriber = new Subject<void>();
|
||||
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private themeService: ThemeService,
|
||||
@@ -31,13 +29,19 @@ export class AppComponent implements OnInit {
|
||||
private translateService: TranslateService,
|
||||
private config: PrimeNGConfig,
|
||||
) {
|
||||
this.themeService.sidebarWidth$.subscribe(value => {
|
||||
this.themeService.sidebarWidth$.pipe(
|
||||
takeUntil(this.unsubscriber)
|
||||
).subscribe(value => {
|
||||
this.sidebarWidth = value;
|
||||
});
|
||||
this.themeService.themeName$.subscribe(value => {
|
||||
this.themeService.themeName$.pipe(
|
||||
takeUntil(this.unsubscriber)
|
||||
).subscribe(value => {
|
||||
this.themeName = value;
|
||||
});
|
||||
this.authService.isLoggedIn$.subscribe(value => {
|
||||
this.authService.isLoggedIn$.pipe(
|
||||
takeUntil(this.unsubscriber)
|
||||
).subscribe(value => {
|
||||
this.isLoggedIn = value;
|
||||
});
|
||||
}
|
||||
@@ -49,6 +53,11 @@ export class AppComponent implements OnInit {
|
||||
this.socket.startSocket();
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.unsubscriber.next();
|
||||
this.unsubscriber.unsubscribe();
|
||||
}
|
||||
|
||||
loadLang(): void {
|
||||
let lang = localStorage.getItem(`default_lang`);
|
||||
if (!lang) {
|
||||
|
Reference in New Issue
Block a user