1 import { Component, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { BytesPipe } from 'ngx-pipes'
4 import { AuthService } from '../../core'
5 import { User } from '../../shared'
6 import { UserService } from '../../shared/users'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
10 selector: 'my-account-settings',
11 templateUrl: './my-account-settings.component.html',
12 styleUrls: [ './my-account-settings.component.scss' ]
14 export class MyAccountSettingsComponent implements OnInit {
17 userVideoQuotaUsed = 0
20 private userService: UserService,
21 private authService: AuthService,
22 private notifier: Notifier,
26 get userInformationLoaded () {
27 return this.authService.userInformationLoaded
31 this.user = this.authService.getUser()
33 this.authService.userInformationLoaded.subscribe(
35 if (this.user.videoQuota !== -1) {
36 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
38 this.userVideoQuota = this.i18n('Unlimited')
43 this.userService.getMyVideoQuotaUsed()
44 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
47 onAvatarChange (formData: FormData) {
48 this.userService.changeAvatar(formData)
51 this.notifier.success(this.i18n('Avatar changed.'))
53 this.user.updateAccountAvatar(data.avatar)
56 err => this.notifier.error(err.message)