forked from mattermost/mattermost-plugin-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.jsx
115 lines (97 loc) · 3.34 KB
/
plugin.jsx
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import React from 'react';
import {FormattedMessage} from 'react-intl';
import en from 'i18n/en.json';
import es from 'i18n/es.json';
import {id as pluginId} from './manifest';
import Root from './components/root';
import BottomTeamSidebar from './components/bottom_team_sidebar';
import LeftSidebarHeader from './components/left_sidebar_header';
import LinkTooltip from './components/link_tooltip';
import UserAttributes from './components/user_attributes';
import UserActions from './components/user_actions';
import PostType from './components/post_type';
import {
MainMenuMobileIcon,
ChannelHeaderButtonIcon,
FileUploadMethodIcon,
} from './components/icons';
import {
mainMenuAction,
channelHeaderButtonAction,
fileUploadMethodAction,
postDropdownMenuAction,
websocketStatusChange,
getStatus,
} from './actions';
import reducer from './reducer';
function getTranslations(locale) {
switch (locale) {
case 'en':
return en;
case 'es':
return es;
}
return {};
}
export default class DemoPlugin {
initialize(registry, store) {
registry.registerRootComponent(Root);
registry.registerPopoverUserAttributesComponent(UserAttributes);
registry.registerPopoverUserActionsComponent(UserActions);
registry.registerLeftSidebarHeaderComponent(LeftSidebarHeader);
registry.registerLinkTooltipComponent(LinkTooltip);
registry.registerBottomTeamSidebarComponent(
BottomTeamSidebar,
);
registry.registerChannelHeaderButtonAction(
<ChannelHeaderButtonIcon/>,
() => store.dispatch(channelHeaderButtonAction()),
<FormattedMessage
id='plugin.name'
defaultMessage='Demo Plugin'
/>,
);
registry.registerPostTypeComponent('custom_demo_plugin', PostType);
registry.registerMainMenuAction(
<FormattedMessage
id='plugin.name'
defaultMessage='Demo Plugin'
/>,
() => store.dispatch(mainMenuAction()),
<MainMenuMobileIcon/>,
);
registry.registerPostDropdownMenuAction(
<FormattedMessage
id='plugin.name'
defaultMessage='Demo Plugin'
/>,
() => store.dispatch(postDropdownMenuAction()),
);
registry.registerFileUploadMethod(
<FileUploadMethodIcon/>,
() => store.dispatch(fileUploadMethodAction()),
<FormattedMessage
id='plugin.upload'
defaultMessage='Upload using Demo Plugin'
/>,
);
registry.registerWebSocketEventHandler(
'custom_' + pluginId + '_status_change',
(message) => {
store.dispatch(websocketStatusChange(message));
},
);
registry.registerReducer(reducer);
// Immediately fetch the current plugin status.
store.dispatch(getStatus());
// Fetch the current status whenever we recover an internet connection.
registry.registerReconnectHandler(() => {
store.dispatch(getStatus());
});
registry.registerTranslations(getTranslations);
}
uninitialize() {
//eslint-disable-next-line no-console
console.log(pluginId + '::uninitialize()');
}
}