Unverified Commit a3b98ac9 authored by Elias Nahum's avatar Elias Nahum Committed by GitHub
Browse files

Fix pinned post list from refreshing (#2042)

* Fix pinned post list from refreshing

* Fix show post for the current channel when the channel is switched
parent 59ed7ced
......@@ -3,18 +3,13 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getMorePostsForSearch} from 'mattermost-redux/actions/search';
import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getSearchMatches, getSearchResults} from 'mattermost-redux/selectors/entities/posts';
import * as PreferenceSelectors from 'mattermost-redux/selectors/entities/preferences';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getMorePostsForSearch} from 'mattermost-redux/actions/search';
import {
getCurrentUser,
getUsers,
getUserStatuses,
} from 'mattermost-redux/selectors/entities/users';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
import {
getSearchResultsTerms,
......@@ -27,14 +22,9 @@ import {Preferences} from 'utils/constants.jsx';
import SearchResults from './search_results.jsx';
const getCategory = PreferenceSelectors.makeGetCategory();
function makeMapStateToProps() {
let results;
let posts;
let channels;
let flaggedPosts;
let isFlaggedByPostId;
return function mapStateToProps(state) {
const config = getConfig(state);
......@@ -49,22 +39,13 @@ function makeMapStateToProps() {
if (newResults && newResults !== results) {
results = newResults;
channels = new Map();
posts = [];
results.forEach((post) => {
if (!post) {
return;
}
let channel;
if (channels.has(post.channel_id)) {
channel = channels.get(post.channel_id);
} else {
channel = getChannel(state, post.channel_id);
channels.set(post.channel_id, channel);
}
const channel = getChannel(state, post.channel_id);
if (channel && channel.delete_at !== 0 && !viewArchivedChannels) {
return;
}
......@@ -73,28 +54,11 @@ function makeMapStateToProps() {
});
}
const newFlaggedPosts = getCategory(state, Preferences.CATEGORY_FLAGGED_POST);
// Cache flagged posts map
if (newFlaggedPosts !== flaggedPosts) {
flaggedPosts = newFlaggedPosts;
isFlaggedByPostId = new Map();
for (const pref of flaggedPosts) {
isFlaggedByPostId.set(pref.name, true);
}
}
return {
results: posts,
matches: getSearchMatches(state),
profiles: getUsers(state),
statuses: getUserStatuses(state),
currentUser: getCurrentUser(state),
channels,
searchTerms: getSearchResultsTerms(state),
isFlaggedByPostId,
isSearchingTerm: getIsSearchingTerm(state),
isSearchingFlaggedPost: getIsSearchingFlaggedPost(state),
isSearchingPinnedPost: getIsSearchingPinnedPost(state),
......
......@@ -48,12 +48,8 @@ export default class SearchResults extends React.PureComponent {
static propTypes = {
results: PropTypes.array,
matches: PropTypes.object,
profiles: PropTypes.object,
statuses: PropTypes.object,
currentUser: PropTypes.object,
channels: PropTypes.object,
searchTerms: PropTypes.string,
isFlaggedByPostId: PropTypes.object,
isSearchingTerm: PropTypes.bool,
isSearchingFlaggedPost: PropTypes.bool,
isSearchingPinnedPost: PropTypes.bool,
......@@ -129,8 +125,6 @@ export default class SearchResults extends React.PureComponent {
const results = this.props.results;
const noResults = (!results || results.length === 0);
const searchTerms = this.props.searchTerms;
const profiles = this.props.profiles || {};
const statuses = this.props.statuses || {};
let ctls = null;
......@@ -196,38 +190,17 @@ export default class SearchResults extends React.PureComponent {
}
ctls = sortedResults.map((post, idx, arr) => {
let profile;
if (this.props.currentUser.id === post.user_id) {
profile = this.props.currentUser;
} else {
profile = profiles[post.user_id];
}
let status = 'offline';
if (statuses) {
status = statuses[post.user_id] || 'offline';
}
let isFlagged = false;
if (this.props.isFlaggedByPostId) {
isFlagged = this.props.isFlaggedByPostId.get(post.id) || false;
}
const reverseCount = arr.length - idx - 1;
return (
<SearchResultsItem
key={post.id}
channel={this.props.channels.get(post.channel_id)}
compactDisplay={this.props.compactDisplay}
post={post}
matches={this.props.matches[post.id]}
lastPostCount={(reverseCount >= 0 && reverseCount < Constants.TEST_ID_COUNT) ? reverseCount : -1}
user={profile}
term={(!this.props.isFlaggedPosts && !this.props.isPinnedPosts && !this.props.isMentionSearch) ? searchTerms : ''}
isMentionSearch={this.props.isMentionSearch}
isFlagged={isFlagged}
status={status}
/>
);
}, this);
......
......@@ -3,9 +3,13 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {makeGetCommentCountForPost} from 'mattermost-redux/selectors/entities/posts';
import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {makeGetCommentCountForPost} from 'mattermost-redux/selectors/entities/posts';
import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {getUser, getStatusForUserId} from 'mattermost-redux/selectors/entities/users';
import {isPostFlagged} from 'mattermost-redux/utils/post_utils';
import {
closeRightHandSide,
......@@ -20,12 +24,18 @@ function mapStateToProps() {
return (state, ownProps) => {
const config = getConfig(state);
const preferences = getMyPreferences(state);
const enablePostUsernameOverride = config.EnablePostUsernameOverride === 'true';
const {post} = ownProps;
return {
channel: getChannel(state, post.channel_id),
currentTeamName: getCurrentTeam(state).name,
commentCountForPost: getCommentCountForPost(state, {post: ownProps.post}),
commentCountForPost: getCommentCountForPost(state, {post}),
enablePostUsernameOverride,
isFlagged: isPostFlagged(post.id, preferences),
user: getUser(state, post.user_id),
status: getStatusForUserId(state, post.user_id) || 'offline',
};
};
}
......
......@@ -7,7 +7,7 @@ import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {getPost} from 'mattermost-redux/selectors/entities/posts';
import {getPinnedPosts, setRhsExpanded, showPinnedPosts} from 'actions/views/rhs';
import {setRhsExpanded, showPinnedPosts} from 'actions/views/rhs';
import {
getIsRhsExpanded,
getIsRhsOpen,
......@@ -57,7 +57,6 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
getPinnedPosts,
setRhsExpanded,
showPinnedPosts,
}, dispatch),
......
......@@ -27,7 +27,6 @@ export default class SidebarRight extends React.PureComponent {
isPinnedPosts: PropTypes.bool,
previousRhsState: PropTypes.string,
actions: PropTypes.shape({
getPinnedPosts: PropTypes.func.isRequired,
setRhsExpanded: PropTypes.func.isRequired,
showPinnedPosts: PropTypes.func.isRequired,
}),
......@@ -41,6 +40,11 @@ export default class SidebarRight extends React.PureComponent {
trackEvent('ui', 'ui_rhs_opened');
setTimeout(postListScrollChange, 0);
}
const {actions, isPinnedPosts, channel} = this.props;
if (isPinnedPosts && prevProps.isPinnedPosts === isPinnedPosts && channel.id !== prevProps.channel.id) {
actions.showPinnedPosts(channel.id);
}
}
onShrink = () => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment