@salesforcedevs/dx-components 1.2.2-avatar-button-3 → 1.2.2-avatar-button-4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.2.2-avatar-button-3",
3
+ "version": "1.2.2-avatar-button-4",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -73,8 +73,9 @@ export default class AvatarButton extends LightningElement {
73
73
  private isLoading = false;
74
74
  private settingsUrl = TBID_SETTINGS_URL;
75
75
  private profileUrl = TBID_PROFILE_URL;
76
- private _didReceiveUserInfo = false;
77
76
  private eventSource?: EventSource;
77
+ private _hasRendered = false;
78
+ private _didReceiveUserInfo = false;
78
79
 
79
80
  private get loginUrl() {
80
81
  return `${TBID_API_LOGIN_URL}?startURL=${encodeURIComponent(
@@ -90,14 +91,31 @@ export default class AvatarButton extends LightningElement {
90
91
  const searchParams = new URLSearchParams(window.location.search);
91
92
 
92
93
  if (searchParams.get("loginSuccess") === "true") {
93
- // clear the query param
94
94
  this.isLoading = true;
95
+ // clear the query param
95
96
  searchParams.delete("loginSuccess");
96
- window.location.search = searchParams.toString();
97
+ window.history.replaceState(
98
+ null,
99
+ "",
100
+ `${window.location.pathname}${
101
+ window.location.hash
102
+ }${searchParams.toString()}`
103
+ );
97
104
  }
98
105
 
99
106
  window.addEventListener("tbid-login", this.handleSsoLogin);
100
107
  window.addEventListener("tbid-logout", this.handleSsoLogout);
108
+ }
109
+
110
+ disconnectedCallback() {
111
+ window.removeEventListener("tbid-login", this.handleSsoLogin);
112
+ window.removeEventListener("tbid-logout", this.handleSsoLogout);
113
+ }
114
+
115
+ renderedCallback() {
116
+ if (this._hasRendered) {
117
+ return;
118
+ }
101
119
 
102
120
  const isWidgetDisabled = window.SFIDWidget?.disabled;
103
121
  const isWidgetLoggedIn = window.SFIDWidget?.openid_response;
@@ -118,28 +136,18 @@ export default class AvatarButton extends LightningElement {
118
136
  this.platformEventsSubscribe();
119
137
  this.requestUserInfo();
120
138
  }
121
- }, 3000);
139
+ }, 1000);
122
140
  } else {
123
141
  if (this.isLoading) {
124
- console.log('Subscribing to platform events!');
125
142
  // This was a login.
126
- setTimeout(() => this.platformEventsSubscribe(), 3000);
143
+ console.log("Subscribing to platform events!");
144
+ this.platformEventsSubscribe();
127
145
  // this.trackLogin(); TODO: track only clicks
128
146
  }
129
147
  this.requestUserInfo();
130
148
  }
131
149
  }
132
150
 
133
- renderedCallback() {
134
- // TESTING
135
- this.template.querySelector('img.avatar')?.addEventListener('click', this.platformEventsSubscribe);
136
- }
137
-
138
- disconnectedCallback() {
139
- window.removeEventListener("tbid-login", this.handleSsoLogin);
140
- window.removeEventListener("tbid-logout", this.handleSsoLogout);
141
- }
142
-
143
151
  private handleUserDataChange = ({ data }: EventSourceEvent) => {
144
152
  let parsedEventData: any;
145
153
 
@@ -198,7 +206,7 @@ export default class AvatarButton extends LightningElement {
198
206
  };
199
207
 
200
208
  private platformEventsSubscribe = () => {
201
- console.log('platform events subscribe');
209
+ console.log("platform events subscribe");
202
210
  this.teardownEventSource();
203
211
  this.setupEventSource();
204
212
  };