diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-28 13:52:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 13:52:21 +0100 |
commit | d3217560a611b94f888ecf3de93b428a7521d4de (patch) | |
tree | 26fc984f351afb994dc13c94e138476ded50c76a /client/src/app/modal/quick-settings-modal.component.ts | |
parent | 64645512b08875c18ebdc009a550cdfa69def955 (diff) | |
download | PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.tar.gz PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.tar.zst PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.zip |
Add visitor settings, rework logged-in dropdown (#2514)
* Add visitor settings, rework logged-in dropdown
* Make user dropdown P2P switch functional
* Fix lint
* Fix unnecessary notification when user logs out
* Simplify visitor settings code and remove unnecessary icons
* Catch parsing errors and reindent menu styles
Diffstat (limited to 'client/src/app/modal/quick-settings-modal.component.ts')
-rw-r--r-- | client/src/app/modal/quick-settings-modal.component.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/client/src/app/modal/quick-settings-modal.component.ts b/client/src/app/modal/quick-settings-modal.component.ts new file mode 100644 index 000000000..41d6c9f47 --- /dev/null +++ b/client/src/app/modal/quick-settings-modal.component.ts | |||
@@ -0,0 +1,62 @@ | |||
1 | import { Component, ViewChild, OnInit } from '@angular/core' | ||
2 | import { AuthService, AuthStatus } from '@app/core' | ||
3 | import { FormReactive, FormValidatorService, UserService, User } from '@app/shared' | ||
4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
5 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
6 | import { ReplaySubject } from 'rxjs' | ||
7 | import { LocalStorageService } from '@app/shared/misc/storage.service' | ||
8 | import { 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 | }) | ||
15 | export 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() | ||
35 | this.localStorageService.watch().subscribe( | ||
36 | () => this.user = this.userService.getAnonymousUser() | ||
37 | ) | ||
38 | this.userInformationLoaded.next(true) | ||
39 | |||
40 | this.authService.loginChangedSource | ||
41 | .pipe(filter(status => status !== AuthStatus.LoggedIn)) | ||
42 | .subscribe( | ||
43 | () => { | ||
44 | this.user = this.userService.getAnonymousUser() | ||
45 | this.userInformationLoaded.next(true) | ||
46 | } | ||
47 | ) | ||
48 | } | ||
49 | |||
50 | isUserLoggedIn () { | ||
51 | return this.authService.isLoggedIn() | ||
52 | } | ||
53 | |||
54 | show () { | ||
55 | this.openedModal = this.modalService.open(this.modal, { centered: true }) | ||
56 | } | ||
57 | |||
58 | hide () { | ||
59 | this.openedModal.close() | ||
60 | this.form.reset() | ||
61 | } | ||
62 | } | ||