]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
CommitLineData
c5911fd3 1import { Component, OnInit, ViewChild } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
234b535d 3import { BytesPipe } from 'ngx-pipes'
c30745f3 4import { AuthService } from '../../core'
01de67b9 5import { User } from '../../shared'
c5911fd3 6import { UserService } from '../../shared/users'
b1d40cff 7import { I18n } from '@ngx-translate/i18n-polyfill'
c30745f3
C
8
9@Component({
10 selector: 'my-account-settings',
4bb6886d
C
11 templateUrl: './my-account-settings.component.html',
12 styleUrls: [ './my-account-settings.component.scss' ]
c30745f3 13})
4bb6886d 14export class MyAccountSettingsComponent implements OnInit {
c30745f3 15 user: User = null
234b535d 16 userVideoQuota = '0'
ce5496d6 17 userVideoQuotaUsed = 0
c30745f3 18
c5911fd3
C
19 constructor (
20 private userService: UserService,
21 private authService: AuthService,
f8b2c1b4 22 private notifier: Notifier,
b1d40cff 23 private i18n: I18n
c5911fd3 24 ) {}
c30745f3 25
d18d6478
C
26 get userInformationLoaded () {
27 return this.authService.userInformationLoaded
28 }
29
c30745f3
C
30 ngOnInit () {
31 this.user = this.authService.getUser()
ce5496d6 32
234b535d
C
33 this.authService.userInformationLoaded.subscribe(
34 () => {
35 if (this.user.videoQuota !== -1) {
36 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
37 } else {
b1d40cff 38 this.userVideoQuota = this.i18n('Unlimited')
234b535d
C
39 }
40 }
41 )
42
ce5496d6
C
43 this.userService.getMyVideoQuotaUsed()
44 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
c30745f3 45 }
2295ce6c 46
52d9f792 47 onAvatarChange (formData: FormData) {
c5911fd3
C
48 this.userService.changeAvatar(formData)
49 .subscribe(
50 data => {
f8b2c1b4 51 this.notifier.success(this.i18n('Avatar changed.'))
c5911fd3 52
0c237b19 53 this.user.updateAccountAvatar(data.avatar)
c5911fd3
C
54 },
55
f8b2c1b4 56 err => this.notifier.error(err.message)
c5911fd3 57 )
2295ce6c 58 }
c30745f3 59}