X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Bmy-account%2Fmy-account-settings%2Fmy-account-settings.component.ts;h=c1636895204e6278f777c2d53339b37f3d86122d;hb=931d3430184143ebd88e5243def6eb1d7acfdbf4;hp=62053d97b2003220cf0f7da19c3bfc3858c66001;hpb=6937f26a5e8b17c7a27f267bce2682ab01611f2f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts index 62053d97b..c16368952 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts @@ -1,27 +1,25 @@ -import { Component, OnInit, ViewChild } from '@angular/core' -import { NotificationsService } from 'angular2-notifications' -import { BytesPipe } from 'ngx-pipes' -import { AuthService } from '../../core' -import { User } from '../../shared' -import { UserService } from '../../shared/users' -import { I18n } from '@ngx-translate/i18n-polyfill' +import { ViewportScroller } from '@angular/common' +import { HttpErrorResponse } from '@angular/common/http' +import { AfterViewChecked, Component, OnInit } from '@angular/core' +import { AuthService, Notifier, User, UserService } from '@app/core' +import { uploadErrorHandler } from '@app/helpers' @Component({ selector: 'my-account-settings', templateUrl: './my-account-settings.component.html', styleUrls: [ './my-account-settings.component.scss' ] }) -export class MyAccountSettingsComponent implements OnInit { +export class MyAccountSettingsComponent implements OnInit, AfterViewChecked { user: User = null - userVideoQuota = '0' - userVideoQuotaUsed = 0 + + private lastScrollHash: string constructor ( + private viewportScroller: ViewportScroller, private userService: UserService, private authService: AuthService, - private notificationsService: NotificationsService, - private i18n: I18n - ) {} + private notifier: Notifier + ) {} get userInformationLoaded () { return this.authService.userInformationLoaded @@ -29,31 +27,43 @@ export class MyAccountSettingsComponent implements OnInit { ngOnInit () { this.user = this.authService.getUser() + } + + ngAfterViewChecked () { + if (window.location.hash && window.location.hash !== this.lastScrollHash) { + this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', '')) - this.authService.userInformationLoaded.subscribe( - () => { - if (this.user.videoQuota !== -1) { - this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString() - } else { - this.userVideoQuota = this.i18n('Unlimited') - } - } - ) - - this.userService.getMyVideoQuotaUsed() - .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed) + this.lastScrollHash = window.location.hash + } } onAvatarChange (formData: FormData) { this.userService.changeAvatar(formData) .subscribe( data => { - this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.')) + this.notifier.success($localize`Avatar changed.`) this.user.updateAccountAvatar(data.avatar) }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + (err: HttpErrorResponse) => uploadErrorHandler({ + err, + name: $localize`avatar`, + notifier: this.notifier + }) + ) + } + + onAvatarDelete () { + this.userService.deleteAvatar() + .subscribe( + data => { + this.notifier.success($localize`Avatar deleted.`) + + this.user.updateAccountAvatar() + }, + + (err: HttpErrorResponse) => this.notifier.error(err.message) ) } }