]> 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
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
1 import { Component, Input, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
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'
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 notifier: Notifier,
23 private userService: UserService,
24 private i18n: I18n
25 ) {
26 super()
27 }
28
29 ngOnInit () {
30 this.buildForm({
31 nsfwPolicy: null,
32 webTorrentEnabled: null,
33 autoPlayVideo: null
34 })
35
36 this.userInformationLoaded.subscribe(() => {
37 this.form.patchValue({
38 nsfwPolicy: this.user.nsfwPolicy,
39 webTorrentEnabled: this.user.webTorrentEnabled,
40 autoPlayVideo: this.user.autoPlayVideo === true
41 })
42 })
43 }
44
45 updateDetails () {
46 const nsfwPolicy = this.form.value['nsfwPolicy']
47 const webTorrentEnabled = this.form.value['webTorrentEnabled']
48 const autoPlayVideo = this.form.value['autoPlayVideo']
49 const details: UserUpdateMe = {
50 nsfwPolicy,
51 webTorrentEnabled,
52 autoPlayVideo
53 }
54
55 this.userService.updateMyProfile(details).subscribe(
56 () => {
57 this.notifier.success(this.i18n('Information updated.'))
58
59 this.authService.refreshUserInformation()
60 },
61
62 err => this.notifier.error(err.message)
63 )
64 }
65 }