|
@@ -13,7 +13,8 @@ import CommentContainer from '~/client/services/CommentContainer';
|
|
|
import EditorContainer from '~/client/services/EditorContainer';
|
|
import EditorContainer from '~/client/services/EditorContainer';
|
|
|
import PageContainer from '~/client/services/PageContainer';
|
|
import PageContainer from '~/client/services/PageContainer';
|
|
|
import GrowiRenderer from '~/client/util/GrowiRenderer';
|
|
import GrowiRenderer from '~/client/util/GrowiRenderer';
|
|
|
-import { useCurrentUser } from '~/stores/context';
|
|
|
|
|
|
|
+import { useCurrentPagePath, useCurrentUser } from '~/stores/context';
|
|
|
|
|
+import { useSWRxSlackChannels, useIsSlackEnabled } from '~/stores/editor';
|
|
|
import { useIsMobile } from '~/stores/ui';
|
|
import { useIsMobile } from '~/stores/ui';
|
|
|
|
|
|
|
|
import { CustomNavTab } from '../CustomNavigation/CustomNav';
|
|
import { CustomNavTab } from '../CustomNavigation/CustomNav';
|
|
@@ -64,6 +65,7 @@ class CommentEditor extends React.Component {
|
|
|
isUploadableFile,
|
|
isUploadableFile,
|
|
|
errorMessage: undefined,
|
|
errorMessage: undefined,
|
|
|
isSlackConfigured: config.isSlackConfigured,
|
|
isSlackConfigured: config.isSlackConfigured,
|
|
|
|
|
+ slackChannels: this.props.slackChannels,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
this.updateState = this.updateState.bind(this);
|
|
this.updateState = this.updateState.bind(this);
|
|
@@ -77,8 +79,8 @@ class CommentEditor extends React.Component {
|
|
|
|
|
|
|
|
this.renderHtml = this.renderHtml.bind(this);
|
|
this.renderHtml = this.renderHtml.bind(this);
|
|
|
this.handleSelect = this.handleSelect.bind(this);
|
|
this.handleSelect = this.handleSelect.bind(this);
|
|
|
- this.onSlackEnabledFlagChange = this.onSlackEnabledFlagChange.bind(this);
|
|
|
|
|
this.onSlackChannelsChange = this.onSlackChannelsChange.bind(this);
|
|
this.onSlackChannelsChange = this.onSlackChannelsChange.bind(this);
|
|
|
|
|
+ this.fetchSlackChannels = this.fetchSlackChannels.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
updateState(value) {
|
|
updateState(value) {
|
|
@@ -97,12 +99,18 @@ class CommentEditor extends React.Component {
|
|
|
this.renderHtml(this.state.comment);
|
|
this.renderHtml(this.state.comment);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- onSlackEnabledFlagChange(isSlackEnabled) {
|
|
|
|
|
- this.props.commentContainer.setState({ isSlackEnabled });
|
|
|
|
|
|
|
+ fetchSlackChannels(slackChannels) {
|
|
|
|
|
+ this.setState({ slackChannels });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ componentDidUpdate(prevProps) {
|
|
|
|
|
+ if (this.props.slackChannels !== prevProps.slackChannels) {
|
|
|
|
|
+ this.fetchSlackChannels(this.props.slackChannels);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onSlackChannelsChange(slackChannels) {
|
|
onSlackChannelsChange(slackChannels) {
|
|
|
- this.props.commentContainer.setState({ slackChannels });
|
|
|
|
|
|
|
+ this.setState({ slackChannels });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
initializeEditor() {
|
|
initializeEditor() {
|
|
@@ -165,8 +173,8 @@ class CommentEditor extends React.Component {
|
|
|
this.state.comment,
|
|
this.state.comment,
|
|
|
this.state.isMarkdown,
|
|
this.state.isMarkdown,
|
|
|
replyTo,
|
|
replyTo,
|
|
|
- commentContainer.state.isSlackEnabled,
|
|
|
|
|
- commentContainer.state.slackChannels,
|
|
|
|
|
|
|
+ this.props.isSlackEnabled,
|
|
|
|
|
+ this.state.slackChannels,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
this.initializeEditor();
|
|
this.initializeEditor();
|
|
@@ -358,9 +366,9 @@ class CommentEditor extends React.Component {
|
|
|
&& (
|
|
&& (
|
|
|
<div className="form-inline align-self-center mr-md-2">
|
|
<div className="form-inline align-self-center mr-md-2">
|
|
|
<SlackNotification
|
|
<SlackNotification
|
|
|
- isSlackEnabled={commentContainer.state.isSlackEnabled}
|
|
|
|
|
- slackChannels={commentContainer.state.slackChannels}
|
|
|
|
|
- onEnabledFlagChange={this.onSlackEnabledFlagChange}
|
|
|
|
|
|
|
+ isSlackEnabled={this.props.isSlackEnabled}
|
|
|
|
|
+ slackChannels={this.state.slackChannels}
|
|
|
|
|
+ onEnabledFlagChange={this.props.onSlackEnabledFlagChange}
|
|
|
onChannelChange={this.onSlackChannelsChange}
|
|
onChannelChange={this.onSlackChannelsChange}
|
|
|
id="idForComment"
|
|
id="idForComment"
|
|
|
/>
|
|
/>
|
|
@@ -416,6 +424,8 @@ CommentEditor.propTypes = {
|
|
|
editorContainer: PropTypes.instanceOf(EditorContainer).isRequired,
|
|
editorContainer: PropTypes.instanceOf(EditorContainer).isRequired,
|
|
|
commentContainer: PropTypes.instanceOf(CommentContainer).isRequired,
|
|
commentContainer: PropTypes.instanceOf(CommentContainer).isRequired,
|
|
|
|
|
|
|
|
|
|
+ slackChannels: PropTypes.string.isRequired,
|
|
|
|
|
+ isSlackEnabled: PropTypes.bool.isRequired,
|
|
|
growiRenderer: PropTypes.instanceOf(GrowiRenderer).isRequired,
|
|
growiRenderer: PropTypes.instanceOf(GrowiRenderer).isRequired,
|
|
|
currentUser: PropTypes.instanceOf(Object),
|
|
currentUser: PropTypes.instanceOf(Object),
|
|
|
isMobile: PropTypes.bool,
|
|
isMobile: PropTypes.bool,
|
|
@@ -426,15 +436,26 @@ CommentEditor.propTypes = {
|
|
|
commentCreator: PropTypes.string,
|
|
commentCreator: PropTypes.string,
|
|
|
onCancelButtonClicked: PropTypes.func,
|
|
onCancelButtonClicked: PropTypes.func,
|
|
|
onCommentButtonClicked: PropTypes.func,
|
|
onCommentButtonClicked: PropTypes.func,
|
|
|
|
|
+ onSlackEnabledFlagChange: PropTypes.func,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const CommentEditorWrapper = (props) => {
|
|
const CommentEditorWrapper = (props) => {
|
|
|
const { data: isMobile } = useIsMobile();
|
|
const { data: isMobile } = useIsMobile();
|
|
|
const { data: currentUser } = useCurrentUser();
|
|
const { data: currentUser } = useCurrentUser();
|
|
|
|
|
+ const { data: isSlackEnabled, mutate: mutateIsSlackEnabled } = useIsSlackEnabled();
|
|
|
|
|
+ const { data: currentPagePath } = useCurrentPagePath();
|
|
|
|
|
+ const { data: slackChannelsData } = useSWRxSlackChannels(currentPagePath);
|
|
|
|
|
+
|
|
|
|
|
+ const onSlackEnabledFlagChange = (isSlackEnabled) => {
|
|
|
|
|
+ mutateIsSlackEnabled(isSlackEnabled, false);
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<CommentEditorHOCWrapper
|
|
<CommentEditorHOCWrapper
|
|
|
{...props}
|
|
{...props}
|
|
|
|
|
+ onSlackEnabledFlagChange={onSlackEnabledFlagChange}
|
|
|
|
|
+ slackChannels={slackChannelsData.toString()}
|
|
|
|
|
+ isSlackEnabled={isSlackEnabled}
|
|
|
currentUser={currentUser}
|
|
currentUser={currentUser}
|
|
|
isMobile={isMobile}
|
|
isMobile={isMobile}
|
|
|
/>
|
|
/>
|