]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-video-settings / my-account-video-settings.component.ts
index acc70c14d7f833c02d2ba32d96cece1cbe77ec9a..b8f80bc1a344527ae0ab56c807a54a13e01158e0 100644 (file)
@@ -1,9 +1,11 @@
 import { Component, Input, OnInit } from '@angular/core'
-import { FormBuilder, FormGroup } from '@angular/forms'
-import { NotificationsService } from 'angular2-notifications'
+import { Notifier } from '@app/core'
 import { UserUpdateMe } from '../../../../../../shared'
 import { AuthService } from '../../../core'
 import { FormReactive, User, UserService } from '../../../shared'
+import { I18n } from '@ngx-translate/i18n-polyfill'
+import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
+import { Subject } from 'rxjs'
 
 @Component({
   selector: 'my-account-video-settings',
@@ -12,49 +14,52 @@ import { FormReactive, User, UserService } from '../../../shared'
 })
 export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit {
   @Input() user: User = null
-
-  form: FormGroup
-  formErrors = {}
-  validationMessages = {}
+  @Input() userInformationLoaded: Subject<any>
 
   constructor (
+    protected formValidatorService: FormValidatorService,
     private authService: AuthService,
-    private formBuilder: FormBuilder,
-    private notificationsService: NotificationsService,
-    private userService: UserService
+    private notifier: Notifier,
+    private userService: UserService,
+    private i18n: I18n
   ) {
     super()
   }
 
-  buildForm () {
-    this.form = this.formBuilder.group({
-      nsfwPolicy: [ this.user.nsfwPolicy ],
-      autoPlayVideo: [ this.user.autoPlayVideo ]
+  ngOnInit () {
+    this.buildForm({
+      nsfwPolicy: null,
+      webTorrentEnabled: null,
+      autoPlayVideo: null
     })
 
-    this.form.valueChanges.subscribe(data => this.onValueChanged(data))
-  }
-
-  ngOnInit () {
-    this.buildForm()
+    this.userInformationLoaded.subscribe(() => {
+      this.form.patchValue({
+        nsfwPolicy: this.user.nsfwPolicy,
+        webTorrentEnabled: this.user.webTorrentEnabled,
+        autoPlayVideo: this.user.autoPlayVideo === true
+      })
+    })
   }
 
   updateDetails () {
     const nsfwPolicy = this.form.value['nsfwPolicy']
+    const webTorrentEnabled = this.form.value['webTorrentEnabled']
     const autoPlayVideo = this.form.value['autoPlayVideo']
     const details: UserUpdateMe = {
       nsfwPolicy,
+      webTorrentEnabled,
       autoPlayVideo
     }
 
     this.userService.updateMyProfile(details).subscribe(
       () => {
-        this.notificationsService.success('Success', 'Information updated.')
+        this.notifier.success(this.i18n('Information updated.'))
 
         this.authService.refreshUserInformation()
       },
 
-      err => this.notificationsService.error('Error', err.message)
+      err => this.notifier.error(err.message)
     )
   }
 }