Skip to content

Commit da38600

Browse files
committed
save the open/close state of the webchat in local storage
1 parent 827a46e commit da38600

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

dist/hellotext.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/controllers/webchat_controller.js

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var _hellotext = _interopRequireDefault(require("../hellotext"));
1212
var _webchat = require("../core/configuration/webchat");
1313
var _usePopover = require("./mixins/usePopover");
1414
var _logo_builder = require("../builders/logo_builder");
15+
var _locales = _interopRequireDefault(require("../locales"));
1516
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1617
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1718
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -71,6 +72,9 @@ var _default = /*#__PURE__*/function (_Controller) {
7172
if (!_hellotext.default.business.features.white_label) {
7273
this.toolbarTarget.appendChild(_logo_builder.LogoBuilder.build());
7374
}
75+
if (localStorage.getItem("hellotext--webchat--".concat(this.idValue)) === 'opened') {
76+
this.openValue = true;
77+
}
7478
_get(_getPrototypeOf(_default.prototype), "connect", this).call(this);
7579
}
7680
}, {
@@ -154,6 +158,7 @@ var _default = /*#__PURE__*/function (_Controller) {
154158
this.scrolled = true;
155159
}
156160
_hellotext.default.eventEmitter.dispatch('webchat:opened');
161+
localStorage.setItem("hellotext--webchat--".concat(this.idValue), 'opened');
157162
}
158163
}, {
159164
key: "onPopoverClosed",
@@ -162,6 +167,7 @@ var _default = /*#__PURE__*/function (_Controller) {
162167
setTimeout(() => {
163168
this.inputTarget.value = "";
164169
});
170+
localStorage.setItem("hellotext--webchat--".concat(this.idValue), 'closed');
165171
}
166172
}, {
167173
key: "onMessageReaction",

src/controllers/webchat_controller.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Webchat as WebchatConfiguration, behaviors } from '../core/configuratio
99

1010
import { usePopover } from './mixins/usePopover'
1111
import { LogoBuilder } from '../builders/logo_builder'
12+
import locales from "../locales";
1213

1314
export default class extends Controller {
1415
static values = {
@@ -80,6 +81,10 @@ export default class extends Controller {
8081
this.toolbarTarget.appendChild(LogoBuilder.build())
8182
}
8283

84+
if(localStorage.getItem(`hellotext--webchat--${this.idValue}`) === 'opened') {
85+
this.openValue = true
86+
}
87+
8388
super.connect()
8489
}
8590

@@ -164,6 +169,8 @@ export default class extends Controller {
164169
}
165170

166171
Hellotext.eventEmitter.dispatch('webchat:opened')
172+
173+
localStorage.setItem(`hellotext--webchat--${this.idValue}`, 'opened')
167174
}
168175

169176
onPopoverClosed() {
@@ -172,6 +179,8 @@ export default class extends Controller {
172179
setTimeout(() => {
173180
this.inputTarget.value = ""
174181
})
182+
183+
localStorage.setItem(`hellotext--webchat--${this.idValue}`, 'closed')
175184
}
176185

177186
onMessageReaction(message) {

0 commit comments

Comments
 (0)