we_bstly-web/src/app/app.component.ts

70 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-11-02 08:29:52 +01:00
import { Component, HostListener } from '@angular/core';
import { AuthService } from './services/auth.service';
import { I18nService } from './services/i18n.service';
import { Router } from '@angular/router';
import { DomSanitizer } from '@angular/platform-browser';
import { MatIconRegistry } from '@angular/material/icon';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
opened = true;
title = 'we.bstly';
currentLocale: String;
2021-01-12 19:29:00 +01:00
locales;
2020-11-02 08:29:52 +01:00
auth;
constructor(private i18n: I18nService, private authService: AuthService, private router: Router, private iconRegistry: MatIconRegistry, private sanitizer: DomSanitizer) {
this.currentLocale = this.i18n.getLocale();
2021-01-12 19:29:00 +01:00
this.locales = this.i18n.getLocales();
2020-11-02 08:29:52 +01:00
this.authService.auth.subscribe(data => {
this.auth = data;
})
iconRegistry.addSvgIcon('logo', sanitizer.bypassSecurityTrustResourceUrl('assets/icons/logo.svg'));
}
ngOnInit() {
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
if (width < 768) {
this.opened = false;
} else {
this.opened = true;
}
}
setLocale(locale) {
localStorage.setItem("bstly.locale", locale);
window.location.reload();
}
logout() {
this.authService.logout().subscribe(data => {
this.router.navigate([""]);
})
}
isBiggerScreen() {
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
if (width < 768) {
return false;
} else {
return true;
}
}
@HostListener('window:resize', ['$event'])
onResize(event) {
if (event.target.innerWidth < 768) {
this.opened = false;
} else {
this.opened = true;
}
}
}