diff options
Diffstat (limited to 'client/src/app/app.component.ts')
-rw-r--r-- | client/src/app/app.component.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 3d1026ac4..ca4b69899 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts | |||
@@ -4,7 +4,7 @@ import { filter, first, map, pairwise } from 'rxjs/operators' | |||
4 | import { DOCUMENT, PlatformLocation, ViewportScroller } from '@angular/common' | 4 | import { DOCUMENT, PlatformLocation, ViewportScroller } from '@angular/common' |
5 | import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core' | 5 | import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core' |
6 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' | 6 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' |
7 | import { Event, GuardsCheckStart, NavigationEnd, Router, Scroll } from '@angular/router' | 7 | import { Event, GuardsCheckStart, NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart, Router, Scroll } from '@angular/router' |
8 | import { AuthService, MarkdownService, RedirectService, ScreenService, ServerService, ThemeService, User } from '@app/core' | 8 | import { AuthService, MarkdownService, RedirectService, ScreenService, ServerService, ThemeService, User } from '@app/core' |
9 | import { HooksService } from '@app/core/plugins/hooks.service' | 9 | import { HooksService } from '@app/core/plugins/hooks.service' |
10 | import { PluginService } from '@app/core/plugins/plugin.service' | 10 | import { PluginService } from '@app/core/plugins/plugin.service' |
@@ -12,6 +12,7 @@ import { CustomModalComponent } from '@app/modal/custom-modal.component' | |||
12 | import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' | 12 | import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' |
13 | import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' | 13 | import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' |
14 | import { NgbConfig, NgbModal } from '@ng-bootstrap/ng-bootstrap' | 14 | import { NgbConfig, NgbModal } from '@ng-bootstrap/ng-bootstrap' |
15 | import { LoadingBarService } from '@ngx-loading-bar/core' | ||
15 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | 16 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
16 | import { getShortLocale, is18nPath } from '@shared/core-utils/i18n' | 17 | import { getShortLocale, is18nPath } from '@shared/core-utils/i18n' |
17 | import { BroadcastMessageLevel, ServerConfig, UserRole } from '@shared/models' | 18 | import { BroadcastMessageLevel, ServerConfig, UserRole } from '@shared/models' |
@@ -55,6 +56,7 @@ export class AppComponent implements OnInit, AfterViewInit { | |||
55 | private modalService: NgbModal, | 56 | private modalService: NgbModal, |
56 | private markdownService: MarkdownService, | 57 | private markdownService: MarkdownService, |
57 | private ngbConfig: NgbConfig, | 58 | private ngbConfig: NgbConfig, |
59 | private loadingBar: LoadingBarService, | ||
58 | public menu: MenuService | 60 | public menu: MenuService |
59 | ) { | 61 | ) { |
60 | this.ngbConfig.animation = false | 62 | this.ngbConfig.animation = false |
@@ -126,6 +128,7 @@ export class AppComponent implements OnInit, AfterViewInit { | |||
126 | 128 | ||
127 | const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll)) | 129 | const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll)) |
128 | 130 | ||
131 | // Handle anchors/restore position | ||
129 | scrollEvent.subscribe(e => { | 132 | scrollEvent.subscribe(e => { |
130 | // scrollToAnchor first to preserve anchor position when using history navigation | 133 | // scrollToAnchor first to preserve anchor position when using history navigation |
131 | if (e.anchor) { | 134 | if (e.anchor) { |
@@ -178,19 +181,31 @@ export class AppComponent implements OnInit, AfterViewInit { | |||
178 | } | 181 | } |
179 | }) | 182 | }) |
180 | 183 | ||
184 | // Homepage redirection | ||
181 | navigationEndEvent.pipe( | 185 | navigationEndEvent.pipe( |
182 | map(() => window.location.pathname), | 186 | map(() => window.location.pathname), |
183 | filter(pathname => !pathname || pathname === '/' || is18nPath(pathname)) | 187 | filter(pathname => !pathname || pathname === '/' || is18nPath(pathname)) |
184 | ).subscribe(() => this.redirectService.redirectToHomepage(true)) | 188 | ).subscribe(() => this.redirectService.redirectToHomepage(true)) |
185 | 189 | ||
190 | // Plugin hooks | ||
186 | navigationEndEvent.subscribe(e => { | 191 | navigationEndEvent.subscribe(e => { |
187 | this.hooks.runAction('action:router.navigation-end', 'common', { path: e.url }) | 192 | this.hooks.runAction('action:router.navigation-end', 'common', { path: e.url }) |
188 | }) | 193 | }) |
189 | 194 | ||
195 | // Automatically hide/display the menu | ||
190 | eventsObs.pipe( | 196 | eventsObs.pipe( |
191 | filter((e: Event): e is GuardsCheckStart => e instanceof GuardsCheckStart), | 197 | filter((e: Event): e is GuardsCheckStart => e instanceof GuardsCheckStart), |
192 | filter(() => this.screenService.isInSmallView() || this.screenService.isInTouchScreen()) | 198 | filter(() => this.screenService.isInSmallView() || this.screenService.isInTouchScreen()) |
193 | ).subscribe(() => this.menu.setMenuDisplay(false)) // User clicked on a link in the menu, change the page | 199 | ).subscribe(() => this.menu.setMenuDisplay(false)) // User clicked on a link in the menu, change the page |
200 | |||
201 | // Handle lazy loaded module | ||
202 | eventsObs.pipe( | ||
203 | filter((e: Event): e is RouteConfigLoadStart => e instanceof RouteConfigLoadStart) | ||
204 | ).subscribe(() => this.loadingBar.useRef().start()) | ||
205 | |||
206 | eventsObs.pipe( | ||
207 | filter((e: Event): e is RouteConfigLoadEnd => e instanceof RouteConfigLoadEnd) | ||
208 | ).subscribe(() => this.loadingBar.useRef().complete()) | ||
194 | } | 209 | } |
195 | 210 | ||
196 | private injectBroadcastMessage () { | 211 | private injectBroadcastMessage () { |