d2678096f7887b6bed4e0c621095f39ba4f4354c
[oweals/peertube.git] / client / src / app / app.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { NavigationEnd, Router } from '@angular/router'
3 import { AuthService, ServerService } from '@app/core'
4 import { isInMobileView } from '@app/shared/misc/utils'
5
6 @Component({
7   selector: 'my-app',
8   templateUrl: './app.component.html',
9   styleUrls: [ './app.component.scss' ]
10 })
11 export class AppComponent implements OnInit {
12   notificationOptions = {
13     timeOut: 5000,
14     lastOnBottom: true,
15     clickToClose: true,
16     maxLength: 0,
17     maxStack: 7,
18     showProgressBar: false,
19     pauseOnHover: false,
20     preventDuplicates: false,
21     preventLastDuplicates: 'visible',
22     rtl: false
23   }
24
25   isMenuDisplayed = true
26
27   constructor (
28     private router: Router,
29     private authService: AuthService,
30     private serverService: ServerService
31   ) {}
32
33   get serverVersion () {
34     return this.serverService.getConfig().serverVersion
35   }
36
37   ngOnInit () {
38     this.authService.loadClientCredentials()
39
40     if (this.authService.isLoggedIn()) {
41       // The service will automatically redirect to the login page if the token is not valid anymore
42       this.authService.refreshUserInformation()
43     }
44
45     // Load custom data from server
46     this.serverService.loadConfig()
47     this.serverService.loadVideoCategories()
48     this.serverService.loadVideoLanguages()
49     this.serverService.loadVideoLicences()
50     this.serverService.loadVideoPrivacies()
51
52     // Do not display menu on small screens
53     if (isInMobileView()) {
54       this.isMenuDisplayed = false
55     }
56
57     this.router.events.subscribe(
58       e => {
59         // User clicked on a link in the menu, change the page
60         if (e instanceof NavigationEnd && isInMobileView()) {
61           this.isMenuDisplayed = false
62         }
63       }
64     )
65   }
66
67   toggleMenu () {
68     window.scrollTo(0, 0)
69     this.isMenuDisplayed = !this.isMenuDisplayed
70   }
71
72   getMainColClasses () {
73     // Take all width is the menu is not displayed
74     if (this.isMenuDisplayed === false) return [ 'expanded' ]
75
76     return []
77   }
78 }