Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Reset hook to clear internal state and go back to a first loaded state #628

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

hanoii
Copy link
Contributor

@hanoii hanoii commented Aug 9, 2021

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

hanoii added 2 commits August 22, 2021 18:08
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
@hanoii
Copy link
Contributor Author

hanoii commented Dec 10, 2021

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;
Copy link
Contributor

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?

@murtaza98
Copy link
Contributor

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');
Copy link
Contributor

@murtaza98 murtaza98 Dec 13, 2021

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?

@renatobecker
Copy link
Contributor

@hanoii have you looked at #666 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logout/destroy widget
3 participants