]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-user-settings/user-interface-settings.component.ts
Add transcoding fail message in client
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-user-settings / user-interface-settings.component.ts
1 import { Subject, Subscription } from 'rxjs'
2 import { Component, Input, OnDestroy, OnInit } from '@angular/core'
3 import { AuthService, Notifier, ServerService, UserService } from '@app/core'
4 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5 import { HTMLServerConfig, User, UserUpdateMe } from '@shared/models'
6
7 @Component({
8 selector: 'my-user-interface-settings',
9 templateUrl: './user-interface-settings.component.html',
10 styleUrls: [ './user-interface-settings.component.scss' ]
11 })
12 export class UserInterfaceSettingsComponent extends FormReactive implements OnInit, OnDestroy {
13 @Input() user: User = null
14 @Input() reactiveUpdate = false
15 @Input() notifyOnUpdate = true
16 @Input() userInformationLoaded: Subject<any>
17
18 formValuesWatcher: Subscription
19
20 private serverConfig: HTMLServerConfig
21
22 constructor (
23 protected formValidatorService: FormValidatorService,
24 private authService: AuthService,
25 private notifier: Notifier,
26 private userService: UserService,
27 private serverService: ServerService
28 ) {
29 super()
30 }
31
32 get availableThemes () {
33 return this.serverConfig.theme.registered
34 .map(t => t.name)
35 }
36
37 ngOnInit () {
38 this.serverConfig = this.serverService.getHTMLConfig()
39
40 this.buildForm({
41 theme: null
42 })
43
44 this.userInformationLoaded
45 .subscribe(() => {
46 this.form.patchValue({
47 theme: this.user.theme
48 })
49
50 if (this.reactiveUpdate) {
51 this.formValuesWatcher = this.form.valueChanges.subscribe(val => this.updateInterfaceSettings())
52 }
53 })
54 }
55
56 ngOnDestroy () {
57 this.formValuesWatcher?.unsubscribe()
58 }
59
60 updateInterfaceSettings () {
61 const theme = this.form.value['theme']
62
63 const details: UserUpdateMe = {
64 theme
65 }
66
67 if (this.authService.isLoggedIn()) {
68 this.userService.updateMyProfile(details)
69 .subscribe({
70 next: () => {
71 this.authService.refreshUserInformation()
72
73 if (this.notifyOnUpdate) this.notifier.success($localize`Interface settings updated.`)
74 },
75
76 error: err => this.notifier.error(err.message)
77 })
78
79 return
80 }
81
82 this.userService.updateMyAnonymousProfile(details)
83 if (this.notifyOnUpdate) this.notifier.success($localize`Interface settings updated.`)
84 }
85 }