]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-user-settings/user-interface-settings.component.ts
Support ICU in TS components
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-user-settings / user-interface-settings.component.ts
index b721604e5ed3a601f78b7509eb2fb63caacec625..932db498aa0437e11b098f328caf9e12c431099c 100644 (file)
@@ -2,6 +2,7 @@ import { Subject, Subscription } from 'rxjs'
 import { Component, Input, OnDestroy, OnInit } from '@angular/core'
 import { AuthService, Notifier, ServerService, UserService } from '@app/core'
 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
+import { capitalizeFirstLetter } from '@root-helpers/string'
 import { HTMLServerConfig, User, UserUpdateMe } from '@shared/models'
 
 @Component({
@@ -17,6 +18,8 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
 
   formValuesWatcher: Subscription
 
+  defaultThemeLabel = $localize`Light/Orange`
+
   private serverConfig: HTMLServerConfig
 
   constructor (
@@ -48,7 +51,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 +60,18 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
     this.formValuesWatcher?.unsubscribe()
   }
 
+  getDefaultThemeLabel () {
+    const theme = this.serverConfig.theme.default
+
+    if (theme === 'default') return this.defaultThemeLabel
+
+    return theme
+  }
+
+  capitalizeFirstLetter (str: string) {
+    return capitalizeFirstLetter(str)
+  }
+
   updateInterfaceSettings () {
     const theme = this.form.value['theme']
 
@@ -65,18 +80,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.`)
   }
 }