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

Commit

Permalink
reset hook
Browse files Browse the repository at this point in the history
  • Loading branch information
hanoii committed Aug 22, 2021
1 parent 0ae132a commit 2c7fabd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ const api = {
store.setState({ minimized: false });
parentCall('openWidget');
},

reset() {
store.resetState();
}
};

const onNewMessage = (event) => {
Expand Down
12 changes: 10 additions & 2 deletions src/store/Store.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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('');
}
}
5 changes: 5 additions & 0 deletions src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ function minimizeWidget() {
callHook('minimizeWidget');
}

function reset() {
callHook('reset');
}

function initialize(params) {
for (const method in params) {
if (!params.hasOwnProperty(method)) {
Expand Down Expand Up @@ -439,6 +443,7 @@ window.RocketChat.livechat = {
hideWidget,
maximizeWidget,
minimizeWidget,
reset,

// callbacks
onChatMaximized(fn) { registerCallback('chat-maximized', fn); },
Expand Down

0 comments on commit 2c7fabd

Please sign in to comment.