X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmodal%2Fquick-settings-modal.component.ts;h=19f75ad5c2338b001d7cc8151b038e372b7ceb01;hb=4de99f22dfc4f00587eeac5bc929f462437315e4;hp=7a53179cb47ac0df3eb578ac468d2f0833fb51ef;hpb=1378c0d343028f3d40d7d795422684ab9e6a1599;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 7a53179cb..19f75ad5c 100644 --- a/client/src/app/modal/quick-settings-modal.component.ts +++ b/client/src/app/modal/quick-settings-modal.component.ts @@ -1,8 +1,8 @@ import { ReplaySubject } from 'rxjs' 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 { FormReactive, FormValidatorService } from '@app/shared/shared-forms' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' @@ -10,7 +10,9 @@ import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' selector: 'my-quick-settings', 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 @@ -19,13 +21,13 @@ 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 () { @@ -45,6 +47,14 @@ export class QuickSettingsModalComponent extends FormReactive implements OnInit 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 () { @@ -52,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' }) } }