]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/modal/quick-settings-modal.component.ts
Fix anonymous nsfw policy
[github/Chocobozzz/PeerTube.git] / client / src / app / modal / quick-settings-modal.component.ts
CommitLineData
d3217560
RK
1import { Component, ViewChild, OnInit } from '@angular/core'
2import { AuthService, AuthStatus } from '@app/core'
3import { FormReactive, FormValidatorService, UserService, User } from '@app/shared'
4import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
6import { ReplaySubject } from 'rxjs'
7import { LocalStorageService } from '@app/shared/misc/storage.service'
8import { filter } from 'rxjs/operators'
9
10@Component({
11 selector: 'my-quick-settings',
12 templateUrl: './quick-settings-modal.component.html',
13 styleUrls: [ './quick-settings-modal.component.scss' ]
14})
15export class QuickSettingsModalComponent extends FormReactive implements OnInit {
16 @ViewChild('modal', { static: true }) modal: NgbModal
17
18 user: User
19 userInformationLoaded = new ReplaySubject<boolean>(1)
20
21 private openedModal: NgbModalRef
22
23 constructor (
24 protected formValidatorService: FormValidatorService,
25 private modalService: NgbModal,
26 private userService: UserService,
27 private authService: AuthService,
28 private localStorageService: LocalStorageService
29 ) {
30 super()
31 }
32
33 ngOnInit () {
34 this.user = this.userService.getAnonymousUser()
5c20a455
C
35 this.localStorageService.watch()
36 .subscribe(
37 () => this.user = this.userService.getAnonymousUser()
38 )
39
d3217560
RK
40 this.userInformationLoaded.next(true)
41
42 this.authService.loginChangedSource
43 .pipe(filter(status => status !== AuthStatus.LoggedIn))
44 .subscribe(
45 () => {
46 this.user = this.userService.getAnonymousUser()
47 this.userInformationLoaded.next(true)
48 }
49 )
50 }
51
52 isUserLoggedIn () {
53 return this.authService.isLoggedIn()
54 }
55
56 show () {
57 this.openedModal = this.modalService.open(this.modal, { centered: true })
58 }
59
60 hide () {
61 this.openedModal.close()
62 this.form.reset()
63 }
64}