]>
Commit | Line | Data |
---|---|---|
1 | import { ViewportScroller } from '@angular/common' | |
2 | import { AfterViewChecked, Component, OnInit } from '@angular/core' | |
3 | import { AuthService, Notifier, User, UserService } from '@app/core' | |
4 | ||
5 | @Component({ | |
6 | selector: 'my-account-settings', | |
7 | templateUrl: './my-account-settings.component.html', | |
8 | styleUrls: [ './my-account-settings.component.scss' ] | |
9 | }) | |
10 | export class MyAccountSettingsComponent implements OnInit, AfterViewChecked { | |
11 | user: User = null | |
12 | ||
13 | private lastScrollHash: string | |
14 | ||
15 | constructor ( | |
16 | private viewportScroller: ViewportScroller, | |
17 | private userService: UserService, | |
18 | private authService: AuthService, | |
19 | private notifier: Notifier | |
20 | ) {} | |
21 | ||
22 | get userInformationLoaded () { | |
23 | return this.authService.userInformationLoaded | |
24 | } | |
25 | ||
26 | ngOnInit () { | |
27 | this.user = this.authService.getUser() | |
28 | } | |
29 | ||
30 | ngAfterViewChecked () { | |
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 | } | |
36 | } | |
37 | ||
38 | onAvatarChange (formData: FormData) { | |
39 | this.userService.changeAvatar(formData) | |
40 | .subscribe( | |
41 | data => { | |
42 | this.notifier.success($localize`Avatar changed.`) | |
43 | ||
44 | this.user.updateAccountAvatar(data.avatar) | |
45 | }, | |
46 | ||
47 | err => this.notifier.error(err.message) | |
48 | ) | |
49 | } | |
50 | } |