From cdff304be176f91f9dad3b945752ad2ec88e5e4c Mon Sep 17 00:00:00 2001 From: enahum Date: Thu, 13 Apr 2017 11:57:19 -0300 Subject: [PATCH] RN-64 Ability to open the app in offline mode (#479) --- .../at_mention/at_mention_container.js | 17 ---- app/components/at_mention/index.js | 16 +++- .../channel_drawer_list_container.js | 57 ------------ app/components/channel_drawer_list/index.js | 55 ++++++++++- .../error_list/error_list_container.js | 27 ------ app/components/error_list/index.js | 25 ++++- ..._attachment_list_container.js => index.js} | 0 .../markdown/{markdown.js => index.js} | 0 .../offline_indicator/offline_indicator.js | 2 +- app/components/post/index.js | 55 ++++++++++- app/components/post/post.js | 4 +- app/components/post/post_container.js | 57 ------------ app/components/post_list/index.js | 15 ++- .../post_list/post_list_container.js | 17 ---- app/components/post_textbox/index.js | 39 +++++++- .../post_textbox/post_textbox_container.js | 41 --------- app/components/profile_picture/index.js | 32 ++++++- .../profile_picture_container.js | 34 ------- app/components/root/index.js | 51 ++++++++++- app/components/root/root.js | 25 +---- app/components/root/root_container.js | 53 ----------- app/initial_state.js | 1 + .../account_settings_container.js | 26 ------ app/scenes/account_settings/index.js | 24 ++++- app/scenes/channel/channel.js | 34 ++++--- app/scenes/channel/channel_container.js | 67 -------------- .../channel_post_list_container.js | 91 ------------------- app/scenes/channel/channel_post_list/index.js | 89 +++++++++++++++++- app/scenes/channel/index.js | 67 +++++++++++++- .../channel_add_members_container.js | 51 ----------- app/scenes/channel_add_members/index.js | 49 +++++++++- app/scenes/channel_drawer/channel_drawer.js | 19 +++- .../channel_drawer_container.js | 40 -------- app/scenes/channel_drawer/index.js | 38 +++++++- .../channel_info/channel_info_container.js | 83 ----------------- app/scenes/channel_info/index.js | 81 ++++++++++++++++- .../channel_members_container.js | 48 ---------- app/scenes/channel_members/index.js | 46 +++++++++- app/scenes/index.js | 10 +- app/scenes/load_team/index.js | 38 +++++++- app/scenes/load_team/load_team.js | 5 +- app/scenes/load_team/load_team_container.js | 40 -------- .../login/{login_container.js => index.js} | 0 app/scenes/mfa/index.js | 30 +++++- app/scenes/mfa/mfa_container.js | 32 ------- .../root/{root_container.js => index.js} | 4 +- app/scenes/root/root.js | 26 +++--- .../search/{search_container.js => index.js} | 0 .../{select_server_container.js => index.js} | 0 .../{select_team_container.js => index.js} | 0 app/scenes/thread/index.js | 54 ++++++++++- app/scenes/thread/thread_container.js | 56 ------------ app/scenes/user_profile/index.js | 31 ++++++- .../user_profile/user_profile_container.js | 33 ------- 54 files changed, 866 insertions(+), 969 deletions(-) delete mode 100644 app/components/at_mention/at_mention_container.js delete mode 100644 app/components/channel_drawer_list/channel_drawer_list_container.js delete mode 100644 app/components/error_list/error_list_container.js rename app/components/file_attachment_list/{file_attachment_list_container.js => index.js} (100%) rename app/components/markdown/{markdown.js => index.js} (100%) delete mode 100644 app/components/post/post_container.js delete mode 100644 app/components/post_list/post_list_container.js delete mode 100644 app/components/post_textbox/post_textbox_container.js delete mode 100644 app/components/profile_picture/profile_picture_container.js delete mode 100644 app/components/root/root_container.js delete mode 100644 app/scenes/account_settings/account_settings_container.js delete mode 100644 app/scenes/channel/channel_container.js delete mode 100644 app/scenes/channel/channel_post_list/channel_post_list_container.js delete mode 100644 app/scenes/channel_add_members/channel_add_members_container.js delete mode 100644 app/scenes/channel_drawer/channel_drawer_container.js delete mode 100644 app/scenes/channel_info/channel_info_container.js delete mode 100644 app/scenes/channel_members/channel_members_container.js delete mode 100644 app/scenes/load_team/load_team_container.js rename app/scenes/login/{login_container.js => index.js} (100%) delete mode 100644 app/scenes/mfa/mfa_container.js rename app/scenes/root/{root_container.js => index.js} (90%) rename app/scenes/search/{search_container.js => index.js} (100%) rename app/scenes/select_server/{select_server_container.js => index.js} (100%) rename app/scenes/select_team/{select_team_container.js => index.js} (100%) delete mode 100644 app/scenes/thread/thread_container.js delete mode 100644 app/scenes/user_profile/user_profile_container.js diff --git a/app/components/at_mention/at_mention_container.js b/app/components/at_mention/at_mention_container.js deleted file mode 100644 index d89a4847d..000000000 --- a/app/components/at_mention/at_mention_container.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {connect} from 'react-redux'; - -import {getUsersByUsername} from 'mattermost-redux/selectors/entities/users'; - -import AtMention from './at_mention'; - -function mapStateToProps(state, ownProps) { - return { - usersByUsername: getUsersByUsername(state), - ...ownProps - }; -} - -export default connect(mapStateToProps)(AtMention); diff --git a/app/components/at_mention/index.js b/app/components/at_mention/index.js index 90d1fa71f..d89a4847d 100644 --- a/app/components/at_mention/index.js +++ b/app/components/at_mention/index.js @@ -1,5 +1,17 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import AtMention from './at_mention_container'; -export default AtMention; +import {connect} from 'react-redux'; + +import {getUsersByUsername} from 'mattermost-redux/selectors/entities/users'; + +import AtMention from './at_mention'; + +function mapStateToProps(state, ownProps) { + return { + usersByUsername: getUsersByUsername(state), + ...ownProps + }; +} + +export default connect(mapStateToProps)(AtMention); diff --git a/app/components/channel_drawer_list/channel_drawer_list_container.js b/app/components/channel_drawer_list/channel_drawer_list_container.js deleted file mode 100644 index ac6e0a47a..000000000 --- a/app/components/channel_drawer_list/channel_drawer_list_container.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; -import {connect} from 'react-redux'; - -import { - goToCreateChannel, - openSettingsModal, - requestCloseModal, - showMoreChannelsModal, - showDirectMessagesModal, - showOptionsModal -} from 'app/actions/navigation'; - -import { - closeDirectChannel, - leaveChannel, - markFavorite, - unmarkFavorite -} from 'app/actions/views/channel'; - -import {Constants} from 'mattermost-redux/constants'; -import {getCurrentUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users'; -import {showCreateOption} from 'mattermost-redux/utils/channel_utils'; -import {isAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; - -import ChannelDrawerList from './channel_drawer_list'; - -function mapStateToProps(state, ownProps) { - const {config, license} = state.entities.general; - const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : ''; - - return { - canCreatePrivateChannels: showCreateOption(config, license, Constants.PRIVATE_CHANNEL, isAdmin(roles), isSystemAdmin(roles)), - ...ownProps - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - closeDirectChannel, - goToCreateChannel, - leaveChannel, - markFavorite, - openSettingsModal, - unmarkFavorite, - showOptionsModal, - showDirectMessagesModal, - showMoreChannelsModal, - closeOptionsModal: requestCloseModal - }, dispatch) - }; -} - -export default connect(mapStateToProps, mapDispatchToProps)(ChannelDrawerList); diff --git a/app/components/channel_drawer_list/index.js b/app/components/channel_drawer_list/index.js index 5da62851d..ac6e0a47a 100644 --- a/app/components/channel_drawer_list/index.js +++ b/app/components/channel_drawer_list/index.js @@ -1,6 +1,57 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ChannelListContainer from './channel_drawer_list_container'; +import {bindActionCreators} from 'redux'; +import {connect} from 'react-redux'; -export default ChannelListContainer; +import { + goToCreateChannel, + openSettingsModal, + requestCloseModal, + showMoreChannelsModal, + showDirectMessagesModal, + showOptionsModal +} from 'app/actions/navigation'; + +import { + closeDirectChannel, + leaveChannel, + markFavorite, + unmarkFavorite +} from 'app/actions/views/channel'; + +import {Constants} from 'mattermost-redux/constants'; +import {getCurrentUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users'; +import {showCreateOption} from 'mattermost-redux/utils/channel_utils'; +import {isAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; + +import ChannelDrawerList from './channel_drawer_list'; + +function mapStateToProps(state, ownProps) { + const {config, license} = state.entities.general; + const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : ''; + + return { + canCreatePrivateChannels: showCreateOption(config, license, Constants.PRIVATE_CHANNEL, isAdmin(roles), isSystemAdmin(roles)), + ...ownProps + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + closeDirectChannel, + goToCreateChannel, + leaveChannel, + markFavorite, + openSettingsModal, + unmarkFavorite, + showOptionsModal, + showDirectMessagesModal, + showMoreChannelsModal, + closeOptionsModal: requestCloseModal + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(ChannelDrawerList); diff --git a/app/components/error_list/error_list_container.js b/app/components/error_list/error_list_container.js deleted file mode 100644 index 944b79e85..000000000 --- a/app/components/error_list/error_list_container.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; -import {connect} from 'react-redux'; - -import {getDisplayableErrors} from 'mattermost-redux/selectors/errors'; -import {dismissError, clearErrors} from 'mattermost-redux/actions/errors'; - -import ErrorList from './error_list'; - -function mapStateToProps(state) { - return { - errors: getDisplayableErrors(state) - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - dismissError, - clearErrors - }, dispatch) - }; -} - -export default connect(mapStateToProps, mapDispatchToProps)(ErrorList); diff --git a/app/components/error_list/index.js b/app/components/error_list/index.js index 812602c38..944b79e85 100644 --- a/app/components/error_list/index.js +++ b/app/components/error_list/index.js @@ -1,6 +1,27 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ErrorListContainer from './error_list_container'; +import {bindActionCreators} from 'redux'; +import {connect} from 'react-redux'; -export default ErrorListContainer; +import {getDisplayableErrors} from 'mattermost-redux/selectors/errors'; +import {dismissError, clearErrors} from 'mattermost-redux/actions/errors'; + +import ErrorList from './error_list'; + +function mapStateToProps(state) { + return { + errors: getDisplayableErrors(state) + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + dismissError, + clearErrors + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(ErrorList); diff --git a/app/components/file_attachment_list/file_attachment_list_container.js b/app/components/file_attachment_list/index.js similarity index 100% rename from app/components/file_attachment_list/file_attachment_list_container.js rename to app/components/file_attachment_list/index.js diff --git a/app/components/markdown/markdown.js b/app/components/markdown/index.js similarity index 100% rename from app/components/markdown/markdown.js rename to app/components/markdown/index.js diff --git a/app/components/offline_indicator/offline_indicator.js b/app/components/offline_indicator/offline_indicator.js index e497c364b..9f41ea339 100644 --- a/app/components/offline_indicator/offline_indicator.js +++ b/app/components/offline_indicator/offline_indicator.js @@ -77,7 +77,7 @@ export default class OfflineIndicator extends PureComponent { // set forced to be false after trying for 3 seconds setTimeout(() => { - closeWebSocket(); + closeWebSocket(true); this.setState({forced: false, network: OFFLINE}); }, 3000); }); diff --git a/app/components/post/index.js b/app/components/post/index.js index b068ebe3c..5a459a502 100644 --- a/app/components/post/index.js +++ b/app/components/post/index.js @@ -1,6 +1,57 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import Post from './post_container'; +import {connect} from 'react-redux'; +import {bindActionCreators} from 'redux'; +import {deletePost, flagPost, unflagPost} from 'mattermost-redux/actions/posts'; +import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; +import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; +import {makeGetCommentCountForPost} from 'mattermost-redux/selectors/entities/posts'; +import {getCurrentUserId, getCurrentUserRoles, getUser} from 'mattermost-redux/selectors/entities/users'; +import {isPostFlagged} from 'mattermost-redux/utils/post_utils'; +import {displayUsername} from 'mattermost-redux/utils/user_utils'; -export default Post; +import {goToUserProfile, openEditPostModal} from 'app/actions/navigation'; +import {getTheme} from 'app/selectors/preferences'; + +import Post from './post'; + +function makeMapStateToProps() { + const getCommentCountForPost = makeGetCommentCountForPost(); + return function mapStateToProps(state, ownProps) { + const commentedOnUser = ownProps.commentedOnPost ? getUser(state, ownProps.commentedOnPost.user_id) : null; + const user = getUser(state, ownProps.post.user_id); + const myPreferences = getMyPreferences(state); + const {config, license} = state.entities.general; + const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : ''; + + return { + ...ownProps, + config, + commentCount: getCommentCountForPost(state, ownProps), + commentedOnDisplayName: displayUsername(commentedOnUser, myPreferences), + currentTeamId: getCurrentTeamId(state), + currentUserId: getCurrentUserId(state), + displayName: displayUsername(user, myPreferences), + isFlagged: isPostFlagged(ownProps.post.id, myPreferences), + license, + roles, + theme: getTheme(state), + user + }; + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + deletePost, + flagPost, + goToUserProfile, + openEditPostModal, + unflagPost + }, dispatch) + }; +} + +export default connect(makeMapStateToProps, mapDispatchToProps)(Post); diff --git a/app/components/post/post.js b/app/components/post/post.js index b764b0342..7f9760c3a 100644 --- a/app/components/post/post.js +++ b/app/components/post/post.js @@ -14,11 +14,11 @@ import { } from 'react-native'; import {injectIntl, intlShape} from 'react-intl'; -import FileAttachmentList from 'app/components/file_attachment_list/file_attachment_list_container'; +import FileAttachmentList from 'app/components/file_attachment_list'; import FormattedText from 'app/components/formatted_text'; import FormattedTime from 'app/components/formatted_time'; import MattermostIcon from 'app/components/mattermost_icon'; -import Markdown from 'app/components/markdown/markdown'; +import Markdown from 'app/components/markdown'; import OptionsContext from 'app/components/options_context'; import ProfilePicture from 'app/components/profile_picture'; import ReplyIcon from 'app/components/reply_icon'; diff --git a/app/components/post/post_container.js b/app/components/post/post_container.js deleted file mode 100644 index 5a459a502..000000000 --- a/app/components/post/post_container.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {connect} from 'react-redux'; -import {bindActionCreators} from 'redux'; -import {deletePost, flagPost, unflagPost} from 'mattermost-redux/actions/posts'; -import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; -import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; -import {makeGetCommentCountForPost} from 'mattermost-redux/selectors/entities/posts'; -import {getCurrentUserId, getCurrentUserRoles, getUser} from 'mattermost-redux/selectors/entities/users'; -import {isPostFlagged} from 'mattermost-redux/utils/post_utils'; -import {displayUsername} from 'mattermost-redux/utils/user_utils'; - -import {goToUserProfile, openEditPostModal} from 'app/actions/navigation'; -import {getTheme} from 'app/selectors/preferences'; - -import Post from './post'; - -function makeMapStateToProps() { - const getCommentCountForPost = makeGetCommentCountForPost(); - return function mapStateToProps(state, ownProps) { - const commentedOnUser = ownProps.commentedOnPost ? getUser(state, ownProps.commentedOnPost.user_id) : null; - const user = getUser(state, ownProps.post.user_id); - const myPreferences = getMyPreferences(state); - const {config, license} = state.entities.general; - const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : ''; - - return { - ...ownProps, - config, - commentCount: getCommentCountForPost(state, ownProps), - commentedOnDisplayName: displayUsername(commentedOnUser, myPreferences), - currentTeamId: getCurrentTeamId(state), - currentUserId: getCurrentUserId(state), - displayName: displayUsername(user, myPreferences), - isFlagged: isPostFlagged(ownProps.post.id, myPreferences), - license, - roles, - theme: getTheme(state), - user - }; - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - deletePost, - flagPost, - goToUserProfile, - openEditPostModal, - unflagPost - }, dispatch) - }; -} - -export default connect(makeMapStateToProps, mapDispatchToProps)(Post); diff --git a/app/components/post_list/index.js b/app/components/post_list/index.js index cd5a7b36a..f05db9712 100644 --- a/app/components/post_list/index.js +++ b/app/components/post_list/index.js @@ -1,6 +1,17 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import PostList from './post_list_container'; +import {connect} from 'react-redux'; -export default PostList; +import {getTheme} from 'app/selectors/preferences'; + +import PostList from './post_list'; + +function mapStateToProps(state, ownProps) { + return { + theme: getTheme(state), + ...ownProps + }; +} + +export default connect(mapStateToProps)(PostList); diff --git a/app/components/post_list/post_list_container.js b/app/components/post_list/post_list_container.js deleted file mode 100644 index f05db9712..000000000 --- a/app/components/post_list/post_list_container.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {connect} from 'react-redux'; - -import {getTheme} from 'app/selectors/preferences'; - -import PostList from './post_list'; - -function mapStateToProps(state, ownProps) { - return { - theme: getTheme(state), - ...ownProps - }; -} - -export default connect(mapStateToProps)(PostList); diff --git a/app/components/post_textbox/index.js b/app/components/post_textbox/index.js index 1bea7006e..f3f4b72f0 100644 --- a/app/components/post_textbox/index.js +++ b/app/components/post_textbox/index.js @@ -1,6 +1,41 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import PostTextboxContainer from './post_textbox_container'; +import {bindActionCreators} from 'redux'; +import {connect} from 'react-redux'; +import {createPost} from 'mattermost-redux/actions/posts'; +import {userTyping} from 'mattermost-redux/actions/websocket'; -export default PostTextboxContainer; +import {showOptionsModal, requestCloseModal} from 'app/actions/navigation'; +import {handleRemoveLastFile, handleUploadFiles} from 'app/actions/views/file_upload'; +import {getTheme} from 'app/selectors/preferences'; +import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; +import {getUsersTyping} from 'mattermost-redux/selectors/entities/typing'; + +import PostTextbox from './post_textbox'; + +function mapStateToProps(state, ownProps) { + return { + ...ownProps, + channelIsLoading: state.views.channel.loading, + currentUserId: getCurrentUserId(state), + typing: getUsersTyping(state), + theme: getTheme(state), + uploadFileRequestStatus: state.requests.files.uploadFiles.status + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + createPost, + closeModal: requestCloseModal, + handleRemoveLastFile, + handleUploadFiles, + showOptionsModal, + userTyping + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps, null, {withRef: true})(PostTextbox); diff --git a/app/components/post_textbox/post_textbox_container.js b/app/components/post_textbox/post_textbox_container.js deleted file mode 100644 index f3f4b72f0..000000000 --- a/app/components/post_textbox/post_textbox_container.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; -import {connect} from 'react-redux'; -import {createPost} from 'mattermost-redux/actions/posts'; -import {userTyping} from 'mattermost-redux/actions/websocket'; - -import {showOptionsModal, requestCloseModal} from 'app/actions/navigation'; -import {handleRemoveLastFile, handleUploadFiles} from 'app/actions/views/file_upload'; -import {getTheme} from 'app/selectors/preferences'; -import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import {getUsersTyping} from 'mattermost-redux/selectors/entities/typing'; - -import PostTextbox from './post_textbox'; - -function mapStateToProps(state, ownProps) { - return { - ...ownProps, - channelIsLoading: state.views.channel.loading, - currentUserId: getCurrentUserId(state), - typing: getUsersTyping(state), - theme: getTheme(state), - uploadFileRequestStatus: state.requests.files.uploadFiles.status - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - createPost, - closeModal: requestCloseModal, - handleRemoveLastFile, - handleUploadFiles, - showOptionsModal, - userTyping - }, dispatch) - }; -} - -export default connect(mapStateToProps, mapDispatchToProps, null, {withRef: true})(PostTextbox); diff --git a/app/components/profile_picture/index.js b/app/components/profile_picture/index.js index 5a1b88579..d68a54a1d 100644 --- a/app/components/profile_picture/index.js +++ b/app/components/profile_picture/index.js @@ -1,6 +1,34 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ProfilePicture from './profile_picture_container'; +import {bindActionCreators} from 'redux'; +import {connect} from 'react-redux'; -export default ProfilePicture; +import {getTheme} from 'app/selectors/preferences'; +import {getStatusesByIdsBatchedDebounced} from 'mattermost-redux/actions/users'; +import {getStatusForUserId} from 'mattermost-redux/selectors/entities/users'; + +import ProfilePicture from './profile_picture'; + +function mapStateToProps(state, ownProps) { + let status = ownProps.status; + if (!status && ownProps.user) { + status = ownProps.user.status || getStatusForUserId(state, ownProps.user.id); + } + + return { + theme: ownProps.theme || getTheme(state), + status, + ...ownProps + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + getStatusForId: getStatusesByIdsBatchedDebounced + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(ProfilePicture); diff --git a/app/components/profile_picture/profile_picture_container.js b/app/components/profile_picture/profile_picture_container.js deleted file mode 100644 index d68a54a1d..000000000 --- a/app/components/profile_picture/profile_picture_container.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; -import {connect} from 'react-redux'; - -import {getTheme} from 'app/selectors/preferences'; -import {getStatusesByIdsBatchedDebounced} from 'mattermost-redux/actions/users'; -import {getStatusForUserId} from 'mattermost-redux/selectors/entities/users'; - -import ProfilePicture from './profile_picture'; - -function mapStateToProps(state, ownProps) { - let status = ownProps.status; - if (!status && ownProps.user) { - status = ownProps.user.status || getStatusForUserId(state, ownProps.user.id); - } - - return { - theme: ownProps.theme || getTheme(state), - status, - ...ownProps - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - getStatusForId: getStatusesByIdsBatchedDebounced - }, dispatch) - }; -} - -export default connect(mapStateToProps, mapDispatchToProps)(ProfilePicture); diff --git a/app/components/root/index.js b/app/components/root/index.js index 5825d5824..7ad5a4915 100644 --- a/app/components/root/index.js +++ b/app/components/root/index.js @@ -1,6 +1,53 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import RootContainer from './root_container'; +import {bindActionCreators} from 'redux'; +import {connect} from 'react-redux'; -export default RootContainer; +import Config from 'assets/config.json'; + +import {closeDrawers, closeModal, goBack, unrenderDrawer} from 'app/actions/navigation'; +import {goToNotification, loadConfigAndLicense, queueNotification} from 'app/actions/views/root'; +import {setAppState, setDeviceToken} from 'mattermost-redux/actions/general'; +import {logout} from 'mattermost-redux/actions/users'; + +import Root from './root'; + +function mapStateToProps(state, ownProps) { + const users = state.entities.users; + const {currentUserId} = users; + const {currentTeamId} = state.entities.teams; + const {currentChannelId} = state.entities.channels; + + let locale = Config.DefaultLocale; + if (currentUserId && users.profiles[currentUserId]) { + locale = users.profiles[currentUserId].locale; + } + + return { + ...ownProps, + currentTeamId, + currentChannelId, + locale, + navigation: state.navigation + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + closeDrawers, + closeModal, + goBack, + loadConfigAndLicense, + logout, + goToNotification, + queueNotification, + setAppState, + setDeviceToken, + unrenderDrawer + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(Root); diff --git a/app/components/root/root.js b/app/components/root/root.js index 42b38f3cb..95a4f1276 100644 --- a/app/components/root/root.js +++ b/app/components/root/root.js @@ -5,7 +5,6 @@ import React, {Component, PropTypes} from 'react'; import { Alert, AppState, - AsyncStorage, BackAndroid, InteractionManager, Platform, @@ -43,12 +42,6 @@ export default class Root extends Component { }).isRequired }; - constructor(props) { - super(props); - - this.handleAppStateChange = this.handleAppStateChange.bind(this); - } - componentDidMount() { this.props.actions.setAppState(AppState.currentState === 'active'); AppState.addEventListener('change', this.handleAppStateChange); @@ -69,13 +62,13 @@ export default class Root extends Component { } } - handleAppStateChange(appState) { + handleAppStateChange = (appState) => { this.props.actions.setAppState(appState === 'active'); if (appState === 'inactive') { // TODO: See if we still need this } - } + }; handleAndroidBack = () => { const {index, isModal, leftDrawerOpen, modal} = this.props.navigation; @@ -125,17 +118,9 @@ export default class Root extends Component { Client.serverVersion = ''; - const storage = await AsyncStorage.getItem('storage'); - if (storage) { - setTimeout(async () => { - const {token} = JSON.parse(await AsyncStorage.getItem('storage')); - if (token) { - closeDrawers(); - unrenderDrawer(); - InteractionManager.runAfterInteractions(logout); - } - }, 1000); - } + closeDrawers(); + unrenderDrawer(); + InteractionManager.runAfterInteractions(logout); }; render() { diff --git a/app/components/root/root_container.js b/app/components/root/root_container.js deleted file mode 100644 index 5c153d773..000000000 --- a/app/components/root/root_container.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; -import {connect} from 'react-redux'; - -import Config from 'assets/config.json'; - -import {closeDrawers, closeModal, goBack, unrenderDrawer} from 'app/actions/navigation'; -import {goToNotification, loadConfigAndLicense, queueNotification} from 'app/actions/views/root'; -import {setAppState, setDeviceToken} from 'mattermost-redux/actions/general'; -import {logout} from 'mattermost-redux/actions/users'; - -import Root from './root'; - -function mapStateToProps(state, ownProps) { - const users = state.entities.users; - const {currentUserId} = users; - const {currentTeamId} = state.entities.teams; - const {currentChannelId} = state.entities.channels; - - let locale = Config.DefaultLocale; - if (currentUserId && users.profiles[currentUserId]) { - locale = users.profiles[currentUserId].locale; - } - - return { - ...ownProps, - currentTeamId, - currentChannelId, - locale, - navigation: state.navigation - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - closeDrawers, - closeModal, - goBack, - loadConfigAndLicense, - logout, - goToNotification, - queueNotification, - setAppState, - setDeviceToken, - unrenderDrawer - }, dispatch) - }; -} - -export default connect(mapStateToProps, mapDispatchToProps)(Root); diff --git a/app/initial_state.js b/app/initial_state.js index fcd713be1..1fd7f706c 100644 --- a/app/initial_state.js +++ b/app/initial_state.js @@ -279,6 +279,7 @@ const state = { drafts: {}, loading: false }, + connection: true, fetchCache: {}, i18n: { locale: '' diff --git a/app/scenes/account_settings/account_settings_container.js b/app/scenes/account_settings/account_settings_container.js deleted file mode 100644 index 3e6249b94..000000000 --- a/app/scenes/account_settings/account_settings_container.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import {goToAccountNotifications} from 'app/actions/navigation'; -import {getTheme} from 'app/selectors/preferences'; - -import navigationSceneConnect from '../navigationSceneConnect'; -import AccountSettings from './account_settings'; - -function mapStateToProps(state) { - return { - theme: getTheme(state) - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - goToAccountNotifications - }, dispatch) - }; -} - -export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(AccountSettings); diff --git a/app/scenes/account_settings/index.js b/app/scenes/account_settings/index.js index 28cabac34..3e6249b94 100644 --- a/app/scenes/account_settings/index.js +++ b/app/scenes/account_settings/index.js @@ -1,6 +1,26 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import AccountSettingsContainer from './account_settings_container'; +import {bindActionCreators} from 'redux'; -export default AccountSettingsContainer; +import {goToAccountNotifications} from 'app/actions/navigation'; +import {getTheme} from 'app/selectors/preferences'; + +import navigationSceneConnect from '../navigationSceneConnect'; +import AccountSettings from './account_settings'; + +function mapStateToProps(state) { + return { + theme: getTheme(state) + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + goToAccountNotifications + }, dispatch) + }; +} + +export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(AccountSettings); diff --git a/app/scenes/channel/channel.js b/app/scenes/channel/channel.js index 2ab8cc78b..210bfae19 100644 --- a/app/scenes/channel/channel.js +++ b/app/scenes/channel/channel.js @@ -64,11 +64,7 @@ export default class Channel extends PureComponent { this.props.subscribeToHeaderEvent('show_channel_info', () => preventDoubleTap(this.props.actions.goToChannelInfo)); NetInfo.isConnected.addEventListener('change', this.handleConnectionChange); EventEmitter.on('leave_team', this.handleLeaveTeam); - - // Android won't detect the initial connection change that's why we need this - if (Platform.OS === 'android') { - NetInfo.isConnected.fetch().then(this.handleConnectionChange); - } + NetInfo.isConnected.fetch().then(this.handleConnectionChange); if (this.props.currentTeam) { const teamId = this.props.currentTeam.id; @@ -77,8 +73,13 @@ export default class Channel extends PureComponent { } componentDidMount() { - this.props.actions.startPeriodicStatusUpdates(); - this.props.actions.renderDrawer(); + const {renderDrawer, startPeriodicStatusUpdates} = this.props.actions; + try { + startPeriodicStatusUpdates(); + } catch (error) { + // We don't care about the error + } + renderDrawer(); } componentWillReceiveProps(nextProps) { @@ -102,18 +103,27 @@ export default class Channel extends PureComponent { if (isConnected) { if (!webSocketRequest || webSocketRequest.status === RequestStatus.NOT_STARTED) { - initWebSocket(Platform.OS); + try { + initWebSocket(Platform.OS); + } catch (error) { + // We don't care if it fails + } } } else { - closeWebSocket(); + closeWebSocket(true); } connection(isConnected); }; loadChannels = (teamId) => { - this.props.actions.loadChannelsIfNecessary(teamId).then(() => { - this.props.actions.loadProfilesAndTeamMembersForDMSidebar(teamId); - return this.props.actions.selectInitialChannel(teamId); + const { + loadChannelsIfNecessary, + loadProfilesAndTeamMembersForDMSidebar, + selectInitialChannel + } = this.props.actions; + loadChannelsIfNecessary(teamId).then(() => { + loadProfilesAndTeamMembersForDMSidebar(teamId); + return selectInitialChannel(teamId); }); }; diff --git a/app/scenes/channel/channel_container.js b/app/scenes/channel/channel_container.js deleted file mode 100644 index 9d33602da..000000000 --- a/app/scenes/channel/channel_container.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import navigationSceneConnect from '../navigationSceneConnect'; - -import { - goToChannelInfo, - openChannelDrawer, - renderDrawer -} from 'app/actions/navigation'; -import { - loadChannelsIfNecessary, - loadProfilesAndTeamMembersForDMSidebar, - selectInitialChannel, - handlePostDraftChanged -} from 'app/actions/views/channel'; -import {connection} from 'app/actions/views/connection'; -import {selectFirstAvailableTeam} from 'app/actions/views/select_team'; -import {getTheme} from 'app/selectors/preferences'; - -import {startPeriodicStatusUpdates, stopPeriodicStatusUpdates} from 'mattermost-redux/actions/users'; -import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; -import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; - -import { - init as initWebSocket, - close as closeWebSocket -} from 'mattermost-redux/actions/websocket'; - -import Channel from './channel'; - -function mapStateToProps(state, ownProps) { - const {websocket} = state.requests.general; - - return { - ...ownProps, - ...state.views.channel, - currentTeam: getCurrentTeam(state), - currentChannel: getCurrentChannel(state), - theme: getTheme(state), - webSocketRequest: websocket - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - connection, - loadChannelsIfNecessary, - loadProfilesAndTeamMembersForDMSidebar, - selectFirstAvailableTeam, - selectInitialChannel, - openChannelDrawer, - handlePostDraftChanged, - goToChannelInfo, - initWebSocket, - closeWebSocket, - startPeriodicStatusUpdates, - stopPeriodicStatusUpdates, - renderDrawer - }, dispatch) - }; -} - -export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(Channel); diff --git a/app/scenes/channel/channel_post_list/channel_post_list_container.js b/app/scenes/channel/channel_post_list/channel_post_list_container.js deleted file mode 100644 index 6111025d8..000000000 --- a/app/scenes/channel/channel_post_list/channel_post_list_container.js +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; -import {connect} from 'react-redux'; -import {createSelector} from 'reselect'; -import {getPostsBefore} from 'mattermost-redux/actions/posts'; -import {getAllPosts, getPostsInCurrentChannel} from 'mattermost-redux/selectors/entities/posts'; -import {getCurrentChannelMembership} from 'mattermost-redux/selectors/entities/channels'; -import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; - -import {goToThread} from 'app/actions/navigation'; -import {loadPostsIfNecessary} from 'app/actions/views/channel'; -import {getTheme} from 'app/selectors/preferences'; - -import ChannelPostList from './channel_post_list'; - -const getPostsInCurrentChannelWithReplyProps = createSelector( - getAllPosts, - getPostsInCurrentChannel, - (allPosts, postsInChannel) => { - const posts = []; - - for (let i = 0; i < postsInChannel.length; i++) { - let post = postsInChannel[i]; - - if (post.root_id) { - let isFirstReply = false; - let isLastReply = false; - let commentedOnPost; - - if (i + 1 <= postsInChannel.length) { - const previousPost = postsInChannel[i + 1]; - - if (previousPost.root_id !== post.root_id) { - isFirstReply = true; - - if (previousPost.id !== post.root_id) { - commentedOnPost = allPosts[post.root_id]; - } - } - } else { - // The first visible comment will always be the first comment in a thread and will be - // commenting on a post that isn't visible - isFirstReply = true; - commentedOnPost = allPosts[post.root_id]; - } - - if (i - 1 < 0 || postsInChannel[i - 1].root_id !== post.root_id) { - isLastReply = true; - } - - post = { - ...post, - isFirstReply, - isLastReply, - commentedOnPost - }; - } - - posts.push(post); - } - - return posts; - } -); - -function mapStateToProps(state, ownProps) { - return { - ...ownProps, - applicationInitializing: state.views.channel.appInitializing, - currentTeamId: getCurrentTeamId(state), - channelIsLoading: state.views.channel.loading, - myMember: getCurrentChannelMembership(state), - postsRequests: state.requests.posts, - posts: getPostsInCurrentChannelWithReplyProps(state), - theme: getTheme(state) - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - loadPostsIfNecessary, - getPostsBefore, - goToThread - }, dispatch) - }; -} - -export default connect(mapStateToProps, mapDispatchToProps)(ChannelPostList); diff --git a/app/scenes/channel/channel_post_list/index.js b/app/scenes/channel/channel_post_list/index.js index 695e4f9a8..6111025d8 100644 --- a/app/scenes/channel/channel_post_list/index.js +++ b/app/scenes/channel/channel_post_list/index.js @@ -1,6 +1,91 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ChannelPostListContainer from './channel_post_list_container'; +import {bindActionCreators} from 'redux'; +import {connect} from 'react-redux'; +import {createSelector} from 'reselect'; +import {getPostsBefore} from 'mattermost-redux/actions/posts'; +import {getAllPosts, getPostsInCurrentChannel} from 'mattermost-redux/selectors/entities/posts'; +import {getCurrentChannelMembership} from 'mattermost-redux/selectors/entities/channels'; +import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; -export default ChannelPostListContainer; +import {goToThread} from 'app/actions/navigation'; +import {loadPostsIfNecessary} from 'app/actions/views/channel'; +import {getTheme} from 'app/selectors/preferences'; + +import ChannelPostList from './channel_post_list'; + +const getPostsInCurrentChannelWithReplyProps = createSelector( + getAllPosts, + getPostsInCurrentChannel, + (allPosts, postsInChannel) => { + const posts = []; + + for (let i = 0; i < postsInChannel.length; i++) { + let post = postsInChannel[i]; + + if (post.root_id) { + let isFirstReply = false; + let isLastReply = false; + let commentedOnPost; + + if (i + 1 <= postsInChannel.length) { + const previousPost = postsInChannel[i + 1]; + + if (previousPost.root_id !== post.root_id) { + isFirstReply = true; + + if (previousPost.id !== post.root_id) { + commentedOnPost = allPosts[post.root_id]; + } + } + } else { + // The first visible comment will always be the first comment in a thread and will be + // commenting on a post that isn't visible + isFirstReply = true; + commentedOnPost = allPosts[post.root_id]; + } + + if (i - 1 < 0 || postsInChannel[i - 1].root_id !== post.root_id) { + isLastReply = true; + } + + post = { + ...post, + isFirstReply, + isLastReply, + commentedOnPost + }; + } + + posts.push(post); + } + + return posts; + } +); + +function mapStateToProps(state, ownProps) { + return { + ...ownProps, + applicationInitializing: state.views.channel.appInitializing, + currentTeamId: getCurrentTeamId(state), + channelIsLoading: state.views.channel.loading, + myMember: getCurrentChannelMembership(state), + postsRequests: state.requests.posts, + posts: getPostsInCurrentChannelWithReplyProps(state), + theme: getTheme(state) + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + loadPostsIfNecessary, + getPostsBefore, + goToThread + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(ChannelPostList); diff --git a/app/scenes/channel/index.js b/app/scenes/channel/index.js index fe16e2c5b..9d33602da 100644 --- a/app/scenes/channel/index.js +++ b/app/scenes/channel/index.js @@ -1,6 +1,67 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ChannelContainer from './channel_container'; +import {bindActionCreators} from 'redux'; -export default ChannelContainer; +import navigationSceneConnect from '../navigationSceneConnect'; + +import { + goToChannelInfo, + openChannelDrawer, + renderDrawer +} from 'app/actions/navigation'; +import { + loadChannelsIfNecessary, + loadProfilesAndTeamMembersForDMSidebar, + selectInitialChannel, + handlePostDraftChanged +} from 'app/actions/views/channel'; +import {connection} from 'app/actions/views/connection'; +import {selectFirstAvailableTeam} from 'app/actions/views/select_team'; +import {getTheme} from 'app/selectors/preferences'; + +import {startPeriodicStatusUpdates, stopPeriodicStatusUpdates} from 'mattermost-redux/actions/users'; +import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; +import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; + +import { + init as initWebSocket, + close as closeWebSocket +} from 'mattermost-redux/actions/websocket'; + +import Channel from './channel'; + +function mapStateToProps(state, ownProps) { + const {websocket} = state.requests.general; + + return { + ...ownProps, + ...state.views.channel, + currentTeam: getCurrentTeam(state), + currentChannel: getCurrentChannel(state), + theme: getTheme(state), + webSocketRequest: websocket + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + connection, + loadChannelsIfNecessary, + loadProfilesAndTeamMembersForDMSidebar, + selectFirstAvailableTeam, + selectInitialChannel, + openChannelDrawer, + handlePostDraftChanged, + goToChannelInfo, + initWebSocket, + closeWebSocket, + startPeriodicStatusUpdates, + stopPeriodicStatusUpdates, + renderDrawer + }, dispatch) + }; +} + +export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(Channel); diff --git a/app/scenes/channel_add_members/channel_add_members_container.js b/app/scenes/channel_add_members/channel_add_members_container.js deleted file mode 100644 index 4a8669d4c..000000000 --- a/app/scenes/channel_add_members/channel_add_members_container.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import navigationSceneConnect from '../navigationSceneConnect'; - -import {handleAddChannelMembers} from 'app/actions/views/channel_add_members'; -import {goBack} from 'app/actions/navigation'; -import {getTheme} from 'app/selectors/preferences'; -import {getCurrentChannel, getCurrentChannelStats} from 'mattermost-redux/selectors/entities/channels'; -import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; -import {getCurrentTeam, getCurrentTeamStats} from 'mattermost-redux/selectors/entities/teams'; -import {getProfilesNotInCurrentChannel} from 'mattermost-redux/selectors/entities/users'; -import {getTeamStats} from 'mattermost-redux/actions/teams'; -import {getProfilesNotInChannel, searchProfiles} from 'mattermost-redux/actions/users'; - -import ChannelAddMembers from './channel_add_members'; - -function mapStateToProps(state) { - const currentTeamMemberCount = getCurrentTeamStats(state) && getCurrentTeamStats(state).total_member_count; - const currentChannelMemberCount = getCurrentChannelStats(state) && getCurrentChannelStats(state).member_count; - - return { - theme: getTheme(state), - currentChannel: getCurrentChannel(state), - membersNotInChannel: getProfilesNotInCurrentChannel(state), - currentTeam: getCurrentTeam(state), - currentTeamMemberCount, - currentChannelMemberCount, - preferences: getMyPreferences(state), - loadMoreRequestStatus: state.requests.users.getProfilesNotInChannel.status, - addChannelMemberRequestStatus: state.requests.channels.addChannelMember, - searchRequestStatus: state.requests.users.searchProfiles.status, - addChannelMemberStatus: state.requests.channels.addChannelMember.status - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - getTeamStats, - getProfilesNotInChannel, - goBack, - handleAddChannelMembers, - searchProfiles - }, dispatch) - }; -} - -export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(ChannelAddMembers); diff --git a/app/scenes/channel_add_members/index.js b/app/scenes/channel_add_members/index.js index 69ef3f1e8..4a8669d4c 100644 --- a/app/scenes/channel_add_members/index.js +++ b/app/scenes/channel_add_members/index.js @@ -1,6 +1,51 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ChannelAddMembersContainer from './channel_add_members_container'; +import {bindActionCreators} from 'redux'; -export default ChannelAddMembersContainer; +import navigationSceneConnect from '../navigationSceneConnect'; + +import {handleAddChannelMembers} from 'app/actions/views/channel_add_members'; +import {goBack} from 'app/actions/navigation'; +import {getTheme} from 'app/selectors/preferences'; +import {getCurrentChannel, getCurrentChannelStats} from 'mattermost-redux/selectors/entities/channels'; +import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; +import {getCurrentTeam, getCurrentTeamStats} from 'mattermost-redux/selectors/entities/teams'; +import {getProfilesNotInCurrentChannel} from 'mattermost-redux/selectors/entities/users'; +import {getTeamStats} from 'mattermost-redux/actions/teams'; +import {getProfilesNotInChannel, searchProfiles} from 'mattermost-redux/actions/users'; + +import ChannelAddMembers from './channel_add_members'; + +function mapStateToProps(state) { + const currentTeamMemberCount = getCurrentTeamStats(state) && getCurrentTeamStats(state).total_member_count; + const currentChannelMemberCount = getCurrentChannelStats(state) && getCurrentChannelStats(state).member_count; + + return { + theme: getTheme(state), + currentChannel: getCurrentChannel(state), + membersNotInChannel: getProfilesNotInCurrentChannel(state), + currentTeam: getCurrentTeam(state), + currentTeamMemberCount, + currentChannelMemberCount, + preferences: getMyPreferences(state), + loadMoreRequestStatus: state.requests.users.getProfilesNotInChannel.status, + addChannelMemberRequestStatus: state.requests.channels.addChannelMember, + searchRequestStatus: state.requests.users.searchProfiles.status, + addChannelMemberStatus: state.requests.channels.addChannelMember.status + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + getTeamStats, + getProfilesNotInChannel, + goBack, + handleAddChannelMembers, + searchProfiles + }, dispatch) + }; +} + +export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(ChannelAddMembers); diff --git a/app/scenes/channel_drawer/channel_drawer.js b/app/scenes/channel_drawer/channel_drawer.js index c70ad6121..c5c2f315b 100644 --- a/app/scenes/channel_drawer/channel_drawer.js +++ b/app/scenes/channel_drawer/channel_drawer.js @@ -29,16 +29,25 @@ export default class ChannelDrawer extends PureComponent { selectChannel = (id) => { const { + actions, currentChannel, currentTeam } = this.props; - this.props.actions.markChannelAsRead(currentChannel.id); - this.props.actions.setChannelLoading(); - this.props.actions.viewChannel(currentTeam.id, id); - this.props.actions.closeDrawers(); + const { + closeDrawers, + handleSelectChannel, + markChannelAsRead, + setChannelLoading, + viewChannel + } = actions; + + markChannelAsRead(currentChannel.id); + setChannelLoading(); + viewChannel(currentTeam.id, id); + closeDrawers(); InteractionManager.runAfterInteractions(() => { - this.props.actions.handleSelectChannel(id); + handleSelectChannel(id); }); }; diff --git a/app/scenes/channel_drawer/channel_drawer_container.js b/app/scenes/channel_drawer/channel_drawer_container.js deleted file mode 100644 index 493308ab1..000000000 --- a/app/scenes/channel_drawer/channel_drawer_container.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; -import {connect} from 'react-redux'; - -import {closeDrawers} from 'app/actions/navigation'; -import {handleSelectChannel, setChannelLoading} from 'app/actions/views/channel'; - -import {getChannelsByCategory, getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; -import {getTheme} from 'app/selectors/preferences'; -import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; - -import {viewChannel, markChannelAsRead} from 'mattermost-redux/actions/channels'; - -import ChannelDrawer from './channel_drawer.js'; - -function mapStateToProps(state) { - return { - currentTeam: getCurrentTeam(state), - currentChannel: getCurrentChannel(state), - channels: getChannelsByCategory(state), - channelMembers: state.entities.channels.myMembers, - theme: getTheme(state) - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - closeDrawers, - handleSelectChannel, - viewChannel, - markChannelAsRead, - setChannelLoading - }, dispatch) - }; -} - -export default connect(mapStateToProps, mapDispatchToProps)(ChannelDrawer); diff --git a/app/scenes/channel_drawer/index.js b/app/scenes/channel_drawer/index.js index 7da872ef7..493308ab1 100644 --- a/app/scenes/channel_drawer/index.js +++ b/app/scenes/channel_drawer/index.js @@ -1,6 +1,40 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ChannelDrawerContainer from './channel_drawer_container'; +import {bindActionCreators} from 'redux'; +import {connect} from 'react-redux'; -export default ChannelDrawerContainer; +import {closeDrawers} from 'app/actions/navigation'; +import {handleSelectChannel, setChannelLoading} from 'app/actions/views/channel'; + +import {getChannelsByCategory, getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; +import {getTheme} from 'app/selectors/preferences'; +import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; + +import {viewChannel, markChannelAsRead} from 'mattermost-redux/actions/channels'; + +import ChannelDrawer from './channel_drawer.js'; + +function mapStateToProps(state) { + return { + currentTeam: getCurrentTeam(state), + currentChannel: getCurrentChannel(state), + channels: getChannelsByCategory(state), + channelMembers: state.entities.channels.myMembers, + theme: getTheme(state) + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + closeDrawers, + handleSelectChannel, + viewChannel, + markChannelAsRead, + setChannelLoading + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(ChannelDrawer); diff --git a/app/scenes/channel_info/channel_info_container.js b/app/scenes/channel_info/channel_info_container.js deleted file mode 100644 index aefbe5cd3..000000000 --- a/app/scenes/channel_info/channel_info_container.js +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import {goToChannelMembers, goToChannelAddMembers, goBack} from 'app/actions/navigation'; -import { - closeDMChannel, - closeGMChannel, - leaveChannel, - markFavorite, - unmarkFavorite -} from 'app/actions/views/channel'; -import navigationSceneConnect from 'app/scenes/navigationSceneConnect'; -import {getTheme} from 'app/selectors/preferences'; - -import {getChannelStats, deleteChannel} from 'mattermost-redux/actions/channels'; -import {Constants} from 'mattermost-redux/constants'; -import { - getCurrentChannel, - getCurrentChannelStats, - getChannelsByCategory, - canManageChannelMembers -} from 'mattermost-redux/selectors/entities/channels'; -import {getCurrentUserId, getUser, getStatusForUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users'; -import {getUserIdFromChannelName, showDeleteOption} from 'mattermost-redux/utils/channel_utils'; -import {isAdmin, isChannelAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; - -import ChannelInfo from './channel_info'; - -function mapStateToProps(state, ownProps) { - const {config, license} = state.entities.general; - const currentChannel = getCurrentChannel(state); - const currentChannelCreator = getUser(state, currentChannel.creator_id); - const currentChannelCreatorName = currentChannelCreator && currentChannelCreator.username; - const currentChannelMemberCount = getCurrentChannelStats(state) && getCurrentChannelStats(state).member_count; - const currentUserId = getCurrentUserId(state); - const favoriteChannels = getChannelsByCategory(state).favoriteChannels.map((f) => f.id); - const isCurrent = currentChannel.id === state.entities.channels.currentChannelId; - const isFavorite = favoriteChannels.indexOf(currentChannel.id) > -1; - const leaveChannelRequest = state.requests.channels.leaveChannel; - const roles = getCurrentUserRoles(state); - - let status; - if (currentChannel.type === Constants.DM_CHANNEL) { - const teammateId = getUserIdFromChannelName(currentUserId, currentChannel.name); - status = getStatusForUserId(state, teammateId); - } - - return { - ...ownProps, - canDeleteChannel: showDeleteOption(config, license, currentChannel, isAdmin(roles), isSystemAdmin(roles), isChannelAdmin(roles)), - currentTeamId: state.entities.teams.currentTeamId, - currentChannel, - currentChannelCreatorName, - currentChannelMemberCount, - isCurrent, - isFavorite, - leaveChannelRequest, - status, - theme: getTheme(state), - canManageUsers: canManageChannelMembers(state) - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - closeDMChannel, - closeGMChannel, - deleteChannel, - getChannelStats, - goBack, - goToChannelAddMembers, - goToChannelMembers, - leaveChannel, - markFavorite, - unmarkFavorite - }, dispatch) - }; -} - -export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(ChannelInfo); diff --git a/app/scenes/channel_info/index.js b/app/scenes/channel_info/index.js index 2c91e3647..aefbe5cd3 100644 --- a/app/scenes/channel_info/index.js +++ b/app/scenes/channel_info/index.js @@ -1,6 +1,83 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ChannelInfoContainer from './channel_info_container'; +import {bindActionCreators} from 'redux'; -export default ChannelInfoContainer; +import {goToChannelMembers, goToChannelAddMembers, goBack} from 'app/actions/navigation'; +import { + closeDMChannel, + closeGMChannel, + leaveChannel, + markFavorite, + unmarkFavorite +} from 'app/actions/views/channel'; +import navigationSceneConnect from 'app/scenes/navigationSceneConnect'; +import {getTheme} from 'app/selectors/preferences'; + +import {getChannelStats, deleteChannel} from 'mattermost-redux/actions/channels'; +import {Constants} from 'mattermost-redux/constants'; +import { + getCurrentChannel, + getCurrentChannelStats, + getChannelsByCategory, + canManageChannelMembers +} from 'mattermost-redux/selectors/entities/channels'; +import {getCurrentUserId, getUser, getStatusForUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users'; +import {getUserIdFromChannelName, showDeleteOption} from 'mattermost-redux/utils/channel_utils'; +import {isAdmin, isChannelAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; + +import ChannelInfo from './channel_info'; + +function mapStateToProps(state, ownProps) { + const {config, license} = state.entities.general; + const currentChannel = getCurrentChannel(state); + const currentChannelCreator = getUser(state, currentChannel.creator_id); + const currentChannelCreatorName = currentChannelCreator && currentChannelCreator.username; + const currentChannelMemberCount = getCurrentChannelStats(state) && getCurrentChannelStats(state).member_count; + const currentUserId = getCurrentUserId(state); + const favoriteChannels = getChannelsByCategory(state).favoriteChannels.map((f) => f.id); + const isCurrent = currentChannel.id === state.entities.channels.currentChannelId; + const isFavorite = favoriteChannels.indexOf(currentChannel.id) > -1; + const leaveChannelRequest = state.requests.channels.leaveChannel; + const roles = getCurrentUserRoles(state); + + let status; + if (currentChannel.type === Constants.DM_CHANNEL) { + const teammateId = getUserIdFromChannelName(currentUserId, currentChannel.name); + status = getStatusForUserId(state, teammateId); + } + + return { + ...ownProps, + canDeleteChannel: showDeleteOption(config, license, currentChannel, isAdmin(roles), isSystemAdmin(roles), isChannelAdmin(roles)), + currentTeamId: state.entities.teams.currentTeamId, + currentChannel, + currentChannelCreatorName, + currentChannelMemberCount, + isCurrent, + isFavorite, + leaveChannelRequest, + status, + theme: getTheme(state), + canManageUsers: canManageChannelMembers(state) + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + closeDMChannel, + closeGMChannel, + deleteChannel, + getChannelStats, + goBack, + goToChannelAddMembers, + goToChannelMembers, + leaveChannel, + markFavorite, + unmarkFavorite + }, dispatch) + }; +} + +export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(ChannelInfo); diff --git a/app/scenes/channel_members/channel_members_container.js b/app/scenes/channel_members/channel_members_container.js deleted file mode 100644 index 4c913c402..000000000 --- a/app/scenes/channel_members/channel_members_container.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import navigationSceneConnect from '../navigationSceneConnect'; - -import {goBack} from 'app/actions/navigation'; -import {handleRemoveChannelMembers} from 'app/actions/views/channel_members'; -import {getTheme} from 'app/selectors/preferences'; -import {getCurrentChannel, getCurrentChannelStats, canManageChannelMembers} from 'mattermost-redux/selectors/entities/channels'; -import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; -import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import {getProfilesInCurrentChannel} from 'mattermost-redux/selectors/entities/users'; -import {getProfilesInChannel, searchProfiles} from 'mattermost-redux/actions/users'; - -import ChannelMembers from './channel_members'; - -function mapStateToProps(state) { - const currentChannelMemberCount = getCurrentChannelStats(state) && getCurrentChannelStats(state).member_count; - - return { - theme: getTheme(state), - currentChannel: getCurrentChannel(state), - currentChannelMembers: getProfilesInCurrentChannel(state), - currentChannelMemberCount, - currentUserId: state.entities.users.currentUserId, - currentTeam: getCurrentTeam(state), - preferences: getMyPreferences(state), - requestStatus: state.requests.users.getProfilesInChannel.status, - searchRequestStatus: state.requests.users.searchProfiles.status, - removeMembersStatus: state.requests.channels.removeChannelMember.status, - canManageUsers: canManageChannelMembers(state) - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - getProfilesInChannel, - goBack, - handleRemoveChannelMembers, - searchProfiles - }, dispatch) - }; -} - -export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(ChannelMembers); diff --git a/app/scenes/channel_members/index.js b/app/scenes/channel_members/index.js index e1433009f..4c913c402 100644 --- a/app/scenes/channel_members/index.js +++ b/app/scenes/channel_members/index.js @@ -1,6 +1,48 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ChannelMembersContainer from './channel_members_container'; +import {bindActionCreators} from 'redux'; -export default ChannelMembersContainer; +import navigationSceneConnect from '../navigationSceneConnect'; + +import {goBack} from 'app/actions/navigation'; +import {handleRemoveChannelMembers} from 'app/actions/views/channel_members'; +import {getTheme} from 'app/selectors/preferences'; +import {getCurrentChannel, getCurrentChannelStats, canManageChannelMembers} from 'mattermost-redux/selectors/entities/channels'; +import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; +import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; +import {getProfilesInCurrentChannel} from 'mattermost-redux/selectors/entities/users'; +import {getProfilesInChannel, searchProfiles} from 'mattermost-redux/actions/users'; + +import ChannelMembers from './channel_members'; + +function mapStateToProps(state) { + const currentChannelMemberCount = getCurrentChannelStats(state) && getCurrentChannelStats(state).member_count; + + return { + theme: getTheme(state), + currentChannel: getCurrentChannel(state), + currentChannelMembers: getProfilesInCurrentChannel(state), + currentChannelMemberCount, + currentUserId: state.entities.users.currentUserId, + currentTeam: getCurrentTeam(state), + preferences: getMyPreferences(state), + requestStatus: state.requests.users.getProfilesInChannel.status, + searchRequestStatus: state.requests.users.searchProfiles.status, + removeMembersStatus: state.requests.channels.removeChannelMember.status, + canManageUsers: canManageChannelMembers(state) + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + getProfilesInChannel, + goBack, + handleRemoveChannelMembers, + searchProfiles + }, dispatch) + }; +} + +export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(ChannelMembers); diff --git a/app/scenes/index.js b/app/scenes/index.js index a722ead6f..b1094a32b 100644 --- a/app/scenes/index.js +++ b/app/scenes/index.js @@ -13,17 +13,17 @@ import CreateChannel from './create_channel'; import EditPost from './edit_post'; import ImagePreview from './image_preview'; import LoadTeam from './load_team'; -import Login from './login/login_container.js'; +import Login from './login'; import LoginOptions from './login_options'; import Mfa from './mfa'; import MoreChannels from './more_channels'; import MoreDirectMessages from './more_dms'; import OptionsModal from './options_modal'; import Settings from './settings'; -import Root from './root/root_container.js'; -import Search from './search/search_container.js'; -import SelectServer from './select_server/select_server_container.js'; -import SelectTeam from './select_team/select_team_container.js'; +import Root from './root'; +import Search from './search'; +import SelectServer from './select_server'; +import SelectTeam from './select_team'; import Thread from './thread'; import UserProfile from './user_profile'; import Saml from './saml'; diff --git a/app/scenes/load_team/index.js b/app/scenes/load_team/index.js index 9029a9bb3..83365c380 100644 --- a/app/scenes/load_team/index.js +++ b/app/scenes/load_team/index.js @@ -1,6 +1,40 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import LoadTeamContainer from './load_team_container'; +import {bindActionCreators} from 'redux'; -export default LoadTeamContainer; +import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; + +import {goToChannelView} from 'app/actions/views/load_team'; +import {clearNotification, goToNotification} from 'app/actions/views/root'; +import {handleTeamChange} from 'app/actions/views/select_team'; +import {getTheme} from 'app/selectors/preferences'; + +import navigationSceneConnect from '../navigationSceneConnect'; + +import LoadTeam from './load_team'; + +function mapStateToProps(state) { + return { + config: state.entities.general.config, + theme: getTheme(state), + teamsRequest: state.requests.teams.allTeams, + teams: state.entities.teams.teams, + currentTeam: getCurrentTeam(state), + myMembers: state.entities.teams.myMembers, + notification: state.views.notification + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + clearNotification, + goToChannelView, + goToNotification, + handleTeamChange + }, dispatch) + }; +} + +export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(LoadTeam); diff --git a/app/scenes/load_team/load_team.js b/app/scenes/load_team/load_team.js index afb25d010..6b1041db6 100644 --- a/app/scenes/load_team/load_team.js +++ b/app/scenes/load_team/load_team.js @@ -27,7 +27,7 @@ export default class LoadTeam extends PureComponent { static navigationProps = { renderBackButton: () => null, renderTitleComponent: () => null - } + }; componentDidMount() { const {notification, currentTeam, myMembers, teams} = this.props; @@ -60,7 +60,8 @@ export default class LoadTeam extends PureComponent { } onSelectTeam(team) { - this.props.actions.handleTeamChange(team).then(this.props.actions.goToChannelView); + const {handleTeamChange, goToChannelView} = this.props.actions; + handleTeamChange(team).then(goToChannelView); } render() { diff --git a/app/scenes/load_team/load_team_container.js b/app/scenes/load_team/load_team_container.js deleted file mode 100644 index 8ca836539..000000000 --- a/app/scenes/load_team/load_team_container.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; - -import {goToChannelView} from 'app/actions/views/load_team'; -import {clearNotification, goToNotification} from 'app/actions/views/root'; -import {handleTeamChange} from 'app/actions/views/select_team'; -import {getTheme} from 'app/selectors/preferences'; - -import navigationSceneConnect from '../navigationSceneConnect'; - -import LoadTeam from './load_team.js'; - -function mapStateToProps(state) { - return { - config: state.entities.general.config, - theme: getTheme(state), - teamsRequest: state.requests.teams.allTeams, - teams: state.entities.teams.teams, - currentTeam: getCurrentTeam(state), - myMembers: state.entities.teams.myMembers, - notification: state.views.notification - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - clearNotification, - goToChannelView, - goToNotification, - handleTeamChange - }, dispatch) - }; -} - -export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(LoadTeam); diff --git a/app/scenes/login/login_container.js b/app/scenes/login/index.js similarity index 100% rename from app/scenes/login/login_container.js rename to app/scenes/login/index.js diff --git a/app/scenes/mfa/index.js b/app/scenes/mfa/index.js index 6d4071d9a..892c17d4b 100644 --- a/app/scenes/mfa/index.js +++ b/app/scenes/mfa/index.js @@ -1,6 +1,32 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import MfaContainer from './mfa_container'; +import {bindActionCreators} from 'redux'; -export default MfaContainer; +import navigationSceneConnect from '../navigationSceneConnect'; + +import {goBack} from 'app/actions/navigation'; +import {login} from 'mattermost-redux/actions/users'; + +import Mfa from './mfa'; + +function mapStateToProps(state) { + const {login: loginRequest} = state.requests.users; + const {loginId, password} = state.views.login; + return { + loginId, + password, + loginRequest + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + goBack, + login + }, dispatch) + }; +} + +export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(Mfa); diff --git a/app/scenes/mfa/mfa_container.js b/app/scenes/mfa/mfa_container.js deleted file mode 100644 index 892c17d4b..000000000 --- a/app/scenes/mfa/mfa_container.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import navigationSceneConnect from '../navigationSceneConnect'; - -import {goBack} from 'app/actions/navigation'; -import {login} from 'mattermost-redux/actions/users'; - -import Mfa from './mfa'; - -function mapStateToProps(state) { - const {login: loginRequest} = state.requests.users; - const {loginId, password} = state.views.login; - return { - loginId, - password, - loginRequest - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - goBack, - login - }, dispatch) - }; -} - -export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(Mfa); diff --git a/app/scenes/root/root_container.js b/app/scenes/root/index.js similarity index 90% rename from app/scenes/root/root_container.js rename to app/scenes/root/index.js index 99dc690a5..fcc350feb 100644 --- a/app/scenes/root/root_container.js +++ b/app/scenes/root/index.js @@ -9,7 +9,7 @@ import {goToSelectServer} from 'app/actions/views/root'; import {handleServerUrlChanged} from 'app/actions/views/select_server'; import {goToLoadTeam} from 'app/actions/navigation'; -import {setStoreFromLocalData} from 'mattermost-redux/actions/general'; +import {loadMe} from 'mattermost-redux/actions/users'; import Root from './root'; @@ -29,7 +29,7 @@ function mapDispatchToProps(dispatch) { goToLoadTeam, goToSelectServer, handleServerUrlChanged, - setStoreFromLocalData + loadMe }, dispatch) }; } diff --git a/app/scenes/root/root.js b/app/scenes/root/root.js index 875658da3..2fc26eacd 100644 --- a/app/scenes/root/root.js +++ b/app/scenes/root/root.js @@ -5,6 +5,7 @@ import React, {PropTypes, PureComponent} from 'react'; import Orientation from 'react-native-orientation'; import Loading from 'app/components/loading'; +import Client from 'mattermost-redux/client'; import {RequestStatus} from 'mattermost-redux/constants'; import SplashScreen from 'react-native-smart-splash-screen'; @@ -17,9 +18,8 @@ export default class Root extends PureComponent { goToLoadTeam: PropTypes.func, goToSelectServer: PropTypes.func, handleServerUrlChanged: PropTypes.func.isRequired, - setStoreFromLocalData: PropTypes.func - }).isRequired, - hydrationComplete: PropTypes.bool.isRequired + loadMe: PropTypes.func + }).isRequired }; static navigationProps = { @@ -53,18 +53,22 @@ export default class Root extends PureComponent { }; loadStoreAndScene = (credentials = {}) => { + const {actions, loginRequest} = this.props; + const {goToLoadTeam, goToSelectServer, loadMe} = actions; if (credentials.token && credentials.url) { // Will probably need to make this optimistic since we // assume that the stored token is good. - this.props.actions.setStoreFromLocalData(credentials); - this.props.actions.goToLoadTeam(); - } else { - this.selectServer(); - } - }; + if (loginRequest.status === RequestStatus.NOT_STARTED) { + Client.setToken(credentials.token); + Client.setUrl(credentials.url); - selectServer = async () => { - this.props.actions.goToSelectServer(); + loadMe().then(goToLoadTeam).catch(goToLoadTeam); + } else { + goToLoadTeam(); + } + } else { + goToSelectServer(); + } }; render() { diff --git a/app/scenes/search/search_container.js b/app/scenes/search/index.js similarity index 100% rename from app/scenes/search/search_container.js rename to app/scenes/search/index.js diff --git a/app/scenes/select_server/select_server_container.js b/app/scenes/select_server/index.js similarity index 100% rename from app/scenes/select_server/select_server_container.js rename to app/scenes/select_server/index.js diff --git a/app/scenes/select_team/select_team_container.js b/app/scenes/select_team/index.js similarity index 100% rename from app/scenes/select_team/select_team_container.js rename to app/scenes/select_team/index.js diff --git a/app/scenes/thread/index.js b/app/scenes/thread/index.js index 131dd3e84..aa3dde39d 100644 --- a/app/scenes/thread/index.js +++ b/app/scenes/thread/index.js @@ -1,6 +1,56 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import ThreadContainer from './thread_container'; +import {bindActionCreators} from 'redux'; -export default ThreadContainer; +import {handleCommentDraftChanged} from 'app/actions/views/thread'; +import {selectPost} from 'mattermost-redux/actions/posts'; + +import {makeGetPostsForThread} from 'mattermost-redux/selectors/entities/posts'; +import {getTheme} from 'app/selectors/preferences'; +import {getCurrentChannelMembership} from 'mattermost-redux/selectors/entities/channels'; +import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; + +import navigationSceneConnect from '../navigationSceneConnect'; +import Thread from './thread'; + +function makeMapStateToProps() { + // Create a getPostsForThread selector for each instance of Thread so that each Thread + // is memoized correctly based on its own props + const getPostsForThread = makeGetPostsForThread(); + + return function mapStateToProps(state, ownProps) { + const posts = getPostsForThread(state, ownProps); + + let teamId = state.entities.channels.channels[ownProps.channelId].team_id; + if (!teamId) { + // We can't make a post without a team id, so get it from the current team + teamId = getCurrentTeamId(state); + } + + const threadDraft = state.views.thread.drafts[ownProps.rootId]; + + return { + ...ownProps, + teamId, + channelId: ownProps.channelId, + myMember: getCurrentChannelMembership(state), + rootId: ownProps.rootId, + draft: threadDraft.draft, + files: threadDraft.files, + posts, + theme: getTheme(state) + }; + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + handleCommentDraftChanged, + selectPost + }, dispatch) + }; +} + +export default navigationSceneConnect(makeMapStateToProps, mapDispatchToProps)(Thread); diff --git a/app/scenes/thread/thread_container.js b/app/scenes/thread/thread_container.js deleted file mode 100644 index aa3dde39d..000000000 --- a/app/scenes/thread/thread_container.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import {handleCommentDraftChanged} from 'app/actions/views/thread'; -import {selectPost} from 'mattermost-redux/actions/posts'; - -import {makeGetPostsForThread} from 'mattermost-redux/selectors/entities/posts'; -import {getTheme} from 'app/selectors/preferences'; -import {getCurrentChannelMembership} from 'mattermost-redux/selectors/entities/channels'; -import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; - -import navigationSceneConnect from '../navigationSceneConnect'; -import Thread from './thread'; - -function makeMapStateToProps() { - // Create a getPostsForThread selector for each instance of Thread so that each Thread - // is memoized correctly based on its own props - const getPostsForThread = makeGetPostsForThread(); - - return function mapStateToProps(state, ownProps) { - const posts = getPostsForThread(state, ownProps); - - let teamId = state.entities.channels.channels[ownProps.channelId].team_id; - if (!teamId) { - // We can't make a post without a team id, so get it from the current team - teamId = getCurrentTeamId(state); - } - - const threadDraft = state.views.thread.drafts[ownProps.rootId]; - - return { - ...ownProps, - teamId, - channelId: ownProps.channelId, - myMember: getCurrentChannelMembership(state), - rootId: ownProps.rootId, - draft: threadDraft.draft, - files: threadDraft.files, - posts, - theme: getTheme(state) - }; - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - handleCommentDraftChanged, - selectPost - }, dispatch) - }; -} - -export default navigationSceneConnect(makeMapStateToProps, mapDispatchToProps)(Thread); diff --git a/app/scenes/user_profile/index.js b/app/scenes/user_profile/index.js index e024383a2..ee4acc87c 100644 --- a/app/scenes/user_profile/index.js +++ b/app/scenes/user_profile/index.js @@ -1,6 +1,33 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import UserProfileContainer from './user_profile_container'; +import {bindActionCreators} from 'redux'; -export default UserProfileContainer; +import {handleSendMessage} from 'app/actions/views/user_profile'; +import navigationSceneConnect from 'app/scenes/navigationSceneConnect'; +import {getTheme} from 'app/selectors/preferences'; + +import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; + +import UserProfile from './user_profile'; + +function mapStateToProps(state, ownProps) { + const {config} = state.entities.general; + + return { + config, + currentUserId: getCurrentUserId(state), + user: state.entities.users.profiles[ownProps.userId], + theme: getTheme(state) + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + handleSendMessage + }, dispatch) + }; +} + +export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(UserProfile); diff --git a/app/scenes/user_profile/user_profile_container.js b/app/scenes/user_profile/user_profile_container.js deleted file mode 100644 index ee4acc87c..000000000 --- a/app/scenes/user_profile/user_profile_container.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; - -import {handleSendMessage} from 'app/actions/views/user_profile'; -import navigationSceneConnect from 'app/scenes/navigationSceneConnect'; -import {getTheme} from 'app/selectors/preferences'; - -import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; - -import UserProfile from './user_profile'; - -function mapStateToProps(state, ownProps) { - const {config} = state.entities.general; - - return { - config, - currentUserId: getCurrentUserId(state), - user: state.entities.users.profiles[ownProps.userId], - theme: getTheme(state) - }; -} - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({ - handleSendMessage - }, dispatch) - }; -} - -export default navigationSceneConnect(mapStateToProps, mapDispatchToProps)(UserProfile);