@triptease/tt-navbar 0.0.40 → 0.0.41

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @triptease/tt-navbar v0.0.40
2
+ * @triptease/tt-navbar v0.0.41
3
3
  */
4
4
 
5
5
  // src/urlMappings.ts
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.40",
6
+ "version": "0.0.41",
7
7
  "type": "module",
8
8
  "main": "dist/src/index.js",
9
9
  "module": "dist/src/index.js",
@@ -5,6 +5,8 @@ export class NavbarController implements ReactiveController {
5
5
 
6
6
  private _isOpen = true;
7
7
 
8
+ private _hasInitialized = false;
9
+
8
10
  constructor(host: ReactiveControllerHost) {
9
11
  (this.host = host).addController(this);
10
12
  }
@@ -13,21 +15,21 @@ export class NavbarController implements ReactiveController {
13
15
  return this._isOpen;
14
16
  }
15
17
 
16
- hostConnected() {
17
- if (window.Clerk) {
18
+ hostUpdate() {
19
+ if (!this._hasInitialized && window.Clerk) {
18
20
  const userSetting =
19
21
  window.Clerk.user?.unsafeMetadata?.preferences?.ui?.navigationOpen;
20
22
 
21
23
  if (userSetting !== undefined) {
22
24
  this._isOpen = userSetting;
25
+ this._hasInitialized = true;
23
26
  this.host.requestUpdate();
24
27
  }
25
28
  }
26
29
  }
27
30
 
28
31
  async toggle() {
29
- const newState = !this._isOpen;
30
- this._isOpen = newState;
32
+ this._isOpen = !this._isOpen;
31
33
 
32
34
  if (window.Clerk) {
33
35
  await window.Clerk.user?.update({
@@ -37,7 +39,7 @@ export class NavbarController implements ReactiveController {
37
39
  ...window.Clerk.user?.unsafeMetadata?.preferences,
38
40
  ui: {
39
41
  ...window.Clerk.user?.unsafeMetadata?.preferences?.ui,
40
- navigationOpen: newState,
42
+ navigationOpen: this.isOpen,
41
43
  },
42
44
  },
43
45
  },
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') ? mappedUrl.replace('$CLIENT_KEY', this.clientKey) : mappedUrl;
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
- <tt-combobox
396
- .openUpward=${true}
397
- .value=${this.clientKey ? [this.clientKey] : []}
398
- @change=${this.handleClientChange}
399
- >
400
- ${this.clients.map(
401
- client => html`
402
- <option slot="option" value=${client.clientKey}>
403
- ${client.displayName}
404
- </option>
405
- `
406
- )}
407
- </tt-combobox>
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
- <div class="single-client-name">
411
- ${this.clients.find(m => m.clientKey === this.clientKey)
412
- ?.displayName}
413
- </div>
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
@@ -461,6 +461,7 @@ describe('TtNavbar', () => {
461
461
  ) as HTMLButtonElement;
462
462
 
463
463
  navbarToggleBtn.click();
464
+ await elementUpdated(navbar);
464
465
 
465
466
  await expect(timesCalled).to.equal(1);
466
467
  expect(calledWith).to.deep.equal({