aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/app.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-12-18 15:31:54 +0100
committerChocobozzz <me@florianbigard.com>2019-12-18 15:40:59 +0100
commitba430d7516bc5b1324b60571ba7594460969b7fb (patch)
treedf5c6952c82f49a94c0a884bbc97d4a0cbd9f867 /client/src/app/app.component.ts
parent5dfb7c1dec8222b0bbccac5b56ad46da1438747e (diff)
downloadPeerTube-ba430d7516bc5b1324b60571ba7594460969b7fb.tar.gz
PeerTube-ba430d7516bc5b1324b60571ba7594460969b7fb.tar.zst
PeerTube-ba430d7516bc5b1324b60571ba7594460969b7fb.zip
Lazy load static objects
Diffstat (limited to 'client/src/app/app.component.ts')
-rw-r--r--client/src/app/app.component.ts46
1 files changed, 18 insertions, 28 deletions
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts
index 351620c59..883f36514 100644
--- a/client/src/app/app.component.ts
+++ b/client/src/app/app.component.ts
@@ -15,7 +15,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
15import { POP_STATE_MODAL_DISMISS } from '@app/shared/misc/constants' 15import { POP_STATE_MODAL_DISMISS } from '@app/shared/misc/constants'
16import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' 16import { WelcomeModalComponent } from '@app/modal/welcome-modal.component'
17import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' 17import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component'
18import { UserRole } from '@shared/models' 18import { ServerConfig, UserRole } from '@shared/models'
19import { User } from '@app/shared' 19import { User } from '@app/shared'
20import { InstanceService } from '@app/shared/instance/instance.service' 20import { InstanceService } from '@app/shared/instance/instance.service'
21 21
@@ -33,6 +33,8 @@ export class AppComponent implements OnInit {
33 33
34 customCSS: SafeHtml 34 customCSS: SafeHtml
35 35
36 private serverConfig: ServerConfig
37
36 constructor ( 38 constructor (
37 private i18n: I18n, 39 private i18n: I18n,
38 private viewportScroller: ViewportScroller, 40 private viewportScroller: ViewportScroller,
@@ -52,7 +54,7 @@ export class AppComponent implements OnInit {
52 ) { } 54 ) { }
53 55
54 get instanceName () { 56 get instanceName () {
55 return this.serverService.getConfig().instance.name 57 return this.serverConfig.instance.name
56 } 58 }
57 59
58 get defaultRoute () { 60 get defaultRoute () {
@@ -62,6 +64,10 @@ export class AppComponent implements OnInit {
62 ngOnInit () { 64 ngOnInit () {
63 document.getElementById('incompatible-browser').className += ' browser-ok' 65 document.getElementById('incompatible-browser').className += ' browser-ok'
64 66
67 this.serverConfig = this.serverService.getTmpConfig()
68 this.serverService.getConfig()
69 .subscribe(config => this.serverConfig = config)
70
65 this.loadPlugins() 71 this.loadPlugins()
66 this.themeService.initialize() 72 this.themeService.initialize()
67 73
@@ -72,14 +78,6 @@ export class AppComponent implements OnInit {
72 this.authService.refreshUserInformation() 78 this.authService.refreshUserInformation()
73 } 79 }
74 80
75 // Load custom data from server
76 this.serverService.loadConfig()
77 this.serverService.loadVideoCategories()
78 this.serverService.loadVideoLanguages()
79 this.serverService.loadVideoLicences()
80 this.serverService.loadVideoPrivacies()
81 this.serverService.loadVideoPlaylistPrivacies()
82
83 // Do not display menu on small screens 81 // Do not display menu on small screens
84 if (this.screenService.isInSmallView()) { 82 if (this.screenService.isInSmallView()) {
85 this.isMenuDisplayed = false 83 this.isMenuDisplayed = false
@@ -187,10 +185,8 @@ export class AppComponent implements OnInit {
187 185
188 private injectJS () { 186 private injectJS () {
189 // Inject JS 187 // Inject JS
190 this.serverService.configLoaded 188 this.serverService.getConfig()
191 .subscribe(() => { 189 .subscribe(config => {
192 const config = this.serverService.getConfig()
193
194 if (config.instance.customizations.javascript) { 190 if (config.instance.customizations.javascript) {
195 try { 191 try {
196 // tslint:disable:no-eval 192 // tslint:disable:no-eval
@@ -204,17 +200,14 @@ export class AppComponent implements OnInit {
204 200
205 private injectCSS () { 201 private injectCSS () {
206 // Inject CSS if modified (admin config settings) 202 // Inject CSS if modified (admin config settings)
207 this.serverService.configLoaded 203 this.serverService.configReloaded
208 .pipe(skip(1)) // We only want to subscribe to reloads, because the CSS is already injected by the server
209 .subscribe(() => { 204 .subscribe(() => {
210 const headStyle = document.querySelector('style.custom-css-style') 205 const headStyle = document.querySelector('style.custom-css-style')
211 if (headStyle) headStyle.parentNode.removeChild(headStyle) 206 if (headStyle) headStyle.parentNode.removeChild(headStyle)
212 207
213 const config = this.serverService.getConfig()
214
215 // We test customCSS if the admin removed the css 208 // We test customCSS if the admin removed the css
216 if (this.customCSS || config.instance.customizations.css) { 209 if (this.customCSS || this.serverConfig.instance.customizations.css) {
217 const styleTag = '<style>' + config.instance.customizations.css + '</style>' 210 const styleTag = '<style>' + this.serverConfig.instance.customizations.css + '</style>'
218 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag) 211 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
219 } 212 }
220 }) 213 })
@@ -227,25 +220,22 @@ export class AppComponent implements OnInit {
227 } 220 }
228 221
229 private async openModalsIfNeeded () { 222 private async openModalsIfNeeded () {
230 this.serverService.configLoaded 223 this.authService.userInformationLoaded
231 .pipe( 224 .pipe(
232 first(),
233 switchMap(() => this.authService.userInformationLoaded),
234 map(() => this.authService.getUser()), 225 map(() => this.authService.getUser()),
235 filter(user => user.role === UserRole.ADMINISTRATOR) 226 filter(user => user.role === UserRole.ADMINISTRATOR)
236 ).subscribe(user => setTimeout(() => this.openAdminModals(user))) // setTimeout because of ngIf in template 227 ).subscribe(user => setTimeout(() => this._openAdminModalsIfNeeded(user))) // setTimeout because of ngIf in template
237 } 228 }
238 229
239 private async openAdminModals (user: User) { 230 private async _openAdminModalsIfNeeded (user: User) {
240 if (user.noWelcomeModal !== true) return this.welcomeModal.show() 231 if (user.noWelcomeModal !== true) return this.welcomeModal.show()
241 232
242 const config = this.serverService.getConfig() 233 if (user.noInstanceConfigWarningModal === true || !this.serverConfig.signup.allowed) return
243 if (user.noInstanceConfigWarningModal === true || !config.signup.allowed) return
244 234
245 this.instanceService.getAbout() 235 this.instanceService.getAbout()
246 .subscribe(about => { 236 .subscribe(about => {
247 if ( 237 if (
248 config.instance.name.toLowerCase() === 'peertube' || 238 this.serverConfig.instance.name.toLowerCase() === 'peertube' ||
249 !about.instance.terms || 239 !about.instance.terms ||
250 !about.instance.administrator || 240 !about.instance.administrator ||
251 !about.instance.maintenanceLifetime 241 !about.instance.maintenanceLifetime