forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive_dialog.js
44 lines (34 loc) · 1.59 KB
/
interactive_dialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {
IntegrationTypes,
} from 'mattermost-redux/action_types';
import {openModal} from 'actions/views/modals';
import {ModalIdentifiers} from 'utils/constants.jsx';
import InteractiveDialog from 'components/interactive_dialog';
import store from '../stores/redux_store';
export function openInteractiveDialog(dialog) {
store.dispatch({type: IntegrationTypes.RECEIVED_DIALOG, data: dialog});
store.dispatch(openModal({modalId: ModalIdentifiers.INTERACTIVE_DIALOG, dialogType: InteractiveDialog}));
}
// This code is problematic for a couple of different reasons:
// * it monitors the store to modify the store: this is perhaps better handled by a saga
// * it makes importing this file impure by triggering a side-effect which may not be obvious
// * it's not really located in the "right place": dialogs are applicable to non-plugins too
// * it's nigh impossible to test as written
//
// It's worth fixing all of this, but I think this requires some refactoring.
let previousTriggerId = '';
store.subscribe(() => {
const state = store.getState();
const currentTriggerId = state.entities.integrations.dialogTriggerId;
if (currentTriggerId === previousTriggerId) {
return;
}
previousTriggerId = currentTriggerId;
const dialog = state.entities.integrations.dialog || {};
if (dialog.trigger_id !== currentTriggerId) {
return;
}
store.dispatch(openModal({modalId: ModalIdentifiers.INTERACTIVE_DIALOG, dialogType: InteractiveDialog}));
});