]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
Add new anchors in my-settings and handle offset sub-menu height (#3032)
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
CommitLineData
45e0d669 1import { ViewportScroller } from '@angular/common'
67ed6552
C
2import { AfterViewChecked, Component, OnInit } from '@angular/core'
3import { AuthService, Notifier, User, UserService } from '@app/core'
4import { I18n } from '@ngx-translate/i18n-polyfill'
c30745f3
C
5
6@Component({
7 selector: 'my-account-settings',
4bb6886d
C
8 templateUrl: './my-account-settings.component.html',
9 styleUrls: [ './my-account-settings.component.scss' ]
c30745f3 10})
45e0d669 11export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
c30745f3 12 user: User = null
66fd1516 13
64e0f8cf
C
14 private lastScrollHash: string
15
c5911fd3 16 constructor (
45e0d669 17 private viewportScroller: ViewportScroller,
c5911fd3
C
18 private userService: UserService,
19 private authService: AuthService,
f8b2c1b4 20 private notifier: Notifier,
b1d40cff 21 private i18n: I18n
c5911fd3 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 => {
f8b2c1b4 44 this.notifier.success(this.i18n('Avatar changed.'))
c5911fd3 45
0c237b19 46 this.user.updateAccountAvatar(data.avatar)
c5911fd3
C
47 },
48
f8b2c1b4 49 err => this.notifier.error(err.message)
c5911fd3 50 )
2295ce6c 51 }
c30745f3 52}