@salesforcedevs/docs-components 0.0.31-chat → 0.0.32-chat

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/docs-components",
3
- "version": "0.0.31-chat",
3
+ "version": "0.0.32-chat",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -53,8 +53,9 @@ export default class Chat extends LightningElement {
53
53
  private _isOpen: boolean = false;
54
54
  private messageIdCounter: number = 0;
55
55
 
56
- // localStorage key for persisting messages
56
+ // localStorage keys for persisting messages and open state
57
57
  private static readonly STORAGE_KEY = 'doc-chat-messages';
58
+ private static readonly OPEN_STATE_KEY = 'doc-chat-should-open';
58
59
 
59
60
  connectedCallback() {
60
61
  // Load existing messages from localStorage
@@ -65,6 +66,9 @@ export default class Chat extends LightningElement {
65
66
  this.addMessage("Hello! How can I help you today?", "assistant");
66
67
  }
67
68
 
69
+ // Check if chat should be opened after reload
70
+ this.checkAndOpenAfterReload();
71
+
68
72
  // Ensure body has proper class state
69
73
  this.updateBodyClass();
70
74
  }
@@ -188,6 +192,26 @@ export default class Chat extends LightningElement {
188
192
  }
189
193
  }
190
194
 
195
+ private checkAndOpenAfterReload() {
196
+ try {
197
+ const shouldOpen = localStorage.getItem(Chat.OPEN_STATE_KEY);
198
+ if (shouldOpen === 'true') {
199
+ // Clear the flag
200
+ localStorage.removeItem(Chat.OPEN_STATE_KEY);
201
+ // Open the chat
202
+ this.isOpen = true;
203
+ this.updateBodyClass();
204
+
205
+ // Dispatch custom event to notify parent components
206
+ this.dispatchEvent(new CustomEvent('chatopened', {
207
+ detail: { opened: true }
208
+ }));
209
+ }
210
+ } catch (error) {
211
+ console.warn('Failed to check open state from localStorage:', error);
212
+ }
213
+ }
214
+
191
215
  handleInputChange(event: Event) {
192
216
  const target = event.target as HTMLInputElement;
193
217
  this.currentMessage = target.value;
@@ -275,23 +299,27 @@ export default class Chat extends LightningElement {
275
299
  }
276
300
 
277
301
  handleOpenClick() {
278
- this.isOpen = true;
279
- this.updateBodyClass();
302
+ try {
303
+ // Set flag to open chat after reload
304
+ localStorage.setItem(Chat.OPEN_STATE_KEY, 'true');
305
+ } catch (error) {
306
+ console.warn('Failed to set open state in localStorage:', error);
307
+ }
280
308
 
281
- // Dispatch custom event to notify parent components
282
- this.dispatchEvent(new CustomEvent('chatopened', {
283
- detail: { opened: true }
284
- }));
309
+ // Hard reload the page to clear cache when opening chat
310
+ window.location.reload();
285
311
  }
286
312
 
287
313
  openChat() {
288
- this.isOpen = true;
289
- this.updateBodyClass();
314
+ try {
315
+ // Set flag to open chat after reload
316
+ localStorage.setItem(Chat.OPEN_STATE_KEY, 'true');
317
+ } catch (error) {
318
+ console.warn('Failed to set open state in localStorage:', error);
319
+ }
290
320
 
291
- // Dispatch custom event to notify parent components
292
- this.dispatchEvent(new CustomEvent('chatopened', {
293
- detail: { opened: true }
294
- }));
321
+ // Hard reload the page to clear cache when opening chat
322
+ window.location.reload();
295
323
  }
296
324
 
297
325
  closeChat() {