|
1 | | -import {Component, Prop, h} from '@stencil/core'; |
| 1 | +import {Component, Prop, h, State} from '@stencil/core'; |
| 2 | + |
| 3 | +import {Subscription} from 'rxjs'; |
| 4 | + |
| 5 | +import {DeckEditorService} from '../../../services/editor/deck/deck-editor.service'; |
| 6 | +import {Deck} from '../../../models/data/deck'; |
2 | 7 |
|
3 | 8 | @Component({ |
4 | | - tag: 'app-navigation', |
5 | | - styleUrl: 'app-navigation.scss', |
6 | | - shadow: false |
| 9 | + tag: 'app-navigation', |
| 10 | + styleUrl: 'app-navigation.scss', |
| 11 | + shadow: false |
7 | 12 | }) |
8 | 13 | export class AppNavigation { |
9 | | - @Prop() menuToggle: boolean = true; |
10 | | - |
11 | | - @Prop() user: boolean = true; |
12 | | - |
13 | | - @Prop() presentation: boolean = false; |
14 | | - @Prop() publish: boolean = false; |
15 | | - |
16 | | - render() { |
17 | | - return (<ion-header> |
18 | | - <ion-toolbar> |
19 | | - {this.renderLogo()} |
20 | | - {this.renderMenuToggle()} |
21 | | - {this.renderUser()} |
22 | | - </ion-toolbar> |
23 | | - </ion-header> |
24 | | - ); |
25 | | - } |
26 | | - |
27 | | - private renderLogo() { |
28 | | - return <ion-router-link onClick={() => this.closeMenu()} href="/" routerDirection="forward" class="logo"> |
29 | | - <div> |
30 | | - <app-logo></app-logo> |
31 | | - <span class="ion-text-uppercase">DeckDeckGo <mark>BETA</mark></span> |
32 | | - </div> |
33 | | - </ion-router-link>; |
34 | | - } |
35 | | - |
36 | | - private closeMenu(): Promise<void> { |
37 | | - return new Promise<void>(async (resolve) => { |
38 | | - if (!document) { |
39 | | - return; |
40 | | - } |
41 | | - |
42 | | - const element: HTMLIonMenuElement = document.querySelector('ion-menu'); |
43 | | - |
44 | | - if (!element) { |
45 | | - resolve(); |
46 | | - return; |
47 | | - } |
48 | | - |
49 | | - await element.close(); |
50 | | - |
51 | | - resolve(); |
52 | | - }); |
53 | | - } |
54 | | - |
55 | | - private renderMenuToggle() { |
56 | | - if (this.menuToggle) { |
57 | | - return <ion-buttons slot="start"> |
58 | | - <ion-menu-toggle> |
59 | | - <ion-button> |
60 | | - <ion-icon slot="icon-only" name="menu"></ion-icon> |
61 | | - </ion-button> |
62 | | - </ion-menu-toggle> |
63 | | - </ion-buttons>; |
64 | | - } else { |
65 | | - return null; |
| 14 | + @Prop() menuToggle: boolean = true; |
| 15 | + |
| 16 | + @Prop() user: boolean = true; |
| 17 | + |
| 18 | + @Prop() presentation: boolean = false; |
| 19 | + @Prop() publish: boolean = false; |
| 20 | + |
| 21 | + private subscription: Subscription; |
| 22 | + private deckEditorService: DeckEditorService; |
| 23 | + |
| 24 | + @State() |
| 25 | + private deckName: string = null; |
| 26 | + |
| 27 | + constructor() { |
| 28 | + this.deckEditorService = DeckEditorService.getInstance(); |
| 29 | + } |
| 30 | + |
| 31 | + componentWillLoad() { |
| 32 | + this.subscription = this.deckEditorService.watch().subscribe((deck: Deck) => { |
| 33 | + this.deckName = deck && deck.data && deck.data.name && deck.data.name !== '' ? deck.data.name : null; |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + componentDidUnload() { |
| 38 | + if (this.subscription) { |
| 39 | + this.subscription.unsubscribe(); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + render() { |
| 44 | + return (<ion-header> |
| 45 | + <ion-toolbar> |
| 46 | + {this.renderTitle()} |
| 47 | + {this.renderMenuToggle()} |
| 48 | + {this.renderUser()} |
| 49 | + </ion-toolbar> |
| 50 | + </ion-header> |
| 51 | + ); |
66 | 52 | } |
67 | | - } |
68 | | - |
69 | | - private renderUser() { |
70 | | - if (this.user) { |
71 | | - return <div slot="end"> |
72 | | - <app-navigation-actions presentation={this.presentation} publish={this.publish}></app-navigation-actions> |
73 | | - </div>; |
74 | | - } else { |
75 | | - return null; |
| 53 | + |
| 54 | + private renderTitle() { |
| 55 | + const titleClass = this.deckName && this.deckName !== '' ? 'title deck-name-visible' : 'title'; |
| 56 | + |
| 57 | + return <div class={titleClass}> |
| 58 | + <ion-router-link onClick={() => this.closeMenu()} href="/" routerDirection="forward" class="home"> |
| 59 | + <div> |
| 60 | + <app-logo></app-logo> |
| 61 | + <ion-label class="ion-text-uppercase">DeckDeckGo <mark>BETA</mark></ion-label> |
| 62 | + </div> |
| 63 | + </ion-router-link> |
| 64 | + |
| 65 | + <ion-label class="ion-text-uppercase deck-name">{this.deckName}</ion-label> |
| 66 | + </div> |
| 67 | + } |
| 68 | + |
| 69 | + private closeMenu(): Promise<void> { |
| 70 | + return new Promise<void>(async (resolve) => { |
| 71 | + if (!document) { |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + const element: HTMLIonMenuElement = document.querySelector('ion-menu'); |
| 76 | + |
| 77 | + if (!element) { |
| 78 | + resolve(); |
| 79 | + return; |
| 80 | + } |
| 81 | + |
| 82 | + await element.close(); |
| 83 | + |
| 84 | + resolve(); |
| 85 | + }); |
| 86 | + } |
| 87 | + |
| 88 | + private renderMenuToggle() { |
| 89 | + if (this.menuToggle) { |
| 90 | + return <ion-buttons slot="start"> |
| 91 | + <ion-menu-toggle> |
| 92 | + <ion-button> |
| 93 | + <ion-icon slot="icon-only" name="menu"></ion-icon> |
| 94 | + </ion-button> |
| 95 | + </ion-menu-toggle> |
| 96 | + </ion-buttons>; |
| 97 | + } else { |
| 98 | + return null; |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + private renderUser() { |
| 103 | + if (this.user) { |
| 104 | + return <div slot="end"> |
| 105 | + <app-navigation-actions presentation={this.presentation} |
| 106 | + publish={this.publish}></app-navigation-actions> |
| 107 | + </div>; |
| 108 | + } else { |
| 109 | + return null; |
| 110 | + } |
76 | 111 | } |
77 | | - } |
78 | 112 |
|
79 | 113 | } |
0 commit comments