]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
Update build steps for localization
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
1 import { ViewportScroller } from '@angular/common'
2 import { AfterViewChecked, Component, OnInit } from '@angular/core'
3 import { AuthService, Notifier, User, UserService } from '@app/core'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5
6 @Component({
7 selector: 'my-account-settings',
8 templateUrl: './my-account-settings.component.html',
9 styleUrls: [ './my-account-settings.component.scss' ]
10 })
11 export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
12 user: User = null
13
14 private lastScrollHash: string
15
16 constructor (
17 private viewportScroller: ViewportScroller,
18 private userService: UserService,
19 private authService: AuthService,
20 private notifier: Notifier,
21 private i18n: I18n
22 ) {}
23
24 get userInformationLoaded () {
25 return this.authService.userInformationLoaded
26 }
27
28 ngOnInit () {
29 this.user = this.authService.getUser()
30 }
31
32 ngAfterViewChecked () {
33 if (window.location.hash && window.location.hash !== this.lastScrollHash) {
34 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
35
36 this.lastScrollHash = window.location.hash
37 }
38 }
39
40 onAvatarChange (formData: FormData) {
41 this.userService.changeAvatar(formData)
42 .subscribe(
43 data => {
44 this.notifier.success(this.i18n('Avatar changed.'))
45
46 this.user.updateAccountAvatar(data.avatar)
47 },
48
49 err => this.notifier.error(err.message)
50 )
51 }
52 }