diff options
author | Chocobozzz <me@florianbigard.com> | 2021-01-13 11:29:55 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-01-13 11:29:55 +0100 |
commit | 6d0110ad7ba46fc115f24a7cc15a71c5ad186ed1 (patch) | |
tree | 60d359816bbc785acdb3a31b4d1ea93be0001ca5 /client/src | |
parent | 0e4ca570fa33105456f0e4650342374c1658d5f4 (diff) | |
download | PeerTube-6d0110ad7ba46fc115f24a7cc15a71c5ad186ed1.tar.gz PeerTube-6d0110ad7ba46fc115f24a7cc15a71c5ad186ed1.tar.zst PeerTube-6d0110ad7ba46fc115f24a7cc15a71c5ad186ed1.zip |
Fix loading bar for HTTP requests
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/app/app.component.ts | 17 | ||||
-rw-r--r-- | client/src/app/core/core.module.ts | 11 | ||||
-rw-r--r-- | client/src/app/shared/shared-main/shared-main.module.ts | 8 |
3 files changed, 25 insertions, 11 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 () { |
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index f51f1920d..c4fc9995e 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts | |||
@@ -8,11 +8,7 @@ import { PeerTubeSocket } from '@app/core/notification/peertube-socket.service' | |||
8 | import { HooksService } from '@app/core/plugins/hooks.service' | 8 | import { HooksService } from '@app/core/plugins/hooks.service' |
9 | import { PluginService } from '@app/core/plugins/plugin.service' | 9 | import { PluginService } from '@app/core/plugins/plugin.service' |
10 | import { UnloggedGuard } from '@app/core/routing/unlogged-guard.service' | 10 | import { UnloggedGuard } from '@app/core/routing/unlogged-guard.service' |
11 | import { LoadingBarModule } from '@ngx-loading-bar/core' | ||
12 | import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' | ||
13 | import { LoadingBarRouterModule } from '@ngx-loading-bar/router' | ||
14 | import { AuthService } from './auth' | 11 | import { AuthService } from './auth' |
15 | import { ScopedTokensService } from './scoped-tokens' | ||
16 | import { ConfirmService } from './confirm' | 12 | import { ConfirmService } from './confirm' |
17 | import { CheatSheetComponent } from './hotkeys' | 13 | import { CheatSheetComponent } from './hotkeys' |
18 | import { MenuService } from './menu' | 14 | import { MenuService } from './menu' |
@@ -23,6 +19,7 @@ import { RestExtractor, RestService } from './rest' | |||
23 | import { LoginGuard, RedirectService, UserRightGuard } from './routing' | 19 | import { LoginGuard, RedirectService, UserRightGuard } from './routing' |
24 | import { CanDeactivateGuard } from './routing/can-deactivate-guard.service' | 20 | import { CanDeactivateGuard } from './routing/can-deactivate-guard.service' |
25 | import { ServerConfigResolver } from './routing/server-config-resolver.service' | 21 | import { ServerConfigResolver } from './routing/server-config-resolver.service' |
22 | import { ScopedTokensService } from './scoped-tokens' | ||
26 | import { ServerService } from './server' | 23 | import { ServerService } from './server' |
27 | import { ThemeService } from './theme' | 24 | import { ThemeService } from './theme' |
28 | import { UserService } from './users' | 25 | import { UserService } from './users' |
@@ -33,9 +30,6 @@ import { LocalStorageService, ScreenService, SessionStorageService } from './wra | |||
33 | CommonModule, | 30 | CommonModule, |
34 | BrowserAnimationsModule, | 31 | BrowserAnimationsModule, |
35 | 32 | ||
36 | LoadingBarHttpClientModule, | ||
37 | LoadingBarRouterModule, | ||
38 | LoadingBarModule, | ||
39 | ToastModule, | 33 | ToastModule, |
40 | 34 | ||
41 | HotkeyModule.forRoot({ | 35 | HotkeyModule.forRoot({ |
@@ -48,9 +42,6 @@ import { LocalStorageService, ScreenService, SessionStorageService } from './wra | |||
48 | ], | 42 | ], |
49 | 43 | ||
50 | exports: [ | 44 | exports: [ |
51 | LoadingBarHttpClientModule, | ||
52 | LoadingBarModule, | ||
53 | |||
54 | ToastModule, | 45 | ToastModule, |
55 | 46 | ||
56 | CheatSheetComponent | 47 | CheatSheetComponent |
diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts index 74bb4559a..123b5a3e3 100644 --- a/client/src/app/shared/shared-main/shared-main.module.ts +++ b/client/src/app/shared/shared-main/shared-main.module.ts | |||
@@ -13,6 +13,8 @@ import { | |||
13 | NgbPopoverModule, | 13 | NgbPopoverModule, |
14 | NgbTooltipModule | 14 | NgbTooltipModule |
15 | } from '@ng-bootstrap/ng-bootstrap' | 15 | } from '@ng-bootstrap/ng-bootstrap' |
16 | import { LoadingBarModule } from '@ngx-loading-bar/core' | ||
17 | import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' | ||
16 | import { SharedGlobalIconModule } from '../shared-icons' | 18 | import { SharedGlobalIconModule } from '../shared-icons' |
17 | import { AccountService, ActorAvatarInfoComponent, VideoAvatarChannelComponent } from './account' | 19 | import { AccountService, ActorAvatarInfoComponent, VideoAvatarChannelComponent } from './account' |
18 | import { | 20 | import { |
@@ -42,6 +44,9 @@ import { VideoChannelService } from './video-channel' | |||
42 | RouterModule, | 44 | RouterModule, |
43 | HttpClientModule, | 45 | HttpClientModule, |
44 | 46 | ||
47 | LoadingBarHttpClientModule, | ||
48 | LoadingBarModule, | ||
49 | |||
45 | NgbDropdownModule, | 50 | NgbDropdownModule, |
46 | NgbModalModule, | 51 | NgbModalModule, |
47 | NgbPopoverModule, | 52 | NgbPopoverModule, |
@@ -95,6 +100,9 @@ import { VideoChannelService } from './video-channel' | |||
95 | RouterModule, | 100 | RouterModule, |
96 | HttpClientModule, | 101 | HttpClientModule, |
97 | 102 | ||
103 | LoadingBarHttpClientModule, | ||
104 | LoadingBarModule, | ||
105 | |||
98 | NgbDropdownModule, | 106 | NgbDropdownModule, |
99 | NgbModalModule, | 107 | NgbModalModule, |
100 | NgbPopoverModule, | 108 | NgbPopoverModule, |