]>
Commit | Line | Data |
---|---|---|
45e0d669 | 1 | import { ViewportScroller } from '@angular/common' |
67ed6552 C |
2 | import { AfterViewChecked, Component, OnInit } from '@angular/core' |
3 | import { AuthService, Notifier, User, UserService } from '@app/core' | |
c30745f3 C |
4 | |
5 | @Component({ | |
6 | selector: 'my-account-settings', | |
4bb6886d C |
7 | templateUrl: './my-account-settings.component.html', |
8 | styleUrls: [ './my-account-settings.component.scss' ] | |
c30745f3 | 9 | }) |
45e0d669 | 10 | export class MyAccountSettingsComponent implements OnInit, AfterViewChecked { |
c30745f3 | 11 | user: User = null |
66fd1516 | 12 | |
64e0f8cf C |
13 | private lastScrollHash: string |
14 | ||
c5911fd3 | 15 | constructor ( |
45e0d669 | 16 | private viewportScroller: ViewportScroller, |
c5911fd3 C |
17 | private userService: UserService, |
18 | private authService: AuthService, | |
66357162 C |
19 | private notifier: Notifier |
20 | ) {} | |
c30745f3 | 21 | |
d18d6478 C |
22 | get userInformationLoaded () { |
23 | return this.authService.userInformationLoaded | |
24 | } | |
25 | ||
c30745f3 C |
26 | ngOnInit () { |
27 | this.user = this.authService.getUser() | |
28 | } | |
2295ce6c | 29 | |
45e0d669 | 30 | ngAfterViewChecked () { |
64e0f8cf C |
31 | if (window.location.hash && window.location.hash !== this.lastScrollHash) { |
32 | this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', '')) | |
33 | ||
34 | this.lastScrollHash = window.location.hash | |
35 | } | |
45e0d669 RK |
36 | } |
37 | ||
52d9f792 | 38 | onAvatarChange (formData: FormData) { |
c5911fd3 C |
39 | this.userService.changeAvatar(formData) |
40 | .subscribe( | |
41 | data => { | |
66357162 | 42 | this.notifier.success($localize`Avatar changed.`) |
c5911fd3 | 43 | |
0c237b19 | 44 | this.user.updateAccountAvatar(data.avatar) |
c5911fd3 C |
45 | }, |
46 | ||
f8b2c1b4 | 47 | err => this.notifier.error(err.message) |
c5911fd3 | 48 | ) |
2295ce6c | 49 | } |
c30745f3 | 50 | } |