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