]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-user-settings/user-interface-settings.component.ts
Fix comment add avatar when unlogged
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-user-settings / user-interface-settings.component.ts
index b721604e5ed3a601f78b7509eb2fb63caacec625..24ad54b1d0942841a6929c8af478fe20c2aa1512 100644 (file)
@@ -1,6 +1,6 @@
 import { Subject, Subscription } from 'rxjs'
 import { Component, Input, OnDestroy, OnInit } from '@angular/core'
-import { AuthService, Notifier, ServerService, UserService } from '@app/core'
+import { AuthService, Notifier, ServerService, ThemeService, UserService } from '@app/core'
 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
 import { HTMLServerConfig, User, UserUpdateMe } from '@shared/models'
 
@@ -24,14 +24,14 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
     private authService: AuthService,
     private notifier: Notifier,
     private userService: UserService,
+    private themeService: ThemeService,
     private serverService: ServerService
   ) {
     super()
   }
 
-  get availableThemes () {
-    return this.serverConfig.theme.registered
-               .map(t => t.name)
+  get instanceName () {
+    return this.serverConfig.instance.name
   }
 
   ngOnInit () {
@@ -48,7 +48,7 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
         })
 
         if (this.reactiveUpdate) {
-          this.formValuesWatcher = this.form.valueChanges.subscribe(val => this.updateInterfaceSettings())
+          this.formValuesWatcher = this.form.valueChanges.subscribe(() => this.updateInterfaceSettings())
         }
       })
   }
@@ -57,6 +57,24 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
     this.formValuesWatcher?.unsubscribe()
   }
 
+  getDefaultThemeLabel () {
+    return this.themeService.getDefaultThemeLabel()
+  }
+
+  getAvailableThemes () {
+    return this.themeService.getAvailableThemeLabels()
+  }
+
+  getDefaultInstanceThemeLabel () {
+    const theme = this.serverConfig.theme.default
+
+    if (theme === 'default') {
+      return this.getDefaultThemeLabel()
+    }
+
+    return theme
+  }
+
   updateInterfaceSettings () {
     const theme = this.form.value['theme']
 
@@ -65,18 +83,21 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
     }
 
     if (this.authService.isLoggedIn()) {
-      this.userService.updateMyProfile(details).subscribe(
-        () => {
-          this.authService.refreshUserInformation()
-
-          if (this.notifyOnUpdate) this.notifier.success($localize`Interface settings updated.`)
-        },
-
-        err => this.notifier.error(err.message)
-      )
-    } else {
-      this.userService.updateMyAnonymousProfile(details)
-      if (this.notifyOnUpdate) this.notifier.success($localize`Interface settings updated.`)
+      this.userService.updateMyProfile(details)
+        .subscribe({
+          next: () => {
+            this.authService.refreshUserInformation()
+
+            if (this.notifyOnUpdate) this.notifier.success($localize`Interface settings updated.`)
+          },
+
+          error: err => this.notifier.error(err.message)
+        })
+
+      return
     }
+
+    this.userService.updateMyAnonymousProfile(details)
+    if (this.notifyOnUpdate) this.notifier.success($localize`Interface settings updated.`)
   }
 }