@salesforcedevs/dx-components 1.2.2-avatar-button-3 → 1.2.2-avatar-button-5
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
|
@@ -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,10 +91,16 @@ 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.
|
|
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);
|
|
@@ -115,29 +122,22 @@ export default class AvatarButton extends LightningElement {
|
|
|
115
122
|
setTimeout(() => {
|
|
116
123
|
if (!window.SFIDWidget?.openid_response) {
|
|
117
124
|
// this.trackLogin(); TODO: track only clicks
|
|
118
|
-
this.platformEventsSubscribe();
|
|
119
125
|
this.requestUserInfo();
|
|
120
126
|
}
|
|
121
|
-
},
|
|
127
|
+
}, 1000);
|
|
122
128
|
} else {
|
|
123
129
|
if (this.isLoading) {
|
|
124
|
-
console.log('Subscribing to platform events!');
|
|
125
130
|
// This was a login.
|
|
126
|
-
setTimeout(() => this.platformEventsSubscribe(), 3000);
|
|
127
131
|
// this.trackLogin(); TODO: track only clicks
|
|
128
132
|
}
|
|
129
133
|
this.requestUserInfo();
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
|
|
133
|
-
renderedCallback() {
|
|
134
|
-
// TESTING
|
|
135
|
-
this.template.querySelector('img.avatar')?.addEventListener('click', this.platformEventsSubscribe);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
137
|
disconnectedCallback() {
|
|
139
138
|
window.removeEventListener("tbid-login", this.handleSsoLogin);
|
|
140
139
|
window.removeEventListener("tbid-logout", this.handleSsoLogout);
|
|
140
|
+
this.teardownEventSource();
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
private handleUserDataChange = ({ data }: EventSourceEvent) => {
|
|
@@ -198,7 +198,6 @@ export default class AvatarButton extends LightningElement {
|
|
|
198
198
|
};
|
|
199
199
|
|
|
200
200
|
private platformEventsSubscribe = () => {
|
|
201
|
-
console.log('platform events subscribe');
|
|
202
201
|
this.teardownEventSource();
|
|
203
202
|
this.setupEventSource();
|
|
204
203
|
};
|
|
@@ -340,6 +339,9 @@ export default class AvatarButton extends LightningElement {
|
|
|
340
339
|
const userInfoRes = await fetch(TBID_API_USERINFO_URL);
|
|
341
340
|
|
|
342
341
|
if (userInfoRes.ok) {
|
|
342
|
+
if (!this.eventSource) {
|
|
343
|
+
this.setupEventSource();
|
|
344
|
+
}
|
|
343
345
|
const userInfo = await userInfoRes.json();
|
|
344
346
|
this.updateAvatarWithUserInfo(userInfo);
|
|
345
347
|
this._didReceiveUserInfo = true;
|