mattermost-mobile/app/screens/search/index.js
Miguel Alatzar 2d81b497cf [MM-23520] Port mattermost-redux (#4088)
* Remove mattermost-redux

* Move mm-redux files into app/redux

* Add @redux path to tsconfig.json

* Fix imports

* Install missing dependencies

* Fix tsc errors

* Fix i18n_utils test

* Fix more imports

* Remove redux websocket

* Fix tests

* Rename @redux

* Apply changes from mattermost-redux PR 1103

* Remove mattermost-redux mention in template

* Add missing imports

* Rename app/redux/ to app/mm-redux/

* Remove test file

* Fix fetching Sidebar GM profiles

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-17 21:12:09 -07:00

89 lines
3.6 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {selectFocusedPostId, selectPost} from '@mm-redux/actions/posts';
import {clearSearch, removeSearchTerms, searchPostsWithParams, getMorePostsForSearch} from '@mm-redux/actions/search';
import {getCurrentChannelId, filterPostIds} from '@mm-redux/selectors/entities/channels';
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams';
import {getConfig} from '@mm-redux/selectors/entities/general';
import {getTheme} from '@mm-redux/selectors/entities/preferences';
import {isTimezoneEnabled} from '@mm-redux/selectors/entities/timezone';
import {isMinimumServerVersion} from '@mm-redux/utils/helpers';
import {getUserCurrentTimezone} from '@mm-redux/utils/timezone_utils';
import {getCurrentUser} from '@mm-redux/selectors/entities/users';
import {loadChannelsByTeamName, loadThreadIfNecessary} from 'app/actions/views/channel';
import {handleSearchDraftChanged} from 'app/actions/views/search';
import {isLandscape} from 'app/selectors/device';
import {makePreparePostIdsForSearchPosts} from 'app/selectors/post_list';
import {getDeviceUtcOffset, getUtcOffsetForTimeZone} from 'app/utils/timezone';
import Search from './search';
function makeMapStateToProps() {
const preparePostIds = makePreparePostIdsForSearchPosts();
const filterPostIdsByDeletedChannels = filterPostIds((c) => c && c.delete_at !== 0);
return (state) => {
const config = getConfig(state);
let results = state.entities.search.results;
const archivedPostIds = filterPostIdsByDeletedChannels(state, results || []);
const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true';
if (!viewArchivedChannels && results && results.length > 0) {
results = results.filter((id) => !archivedPostIds.includes(id));
}
const postIds = preparePostIds(state, results);
const currentTeamId = getCurrentTeamId(state);
const currentChannelId = getCurrentChannelId(state);
const {recent} = state.entities.search;
const currentUser = getCurrentUser(state);
const enableTimezone = isTimezoneEnabled(state);
const userCurrentTimezone = enableTimezone ? getUserCurrentTimezone(currentUser.timezone) : '';
const timezoneOffsetInSeconds = (userCurrentTimezone.length > 0 ? getUtcOffsetForTimeZone(userCurrentTimezone) : getDeviceUtcOffset()) * 60;
const serverVersion = state.entities.general.serverVersion;
const enableDateSuggestion = isMinimumServerVersion(serverVersion, 5, 3);
const isSearchGettingMore = state.entities.search.isSearchGettingMore;
return {
currentTeamId,
currentChannelId,
isLandscape: isLandscape(state),
postIds,
archivedPostIds,
recent: recent[currentTeamId],
isSearchGettingMore,
theme: getTheme(state),
enableDateSuggestion,
timezoneOffsetInSeconds,
viewArchivedChannels,
};
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
clearSearch,
handleSearchDraftChanged,
loadChannelsByTeamName,
loadThreadIfNecessary,
removeSearchTerms,
selectFocusedPostId,
searchPostsWithParams,
getMorePostsForSearch,
selectPost,
}, dispatch),
};
}
export default connect(makeMapStateToProps, mapDispatchToProps)(Search);