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',
})
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)
)
}
}