From 493c329a657abfe6f97c2c9285df5c56bef1763e Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Sun, 8 Aug 2021 23:17:25 -0300 Subject: [PATCH] reset hook --- src/lib/hooks.js | 4 ++++ src/store/Store.js | 12 ++++++++++-- src/widget.js | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/lib/hooks.js b/src/lib/hooks.js index 036ee645c..654323734 100644 --- a/src/lib/hooks.js +++ b/src/lib/hooks.js @@ -151,6 +151,10 @@ const api = { store.setState({ minimized: false }); parentCall('openWidget'); }, + + reset() { + store.resetState(); + } }; const onNewMessage = (event) => { diff --git a/src/store/Store.js b/src/store/Store.js index bb8ac8664..c3533773b 100644 --- a/src/store/Store.js +++ b/src/store/Store.js @@ -1,6 +1,7 @@ +import { route } from 'preact-router'; import mitt from 'mitt'; - import { parentCall } from '../lib/parentCall'; +import { loadConfig } from '../lib/main'; const { localStorage, sessionStorage } = window; @@ -21,7 +22,8 @@ export default class Store { storedState = typeof storedState === 'object' ? storedState : {}; } - this._state = { ...initialState, ...storedState }; + this._initialState = initialState; + this._state = { ...initialState, ...storedState }; window.addEventListener('storage', (e) => { // Cross-tab communication @@ -87,4 +89,10 @@ export default class Store { this._state = { ...storedState, ...nonPeristable }; this.emit('change', [this._state, prevState]); } + + resetState() { + this._state = this._initialState; + loadConfig(); + route(''); + } } diff --git a/src/widget.js b/src/widget.js index d1286107c..6b44abe6c 100644 --- a/src/widget.js +++ b/src/widget.js @@ -299,6 +299,10 @@ function minimizeWidget() { callHook('minimizeWidget'); } +function reset() { + callHook('reset'); +} + function initialize(params) { for (const method in params) { if (!params.hasOwnProperty(method)) { @@ -428,6 +432,7 @@ window.RocketChat.livechat = { hideWidget, maximizeWidget, minimizeWidget, + reset, // callbacks onChatMaximized(fn) { registerCallback('chat-maximized', fn); },