-
Notifications
You must be signed in to change notification settings - Fork 230
Reset hook to clear internal state and go back to a first loaded state #628
base: develop
Are you sure you want to change the base?
Conversation
It was hard to really reset state, so I am simply clearing the localstorage and redirecting the iframe. Also provide a way to reset it on initialization through a querystring
now that #640 got merged I wonder if this one can also be looked at? |
} catch (e) { | ||
storedState = {}; | ||
} finally { | ||
storedState = typeof storedState === 'object' ? storedState : {}; | ||
} | ||
|
||
this._state = { ...initialState, ...storedState }; | ||
this._initialState = initialState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for this new variable assignment?
Hi @hanoii Thanks for the contribution 😄 We recently introduced a similar feature that automatically resets the local storage when a chat gets closed #666. There instead of clearing the local storage (which you're proposing to do on the reset() method), we instead create a new visitor. So I was wondering if we could do something similar here as well... WDYT? |
@@ -47,7 +53,7 @@ export default class Store { | |||
}); | |||
|
|||
window.addEventListener('visibilitychange', () => { | |||
!this._state.minimized && !this._state.triggered && parentCall('openWidget'); | |||
!this._state.minimized && parentCall('openWidget'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I didn't get this change. Why are we not checking for the triggered
property now? Could you please elaborate on the logic here?
This attempts to add support for #625.
This one was rather hard, as resetting it when the page was loaded caused a lot of different issues, so I provide two ways fo resetting the state, a query string so that it. can be reset that takes an approach of redirecting so everything is loaded again. Depending on the usecase both will work but the latter might have an undesired flicker, that's why I added the query string way.
Fixes #625