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