@@ -7,7 +7,7 @@ import {Router} from '@vaadin/router';
7
7
import { css , html , LitElement } from 'lit' ;
8
8
import { i18nMixin , translate } from 'lit-element-i18n' ;
9
9
10
- import { getUser } from '@thinkdeep/deep-economic-analyzer/user.js' ;
10
+ import { user , premium } from '@thinkdeep/deep-economic-analyzer/user.js' ;
11
11
import { initApolloClient } from './graphql/client.js' ;
12
12
13
13
/**
@@ -20,8 +20,14 @@ export class DeepEconomicAnalyzer extends i18nMixin(LitElement) {
20
20
static get properties ( ) {
21
21
return {
22
22
companyName : { type : String } ,
23
+
24
+ /** Window location */
23
25
location : { type : Object } ,
26
+
24
27
user : { type : Object } ,
28
+
29
+ /** Indicates whether the logged in user is a premium user */
30
+ premiumAccount : { type : Boolean } ,
25
31
} ;
26
32
}
27
33
@@ -33,6 +39,7 @@ export class DeepEconomicAnalyzer extends i18nMixin(LitElement) {
33
39
this . companyName = '' ;
34
40
this . location = Router . location ;
35
41
this . user = { } ;
42
+ this . premiumAccount = false ;
36
43
}
37
44
38
45
/**
@@ -56,8 +63,9 @@ export class DeepEconomicAnalyzer extends i18nMixin(LitElement) {
56
63
57
64
this . companyName = translate ( 'translations:companyName' ) ;
58
65
59
- this . user = await getUser ( ) ;
60
- await initApolloClient ( ) ;
66
+ this . user = await user ( ) ;
67
+ this . premiumAccount = premium ( this . user ) ;
68
+ await initApolloClient ( this . user ) ;
61
69
62
70
const routes = [
63
71
{
@@ -81,6 +89,19 @@ export class DeepEconomicAnalyzer extends i18nMixin(LitElement) {
81
89
] ;
82
90
83
91
if ( this . user . loggedIn ) {
92
+ if ( this . premiumAccount ) {
93
+ routes . push ( {
94
+ path : `/${ translate ( 'translations:summaryPageLabel' ) } ` ,
95
+ name : translate ( 'translations:summaryPageLabel' ) ,
96
+ component : 'deep-analyzer-page-summary' ,
97
+ action : async ( ) => {
98
+ await import (
99
+ '@thinkdeep/deep-economic-analyzer/deep-analyzer-page-summary.js'
100
+ ) ;
101
+ } ,
102
+ } ) ;
103
+ }
104
+
84
105
routes . push ( {
85
106
path : `/${ translate ( 'translations:logoutPageLabel' ) } ` ,
86
107
name : translate ( 'translations:logoutPageLabel' ) ,
@@ -89,16 +110,6 @@ export class DeepEconomicAnalyzer extends i18nMixin(LitElement) {
89
110
await this . user . logout ( ) ;
90
111
} ,
91
112
} ) ;
92
- routes . push ( {
93
- path : `/${ translate ( 'translations:summaryPageLabel' ) } ` ,
94
- name : translate ( 'translations:summaryPageLabel' ) ,
95
- component : 'deep-analyzer-page-summary' ,
96
- action : async ( ) => {
97
- await import (
98
- '@thinkdeep/deep-economic-analyzer/deep-analyzer-page-summary.js'
99
- ) ;
100
- } ,
101
- } ) ;
102
113
}
103
114
104
115
// NOTE: It appears that the vaadin router implements a sort of chain-of-responsibility in that it
@@ -168,51 +179,91 @@ export class DeepEconomicAnalyzer extends i18nMixin(LitElement) {
168
179
*/
169
180
render ( ) {
170
181
return html `
171
- ${ this . styles }
182
+ ${ DeepEconomicAnalyzer . styles }
172
183
173
184
< mwc-top-app-bar-fixed >
174
185
< div slot ="title "> ${ this . companyName } </ div >
175
186
176
- < mwc-icon-button
177
- @click =${ ( ) => Router . go ( '/' ) }
178
- icon ="home"
179
- aria-label="${ translate ( 'translations:homePageLabel' ) } "
180
- >
181
- </ mwc-icon-button >
182
-
183
- ${ this . user . loggedIn
184
- ? html `
185
- < mwc-icon-button
186
- @click =${ ( ) =>
187
- Router . go ( '/' + translate ( 'translations:summaryPageLabel' ) ) }
188
- icon ="space_dashboard"
189
- aria-label="${ translate ( 'translations:summaryPageLabel' ) } "
190
- >
191
- </ mwc-icon-button >
192
- < mwc-icon-button
193
- @click ="${ ( ) =>
194
- Router . go ( '/' + translate ( 'translations:logoutPageLabel' ) ) } "
195
- icon ="logout "
196
- aria-label ="${ translate ( 'translations:logoutPageLabel' ) } "
197
- >
198
- </ mwc-icon-button >
199
- `
200
- : html `
201
- < mwc-icon-button
202
- @click ="${ ( ) =>
203
- Router . go ( '/' + translate ( 'translations:loginPageLabel' ) ) } "
204
- icon ="login "
205
- aria-label ="${ translate ( 'translations:loginPageLabel' ) } "
206
- >
207
- </ mwc-icon-button >
208
- ` }
187
+ ${ this . menuItems ( this . user , this . premiumAccount ) }
209
188
</ mwc-top-app-bar-fixed >
210
189
211
190
< main id ="content "> </ main >
212
191
213
192
< deep-footer .companyName ="${ this . companyName } "> </ deep-footer >
214
193
` ;
215
194
}
195
+
196
+ /**
197
+ * Return the markup needed to render the menu items.
198
+ *
199
+ * @param {Object } user Current user.
200
+ * @param {Boolean } premiumAccount Whether the current user is a premium user.
201
+ *
202
+ * @return {TemplateResult } Template definining the menu items.
203
+ */
204
+ menuItems ( user , premiumAccount ) {
205
+ return html ` < mwc-icon-button
206
+ @click =${ ( ) => Router . go ( '/' ) }
207
+ icon ="home"
208
+ aria-label="${ translate ( 'translations:homePageLabel' ) } "
209
+ >
210
+ </ mwc-icon-button >
211
+
212
+ ${ user && user . loggedIn
213
+ ? this . protectedMenuItems ( premiumAccount )
214
+ : this . standardMenuItems ( ) } `;
215
+ }
216
+
217
+ /**
218
+ * Get the markup for protected menu items.
219
+ * @param {Boolean } premiumAccount Whether the current user is a premium user.
220
+ * @return {TemplateResult } Template of the menu items.
221
+ */
222
+ protectedMenuItems ( premiumAccount ) {
223
+ return html `
224
+ ${ premiumAccount ? this . premiumMenuItems ( ) : '' }
225
+
226
+ < mwc-icon-button
227
+ @click ="${ ( ) =>
228
+ Router . go ( '/' + translate ( 'translations:logoutPageLabel' ) ) } "
229
+ icon ="logout "
230
+ aria-label ="${ translate ( 'translations:logoutPageLabel' ) } "
231
+ >
232
+ </ mwc-icon-button >
233
+ ` ;
234
+ }
235
+
236
+ /**
237
+ * Get the markup for premium menu items.
238
+ * @return {TemplateResult } Template containing menu items.
239
+ */
240
+ premiumMenuItems ( ) {
241
+ return html `
242
+ < mwc-icon-button
243
+ @click =${ ( ) =>
244
+ Router . go ( '/' + translate ( 'translations:summaryPageLabel' ) ) }
245
+ icon ="space_dashboard"
246
+ aria-label="${ translate ( 'translations:summaryPageLabel' ) } "
247
+ >
248
+ </ mwc-icon-button >
249
+ ` ;
250
+ }
251
+
252
+ /**
253
+ * Get the markup for standard menu items.
254
+ * @return {TemplateResult } Template containing menu items.
255
+ */
256
+ standardMenuItems ( ) {
257
+ return html `
258
+ < mwc-icon-button
259
+ @click ="${ ( ) =>
260
+ Router . go ( '/' + translate ( 'translations:loginPageLabel' ) ) } "
261
+ icon ="login "
262
+ aria-label ="${ translate ( 'translations:loginPageLabel' ) } "
263
+ >
264
+ </ mwc-icon-button >
265
+ ` ;
266
+ }
216
267
}
217
268
218
269
customElements . define ( 'deep-economic-analyzer' , DeepEconomicAnalyzer ) ;
0 commit comments