@salesforcedevs/docs-components
Advanced tools
Comparing version
{ | ||
"name": "@salesforcedevs/docs-components", | ||
"version": "0.0.31-chat", | ||
"version": "0.0.32-chat", | ||
"description": "Docs Lightning web components for DSC", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -56,4 +56,5 @@ import { LightningElement, api, track } from "lwc"; | ||
// localStorage key for persisting messages | ||
// localStorage keys for persisting messages and open state | ||
private static readonly STORAGE_KEY = 'doc-chat-messages'; | ||
private static readonly OPEN_STATE_KEY = 'doc-chat-should-open'; | ||
@@ -69,2 +70,5 @@ connectedCallback() { | ||
// Check if chat should be opened after reload | ||
this.checkAndOpenAfterReload(); | ||
// Ensure body has proper class state | ||
@@ -193,2 +197,22 @@ this.updateBodyClass(); | ||
private checkAndOpenAfterReload() { | ||
try { | ||
const shouldOpen = localStorage.getItem(Chat.OPEN_STATE_KEY); | ||
if (shouldOpen === 'true') { | ||
// Clear the flag | ||
localStorage.removeItem(Chat.OPEN_STATE_KEY); | ||
// Open the chat | ||
this.isOpen = true; | ||
this.updateBodyClass(); | ||
// Dispatch custom event to notify parent components | ||
this.dispatchEvent(new CustomEvent('chatopened', { | ||
detail: { opened: true } | ||
})); | ||
} | ||
} catch (error) { | ||
console.warn('Failed to check open state from localStorage:', error); | ||
} | ||
} | ||
handleInputChange(event: Event) { | ||
@@ -281,19 +305,23 @@ const target = event.target as HTMLInputElement; | ||
handleOpenClick() { | ||
this.isOpen = true; | ||
this.updateBodyClass(); | ||
try { | ||
// Set flag to open chat after reload | ||
localStorage.setItem(Chat.OPEN_STATE_KEY, 'true'); | ||
} catch (error) { | ||
console.warn('Failed to set open state in localStorage:', error); | ||
} | ||
// Dispatch custom event to notify parent components | ||
this.dispatchEvent(new CustomEvent('chatopened', { | ||
detail: { opened: true } | ||
})); | ||
// Hard reload the page to clear cache when opening chat | ||
window.location.reload(); | ||
} | ||
openChat() { | ||
this.isOpen = true; | ||
this.updateBodyClass(); | ||
try { | ||
// Set flag to open chat after reload | ||
localStorage.setItem(Chat.OPEN_STATE_KEY, 'true'); | ||
} catch (error) { | ||
console.warn('Failed to set open state in localStorage:', error); | ||
} | ||
// Dispatch custom event to notify parent components | ||
this.dispatchEvent(new CustomEvent('chatopened', { | ||
detail: { opened: true } | ||
})); | ||
// Hard reload the page to clear cache when opening chat | ||
window.location.reload(); | ||
} | ||
@@ -300,0 +328,0 @@ |
309232
0.37%7635
0.33%75
4.17%