]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
Fix autoplay setting in my account
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-video-settings / my-account-video-settings.component.ts
1 import { Component, Input, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { UserUpdateMe } from '../../../../../../shared'
4 import { AuthService } from '../../../core'
5 import { FormReactive, User, UserService } from '../../../shared'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
8 import { Subject } from 'rxjs/Subject'
9
10 @Component({
11 selector: 'my-account-video-settings',
12 templateUrl: './my-account-video-settings.component.html',
13 styleUrls: [ './my-account-video-settings.component.scss' ]
14 })
15 export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit {
16 @Input() user: User = null
17 @Input() userInformationLoaded: Subject<any>
18
19 constructor (
20 protected formValidatorService: FormValidatorService,
21 private authService: AuthService,
22 private notificationsService: NotificationsService,
23 private userService: UserService,
24 private i18n: I18n
25 ) {
26 super()
27 }
28
29 ngOnInit () {
30 this.buildForm({
31 nsfwPolicy: null,
32 autoPlayVideo: null
33 })
34
35 this.userInformationLoaded.subscribe(() => {
36 this.form.patchValue({
37 nsfwPolicy: this.user.nsfwPolicy,
38 autoPlayVideo: this.user.autoPlayVideo === true
39 })
40 })
41 }
42
43 updateDetails () {
44 const nsfwPolicy = this.form.value['nsfwPolicy']
45 const autoPlayVideo = this.form.value['autoPlayVideo']
46 const details: UserUpdateMe = {
47 nsfwPolicy,
48 autoPlayVideo
49 }
50
51 this.userService.updateMyProfile(details).subscribe(
52 () => {
53 this.notificationsService.success(this.i18n('Success'), this.i18n('Information updated.'))
54
55 this.authService.refreshUserInformation()
56 },
57
58 err => this.notificationsService.error(this.i18n('Error'), err.message)
59 )
60 }
61 }