Skip to content

Commit edd4c0a

Browse files
Change exposed function names, add isOpen and isVisible exposed functions
1 parent 8b5eeed commit edd4c0a

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import { Widget, toggleWidget, openWidget, closeWidget, showWidget, hideWidget } from './index_for_react_app';
3+
import { Widget, toggleWidget, openWidget, closeWidget, showWidget, hideWidget, isOpen, isVisible } from './index_for_react_app';
44

55
const plugin = {
66
init: (args) => {
@@ -21,18 +21,19 @@ const plugin = {
2121
badge={args.badge}
2222
params={args.params}
2323
/>, document.querySelector(args.selector)
24-
2524
);
2625
}
2726
};
2827

2928
export {
3029
plugin as default,
3130
Widget,
32-
toggleWidget,
33-
openWidget,
34-
closeWidget,
35-
showWidget,
36-
hideWidget
31+
toggleWidget as toggle,
32+
openWidget as open,
33+
closeWidget as close,
34+
showWidget as show,
35+
hideWidget as hide,
36+
isOpen,
37+
isVisible
3738
};
3839

index_for_react_app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
addImageSnippet,
88
addQuickReply,
99
renderCustomComponent,
10+
isOpen,
11+
isVisible,
1012
showWidget,
1113
hideWidget,
1214
toggleWidget,
@@ -25,6 +27,8 @@ export {
2527
addImageSnippet,
2628
addQuickReply,
2729
renderCustomComponent,
30+
isOpen,
31+
isVisible,
2832
showWidget,
2933
hideWidget,
3034
toggleWidget,

src/store/actions/actionTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export const INITIALIZE = 'INITIALIZE';
2+
export const GET_OPEN_STATE = 'GET_OPEN_STATE';
3+
export const GET_VISIBLE_STATE = 'GET_VISIBLE_STATE';
24
export const SHOW_WIDGET = 'SHOW_WIDGET';
35
export const HIDE_WIDGET = 'HIDE_WIDGET';
46
export const TOGGLE_CHAT = 'TOGGLE_CHAT';

src/store/actions/dispatcher.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { store } from '../store';
22
import * as actions from './index';
33

4+
export function isOpen() {
5+
return store.dispatch(actions.getOpenState());
6+
}
7+
8+
export function isVisible() {
9+
return store.dispatch(actions.getVisibleState());
10+
}
11+
412
export function initialize() {
513
store.dispatch(actions.initialize());
614
}

src/store/actions/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ export function initialize() {
66
};
77
}
88

9+
export function getOpenState() {
10+
return {
11+
type: actions.GET_OPEN_STATE
12+
};
13+
}
14+
15+
export function getVisibleState() {
16+
return {
17+
type: actions.GET_VISIBLE_STATE
18+
};
19+
}
20+
921
export function showWidget() {
1022
return {
1123
type: actions.SHOW_WIDGET

src/store/store.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@ import { createStore, combineReducers, applyMiddleware } from "redux";
22

33
import behavior from "./reducers/behaviorReducer";
44
import messages from "./reducers/messagesReducer";
5+
import * as actionTypes from './actions/actionTypes';
56

67
let store = "call initStore first";
78

89
function initStore(hint, socket) {
910
const customMiddleWare = (store) => next => (action) => {
10-
if (action.type === "EMIT_NEW_USER_MESSAGE") {
11-
socket.emit("user_uttered", { message: action.text, customData: socket.customData });
11+
switch (action.type) {
12+
case actionTypes.EMIT_NEW_USER_MESSAGE: {
13+
socket.emit("user_uttered", { message: action.text, customData: socket.customData });
14+
}
15+
case actionTypes.GET_OPEN_STATE: {
16+
return store.getState().behavior.get("showChat");
17+
}
18+
case actionTypes.GET_VISIBLE_STATE: {
19+
return store.getState().behavior.get("showWidget");
20+
}
1221
}
22+
1323
// console.log('Middleware triggered:', action);
1424
next(action);
1525
};

0 commit comments

Comments
 (0)