1 import { HttpEventType, HttpResponse } from '@angular/common/http'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { NotificationsService } from 'angular2-notifications'
4 import { VideoPrivacy } from '../../../../../shared/models/videos'
5 import { User } from '../../shared'
6 import { AuthService } from '../../core'
7 import { UserService } from '../../shared/users'
10 selector: 'my-account-settings',
11 templateUrl: './account-settings.component.html',
12 styleUrls: [ './account-settings.component.scss' ]
14 export class AccountSettingsComponent implements OnInit {
15 @ViewChild('avatarfileInput') avatarfileInput
20 private userService: UserService,
21 private authService: AuthService,
22 private notificationsService: NotificationsService
26 this.user = this.authService.getUser()
30 return this.user.getAvatarUrl()
34 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
36 const formData = new FormData()
37 formData.append('avatarfile', avatarfile)
39 this.userService.changeAvatar(formData)
42 this.notificationsService.success('Success', 'Avatar changed.')
44 this.user.account.avatar = data.avatar
47 err => this.notificationsService.error('Error', err.message)