1 import { ReplaySubject } from 'rxjs'
2 import { filter } from 'rxjs/operators'
3 import { Component, OnInit, ViewChild } from '@angular/core'
4 import { ActivatedRoute, Router } from '@angular/router'
5 import { AuthService, AuthStatus, LocalStorageService, User, UserService } from '@app/core'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
10 selector: 'my-quick-settings',
11 templateUrl: './quick-settings-modal.component.html'
13 export class QuickSettingsModalComponent implements OnInit {
14 private static readonly QUERY_MODAL_NAME = 'quick-settings'
16 @ViewChild('modal', { static: true }) modal: NgbModal
19 userInformationLoaded = new ReplaySubject<boolean>(1)
21 private openedModal: NgbModalRef
24 private modalService: NgbModal,
25 private userService: UserService,
26 private authService: AuthService,
27 private localStorageService: LocalStorageService,
28 private route: ActivatedRoute,
29 private router: Router
34 this.user = this.userService.getAnonymousUser()
35 this.localStorageService.watch()
37 next: () => this.user = this.userService.getAnonymousUser()
40 this.userInformationLoaded.next(true)
42 this.authService.loginChangedSource
43 .pipe(filter(status => status !== AuthStatus.LoggedIn))
46 this.user = this.userService.getAnonymousUser()
47 this.userInformationLoaded.next(true)
51 this.route.queryParams.subscribe(params => {
52 if (params['modal'] === QuickSettingsModalComponent.QUERY_MODAL_NAME) {
53 this.openedModal = this.modalService.open(this.modal, { centered: true })
55 this.openedModal.hidden.subscribe(() => this.setModalQuery('remove'))
61 return this.authService.isLoggedIn()
65 this.setModalQuery('add')
68 private setModalQuery (type: 'add' | 'remove') {
69 const modal = type === 'add'
70 ? QuickSettingsModalComponent.QUERY_MODAL_NAME
73 this.router.navigate([], { queryParams: { modal }, queryParamsHandling: 'merge' })