]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/account/account-settings/account-settings.component.ts
Begin to add avatar to actors
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-settings / account-settings.component.ts
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'
8
9 @Component({
10 selector: 'my-account-settings',
11 templateUrl: './account-settings.component.html',
12 styleUrls: [ './account-settings.component.scss' ]
13 })
14 export class AccountSettingsComponent implements OnInit {
15 @ViewChild('avatarfileInput') avatarfileInput
16
17 user: User = null
18
19 constructor (
20 private userService: UserService,
21 private authService: AuthService,
22 private notificationsService: NotificationsService
23 ) {}
24
25 ngOnInit () {
26 this.user = this.authService.getUser()
27 }
28
29 getAvatarUrl () {
30 return this.user.getAvatarUrl()
31 }
32
33 changeAvatar () {
34 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
35
36 const formData = new FormData()
37 formData.append('avatarfile', avatarfile)
38
39 this.userService.changeAvatar(formData)
40 .subscribe(
41 data => {
42 this.notificationsService.success('Success', 'Avatar changed.')
43
44 this.user.account.avatar = data.avatar
45 },
46
47 err => this.notificationsService.error('Error', err.message)
48 )
49 }
50 }