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'
7 selector: 'my-account-settings',
8 templateUrl: './my-account-settings.component.html',
9 styleUrls: [ './my-account-settings.component.scss' ]
11 export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
14 private lastScrollHash: string
17 private viewportScroller: ViewportScroller,
18 private userService: UserService,
19 private authService: AuthService,
20 private notifier: Notifier,
24 get userInformationLoaded () {
25 return this.authService.userInformationLoaded
29 this.user = this.authService.getUser()
32 ngAfterViewChecked () {
33 if (window.location.hash && window.location.hash !== this.lastScrollHash) {
34 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
36 this.lastScrollHash = window.location.hash
40 onAvatarChange (formData: FormData) {
41 this.userService.changeAvatar(formData)
44 this.notifier.success(this.i18n('Avatar changed.'))
46 this.user.updateAccountAvatar(data.avatar)
49 err => this.notifier.error(err.message)