@triptease/tt-navbar 0.0.40 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/NavbarController.d.ts +4 -1
- package/dist/src/NavbarController.js +21 -10
- package/dist/src/NavbarController.js.map +1 -1
- package/dist/src/TtNavbar.js +20 -19
- package/dist/src/TtNavbar.js.map +1 -1
- package/dist/test/tt-navbar.test.js +23 -12
- package/dist/test/tt-navbar.test.js.map +1 -1
- package/dist/web/NavbarController.js +22 -11
- package/dist/web/NavbarController.js.map +2 -2
- package/dist/web/Routes.js +1 -1
- package/dist/web/TtNavbar.js +38 -28
- package/dist/web/TtNavbar.js.map +3 -3
- package/dist/web/global.d.js +1 -1
- package/dist/web/index.js +38 -28
- package/dist/web/index.js.map +3 -3
- package/dist/web/styles.js +1 -1
- package/dist/web/triptease-logo.js +1 -1
- package/dist/web/tt-navbar.js +38 -28
- package/dist/web/tt-navbar.js.map +3 -3
- package/dist/web/urlMappings.js +1 -1
- package/package.json +2 -1
- package/src/NavbarController.ts +28 -11
- package/src/TtNavbar.ts +23 -22
- package/test/tt-navbar.test.ts +28 -12
package/dist/web/urlMappings.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Webcomponent tt-navbar following open-wc recommendations",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "tt-navbar",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.42",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/src/index.js",
|
|
9
9
|
"module": "dist/src/index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@clerk/clerk-js": "^5.102.1",
|
|
31
|
+
"@clerk/types": "^4.95.1",
|
|
31
32
|
"@triptease/icons": "^1.1.1",
|
|
32
33
|
"@triptease/tt-combobox": "^5.3.0",
|
|
33
34
|
"lit": "^3.1.4"
|
package/src/NavbarController.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
import { UnsubscribeCallback } from '@clerk/types';
|
|
2
3
|
|
|
3
4
|
export class NavbarController implements ReactiveController {
|
|
4
5
|
host: ReactiveControllerHost;
|
|
5
6
|
|
|
6
7
|
private _isOpen = true;
|
|
7
8
|
|
|
9
|
+
private _hasInitialized = false;
|
|
10
|
+
|
|
11
|
+
private _removeClerkListener?: UnsubscribeCallback;
|
|
12
|
+
|
|
8
13
|
constructor(host: ReactiveControllerHost) {
|
|
9
14
|
(this.host = host).addController(this);
|
|
10
15
|
}
|
|
@@ -13,21 +18,33 @@ export class NavbarController implements ReactiveController {
|
|
|
13
18
|
return this._isOpen;
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
if (window.Clerk) {
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
hostUpdate() {
|
|
22
|
+
if (!this._hasInitialized && window.Clerk) {
|
|
23
|
+
this._removeClerkListener = window.Clerk.addListener(resources => {
|
|
24
|
+
const { user } = resources;
|
|
25
|
+
if (user && !this._hasInitialized) {
|
|
26
|
+
const navigationOpen =
|
|
27
|
+
user.unsafeMetadata?.preferences?.ui?.navigationOpen;
|
|
28
|
+
|
|
29
|
+
if (navigationOpen !== undefined) {
|
|
30
|
+
this._isOpen = navigationOpen;
|
|
31
|
+
this.host.requestUpdate();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this._hasInitialized = true;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
20
39
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
40
|
+
hostDisconnected() {
|
|
41
|
+
if (this._removeClerkListener) {
|
|
42
|
+
this._removeClerkListener();
|
|
25
43
|
}
|
|
26
44
|
}
|
|
27
45
|
|
|
28
46
|
async toggle() {
|
|
29
|
-
|
|
30
|
-
this._isOpen = newState;
|
|
47
|
+
this._isOpen = !this._isOpen;
|
|
31
48
|
|
|
32
49
|
if (window.Clerk) {
|
|
33
50
|
await window.Clerk.user?.update({
|
|
@@ -37,7 +54,7 @@ export class NavbarController implements ReactiveController {
|
|
|
37
54
|
...window.Clerk.user?.unsafeMetadata?.preferences,
|
|
38
55
|
ui: {
|
|
39
56
|
...window.Clerk.user?.unsafeMetadata?.preferences?.ui,
|
|
40
|
-
navigationOpen:
|
|
57
|
+
navigationOpen: this.isOpen,
|
|
41
58
|
},
|
|
42
59
|
},
|
|
43
60
|
},
|
package/src/TtNavbar.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
logout,
|
|
13
13
|
sidebarCollapsed,
|
|
14
14
|
user,
|
|
15
|
-
wallet
|
|
15
|
+
wallet,
|
|
16
16
|
} from '@triptease/icons';
|
|
17
17
|
import '@triptease/tt-combobox';
|
|
18
18
|
import { styles } from './styles.js';
|
|
@@ -121,10 +121,11 @@ export class TtNavbar extends LitElement {
|
|
|
121
121
|
const parsedPath = currentPath.replace(this.clientKey, '$CLIENT_KEY');
|
|
122
122
|
const mappedUrl = urlMappings[parsedPath];
|
|
123
123
|
if (mappedUrl) {
|
|
124
|
-
const clientSpecificUrl = mappedUrl.includes('$CLIENT_KEY')
|
|
124
|
+
const clientSpecificUrl = mappedUrl.includes('$CLIENT_KEY')
|
|
125
|
+
? mappedUrl.replace('$CLIENT_KEY', this.clientKey)
|
|
126
|
+
: mappedUrl;
|
|
125
127
|
const links = Object.values(this.allNavLinks);
|
|
126
128
|
bestMatch = links.find(link => link.href.includes(clientSpecificUrl));
|
|
127
|
-
console.log({ mappedUrl, clientSpecificUrl, bestMatch });
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
|
|
@@ -392,26 +393,26 @@ export class TtNavbar extends LitElement {
|
|
|
392
393
|
${
|
|
393
394
|
this.clients.length > 1
|
|
394
395
|
? html`
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
396
|
+
<tt-combobox
|
|
397
|
+
.openUpward=${true}
|
|
398
|
+
.value=${this.clientKey ? [this.clientKey] : []}
|
|
399
|
+
@change=${this.handleClientChange}
|
|
400
|
+
>
|
|
401
|
+
${this.clients.map(
|
|
402
|
+
client => html`
|
|
403
|
+
<option slot="option" value=${client.clientKey}>
|
|
404
|
+
${client.displayName}
|
|
405
|
+
</option>
|
|
406
|
+
`,
|
|
407
|
+
)}
|
|
408
|
+
</tt-combobox>
|
|
409
|
+
`
|
|
409
410
|
: html`
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
411
|
+
<div class="single-client-name">
|
|
412
|
+
${this.clients.find(m => m.clientKey === this.clientKey)
|
|
413
|
+
?.displayName}
|
|
414
|
+
</div>
|
|
415
|
+
`
|
|
415
416
|
}
|
|
416
417
|
</div>
|
|
417
418
|
<a
|
package/test/tt-navbar.test.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
nextFrame,
|
|
8
8
|
waitUntil,
|
|
9
9
|
} from '@open-wc/testing';
|
|
10
|
+
import { Resources } from '@clerk/types';
|
|
10
11
|
import { TtNavbar } from '../src/index.js';
|
|
11
12
|
import { Routes } from '../src/Routes.js';
|
|
12
13
|
|
|
@@ -412,10 +413,17 @@ describe('TtNavbar', () => {
|
|
|
412
413
|
});
|
|
413
414
|
|
|
414
415
|
it('should default to state stored in Clerk when set', async () => {
|
|
416
|
+
const mockUser = {
|
|
417
|
+
unsafeMetadata: { preferences: { ui: { navigationOpen: false } } },
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const mockAddListener = (func: (resources: Resources) => void) => {
|
|
421
|
+
func({ user: mockUser } as unknown as Resources);
|
|
422
|
+
};
|
|
423
|
+
|
|
415
424
|
window.Clerk = {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
},
|
|
425
|
+
addListener: mockAddListener,
|
|
426
|
+
user: mockUser,
|
|
419
427
|
} as Clerk;
|
|
420
428
|
|
|
421
429
|
const navbar = await fixture<TtNavbar>(
|
|
@@ -439,17 +447,24 @@ describe('TtNavbar', () => {
|
|
|
439
447
|
calledWith = args;
|
|
440
448
|
};
|
|
441
449
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
ui: { duck: 'duck', navigationOpen: false },
|
|
450
|
-
},
|
|
450
|
+
const mockUser = {
|
|
451
|
+
update: mockUpdate,
|
|
452
|
+
unsafeMetadata: {
|
|
453
|
+
foo: 'foo',
|
|
454
|
+
preferences: {
|
|
455
|
+
bar: 'bar',
|
|
456
|
+
ui: { duck: 'duck', navigationOpen: false },
|
|
451
457
|
},
|
|
452
458
|
},
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const mockAddListener = (func: (resources: Resources) => void) => {
|
|
462
|
+
func({ user: mockUser } as unknown as Resources);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
window.Clerk = {
|
|
466
|
+
addListener: mockAddListener,
|
|
467
|
+
user: mockUser,
|
|
453
468
|
} as unknown as Clerk;
|
|
454
469
|
|
|
455
470
|
const navbar = await fixture<TtNavbar>(
|
|
@@ -461,6 +476,7 @@ describe('TtNavbar', () => {
|
|
|
461
476
|
) as HTMLButtonElement;
|
|
462
477
|
|
|
463
478
|
navbarToggleBtn.click();
|
|
479
|
+
await elementUpdated(navbar);
|
|
464
480
|
|
|
465
481
|
await expect(timesCalled).to.equal(1);
|
|
466
482
|
expect(calledWith).to.deep.equal({
|