]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/app.component.ts
Use badges for instance languages/categories
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
index 915466af73a38c331a1de34f2b7cbbbbee011572..64bfb9671bf9a9b20f521bb4c2dae8bbb31d9414 100644 (file)
@@ -8,7 +8,11 @@ import { debounceTime, filter, map, pairwise, skip } from 'rxjs/operators'
 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { fromEvent } from 'rxjs'
-import { ViewportScroller } from '@angular/common'
+import { PlatformLocation, ViewportScroller } from '@angular/common'
+import { PluginService } from '@app/core/plugins/plugin.service'
+import { HooksService } from '@app/core/plugins/hooks.service'
+import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
+import { POP_STATE_MODAL_DISMISS } from '@app/shared/misc/constants'
 
 @Component({
   selector: 'my-app',
@@ -27,11 +31,15 @@ export class AppComponent implements OnInit {
     private router: Router,
     private authService: AuthService,
     private serverService: ServerService,
+    private pluginService: PluginService,
     private domSanitizer: DomSanitizer,
     private redirectService: RedirectService,
     private screenService: ScreenService,
     private hotkeysService: HotkeysService,
-    private themeService: ThemeService
+    private themeService: ThemeService,
+    private hooks: HooksService,
+    private location: PlatformLocation,
+    private modalService: NgbModal
   ) { }
 
   get serverVersion () {
@@ -69,6 +77,9 @@ export class AppComponent implements OnInit {
     this.serverService.loadVideoPrivacies()
     this.serverService.loadVideoPlaylistPrivacies()
 
+    this.loadPlugins()
+    this.themeService.initialize()
+
     // Do not display menu on small screens
     if (this.screenService.isInSmallView()) {
       this.isMenuDisplayed = false
@@ -83,6 +94,8 @@ export class AppComponent implements OnInit {
     fromEvent(window, 'resize')
       .pipe(debounceTime(200))
       .subscribe(() => this.onResize())
+
+    this.location.onPopState(() => this.modalService.dismissAll(POP_STATE_MODAL_DISMISS))
   }
 
   isUserLoggedIn () {
@@ -103,7 +116,6 @@ export class AppComponent implements OnInit {
     const eventsObs = this.router.events
 
     const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll))
-    const navigationEndEvent = eventsObs.pipe(filter((e: Event): e is NavigationEnd => e instanceof NavigationEnd))
 
     scrollEvent.subscribe(e => {
       if (e.position) {
@@ -119,6 +131,8 @@ export class AppComponent implements OnInit {
       }
     })
 
+    const navigationEndEvent = eventsObs.pipe(filter((e: Event): e is NavigationEnd => e instanceof NavigationEnd))
+
     // When we add the a-state parameter, we don't want to alter the scroll
     navigationEndEvent.pipe(pairwise())
                       .subscribe(([ e1, e2 ]) => {
@@ -155,6 +169,10 @@ export class AppComponent implements OnInit {
       filter(pathname => !pathname || pathname === '/' || is18nPath(pathname))
     ).subscribe(() => this.redirectService.redirectToHomepage(true))
 
+    navigationEndEvent.subscribe(e => {
+      this.hooks.runAction('action:router.navigation-end', 'common', { path: e.url })
+    })
+
     eventsObs.pipe(
       filter((e: Event): e is GuardsCheckStart => e instanceof GuardsCheckStart),
       filter(() => this.screenService.isInSmallView())
@@ -196,6 +214,12 @@ export class AppComponent implements OnInit {
         })
   }
 
+  private async loadPlugins () {
+    this.pluginService.initializePlugins()
+
+    this.hooks.runAction('action:application.init', 'common')
+  }
+
   private initHotkeys () {
     this.hotkeysService.add([
       new Hotkey(['/', 's'], (event: KeyboardEvent): boolean => {
@@ -209,7 +233,7 @@ export class AppComponent implements OnInit {
       new Hotkey('g o', (event: KeyboardEvent): boolean => {
         this.router.navigate([ '/videos/overview' ])
         return false
-      }, undefined, this.i18n('Go to the videos overview page')),
+      }, undefined, this.i18n('Go to the discover videos page')),
       new Hotkey('g t', (event: KeyboardEvent): boolean => {
         this.router.navigate([ '/videos/trending' ])
         return false
@@ -225,11 +249,7 @@ export class AppComponent implements OnInit {
       new Hotkey('g u', (event: KeyboardEvent): boolean => {
         this.router.navigate([ '/videos/upload' ])
         return false
-      }, undefined, this.i18n('Go to the videos upload page')),
-      new Hotkey('shift+t', (event: KeyboardEvent): boolean => {
-        this.themeService.toggleDarkTheme()
-        return false
-      }, undefined, this.i18n('Toggle Dark theme'))
+      }, undefined, this.i18n('Go to the videos upload page'))
     ])
   }
 }