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'
6 import { shallowCopy } from '@shared/core-utils'
9 selector: 'my-account-settings',
10 templateUrl: './my-account-settings.component.html',
11 styleUrls: [ './my-account-settings.component.scss' ]
13 export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
16 private lastScrollHash: string
19 private viewportScroller: ViewportScroller,
20 private userService: UserService,
21 private authService: AuthService,
22 private notifier: Notifier
25 get userInformationLoaded () {
26 return this.authService.userInformationLoaded
30 this.user = this.authService.getUser()
33 ngAfterViewChecked () {
34 if (window.location.hash && window.location.hash !== this.lastScrollHash) {
35 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
37 this.lastScrollHash = window.location.hash
41 onAvatarChange (formData: FormData) {
42 this.userService.changeAvatar(formData)
45 this.notifier.success($localize`Avatar changed.`)
47 this.user.updateAccountAvatar(data.avatars)
49 // So my-actor-avatar component detects changes
50 this.user.account = shallowCopy(this.user.account)
53 error: (err: HttpErrorResponse) => genericUploadErrorHandler({
55 name: $localize`avatar`,
56 notifier: this.notifier
62 this.userService.deleteAvatar()
65 this.notifier.success($localize`Avatar deleted.`)
67 this.user.updateAccountAvatar()
69 // So my-actor-avatar component detects changes
70 this.user.account = shallowCopy(this.user.account)
73 error: (err: HttpErrorResponse) => this.notifier.error(err.message)