X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmodal%2Fquick-settings-modal.component.ts;h=19f75ad5c2338b001d7cc8151b038e372b7ceb01;hb=cd940f40cb62fa105b14e1ce838e97f316c13c5c;hp=155794d1b1769050b445eb20ca77991e021ff20e;hpb=5c20a45518c3afc40c9494cad4a78def92e5e288;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/modal/quick-settings-modal.component.ts b/client/src/app/modal/quick-settings-modal.component.ts index 155794d1b..19f75ad5c 100644 --- a/client/src/app/modal/quick-settings-modal.component.ts +++ b/client/src/app/modal/quick-settings-modal.component.ts @@ -1,18 +1,18 @@ -import { Component, ViewChild, OnInit } from '@angular/core' -import { AuthService, AuthStatus } from '@app/core' -import { FormReactive, FormValidatorService, UserService, User } from '@app/shared' -import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' import { ReplaySubject } from 'rxjs' -import { LocalStorageService } from '@app/shared/misc/storage.service' import { filter } from 'rxjs/operators' +import { Component, OnInit, ViewChild } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' +import { AuthService, AuthStatus, LocalStorageService, User, UserService } from '@app/core' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' @Component({ selector: 'my-quick-settings', - templateUrl: './quick-settings-modal.component.html', - styleUrls: [ './quick-settings-modal.component.scss' ] + templateUrl: './quick-settings-modal.component.html' }) -export class QuickSettingsModalComponent extends FormReactive implements OnInit { +export class QuickSettingsModalComponent implements OnInit { + private static readonly QUERY_MODAL_NAME = 'quick-settings' + @ViewChild('modal', { static: true }) modal: NgbModal user: User @@ -21,32 +21,40 @@ export class QuickSettingsModalComponent extends FormReactive implements OnInit private openedModal: NgbModalRef constructor ( - protected formValidatorService: FormValidatorService, private modalService: NgbModal, private userService: UserService, private authService: AuthService, - private localStorageService: LocalStorageService + private localStorageService: LocalStorageService, + private route: ActivatedRoute, + private router: Router ) { - super() } ngOnInit () { this.user = this.userService.getAnonymousUser() this.localStorageService.watch() - .subscribe( - () => this.user = this.userService.getAnonymousUser() - ) + .subscribe({ + next: () => this.user = this.userService.getAnonymousUser() + }) this.userInformationLoaded.next(true) this.authService.loginChangedSource .pipe(filter(status => status !== AuthStatus.LoggedIn)) - .subscribe( - () => { + .subscribe({ + next: () => { this.user = this.userService.getAnonymousUser() this.userInformationLoaded.next(true) } - ) + }) + + this.route.queryParams.subscribe(params => { + if (params['modal'] === QuickSettingsModalComponent.QUERY_MODAL_NAME) { + this.openedModal = this.modalService.open(this.modal, { centered: true }) + + this.openedModal.hidden.subscribe(() => this.setModalQuery('remove')) + } + }) } isUserLoggedIn () { @@ -54,11 +62,14 @@ export class QuickSettingsModalComponent extends FormReactive implements OnInit } show () { - this.openedModal = this.modalService.open(this.modal, { centered: true }) + this.setModalQuery('add') } - hide () { - this.openedModal.close() - this.form.reset() + private setModalQuery (type: 'add' | 'remove') { + const modal = type === 'add' + ? QuickSettingsModalComponent.QUERY_MODAL_NAME + : null + + this.router.navigate([], { queryParams: { modal }, queryParamsHandling: 'merge' }) } }