-
Notifications
You must be signed in to change notification settings - Fork 103
/
actions.js
57 lines (47 loc) · 1.65 KB
/
actions.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
45
46
47
48
49
50
51
52
53
54
55
56
57
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {id as pluginId} from './manifest';
import {STATUS_CHANGE, OPEN_ROOT_MODAL, CLOSE_ROOT_MODAL, SUBMENU} from './action_types';
export const openRootModal = (subMenuText = '') => (dispatch) => {
dispatch({
type: SUBMENU,
subMenu: subMenuText,
});
dispatch({
type: OPEN_ROOT_MODAL,
});
};
export const closeRootModal = () => (dispatch) => {
dispatch({
type: CLOSE_ROOT_MODAL,
});
};
export const mainMenuAction = openRootModal;
export const fileUploadMethodAction = openRootModal;
export const postDropdownMenuAction = openRootModal;
export const postDropdownSubMenuAction = openRootModal;
export const channelHeaderMenuAction = openRootModal;
export const fileDropdownMenuAction = openRootModal;
// TODO: Move this into mattermost-redux or mattermost-webapp.
export const getPluginServerRoute = (state) => {
const config = getConfig(state);
let basePath = '/';
if (config && config.SiteURL) {
basePath = new URL(config.SiteURL).pathname;
if (basePath && basePath[basePath.length - 1] === '/') {
basePath = basePath.substr(0, basePath.length - 1);
}
}
return basePath + '/plugins/' + pluginId;
};
export const getStatus = () => async (dispatch, getState) => {
fetch(getPluginServerRoute(getState()) + '/status').then((r) => r.json()).then((r) => {
dispatch({
type: STATUS_CHANGE,
data: r.enabled,
});
});
};
export const websocketStatusChange = (message) => (dispatch) => dispatch({
type: STATUS_CHANGE,
data: message.data.enabled,
});