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