1 import { ViewportScroller } from '@angular/common'
2 import { HttpErrorResponse } from '@angular/common/http'
3 import { AfterViewChecked, Component, OnInit } from '@angular/core'
4 import { AuthService, Notifier, User, UserService } from '@app/core'
5 import { genericUploadErrorHandler } from '@app/helpers'
8 selector: 'my-account-settings',
9 templateUrl: './my-account-settings.component.html',
10 styleUrls: [ './my-account-settings.component.scss' ]
12 export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
15 private lastScrollHash: string
18 private viewportScroller: ViewportScroller,
19 private userService: UserService,
20 private authService: AuthService,
21 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($localize`Avatar changed.`)
46 this.user.updateAccountAvatar(data.avatars)
49 error: (err: HttpErrorResponse) => genericUploadErrorHandler({
51 name: $localize`avatar`,
52 notifier: this.notifier
58 this.userService.deleteAvatar()
61 this.notifier.success($localize`Avatar deleted.`)
63 this.user.updateAccountAvatar()
66 error: (err: HttpErrorResponse) => this.notifier.error(err.message)