signal-desktop/ts/state/smart/LeftPane.tsx

72 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-01-14 21:49:58 +00:00
import React from 'react';
import { connect } from 'react-redux';
import { mapDispatchToProps } from '../actions';
import { LeftPane } from '../../components/LeftPane';
import { StateType } from '../reducer';
2019-03-12 00:20:16 +00:00
import { getSearchResults, isSearching } from '../selectors/search';
2019-01-14 21:49:58 +00:00
import { getIntl } from '../selectors/user';
2019-11-07 21:36:16 +00:00
import {
getLeftPaneLists,
getSelectedConversation,
getShowArchived,
} from '../selectors/conversations';
2019-01-14 21:49:58 +00:00
import { SmartExpiredBuildDialog } from './ExpiredBuildDialog';
2019-01-14 21:49:58 +00:00
import { SmartMainHeader } from './MainHeader';
import { SmartMessageSearchResult } from './MessageSearchResult';
import { SmartNetworkStatus } from './NetworkStatus';
import { SmartRelinkDialog } from './RelinkDialog';
import { SmartUpdateDialog } from './UpdateDialog';
2019-01-14 21:49:58 +00:00
// Workaround: A react component's required properties are filtering up through connect()
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31363
/* eslint-disable @typescript-eslint/no-explicit-any */
const FilteredSmartMessageSearchResult = SmartMessageSearchResult as any;
/* eslint-enable @typescript-eslint/no-explicit-any */
2019-01-14 21:49:58 +00:00
function renderExpiredBuildDialog(): JSX.Element {
return <SmartExpiredBuildDialog />;
}
function renderMainHeader(): JSX.Element {
return <SmartMainHeader />;
}
function renderMessageSearchResult(id: string): JSX.Element {
return <FilteredSmartMessageSearchResult id={id} />;
}
function renderNetworkStatus(): JSX.Element {
return <SmartNetworkStatus />;
}
function renderRelinkDialog(): JSX.Element {
return <SmartRelinkDialog />;
}
function renderUpdateDialog(): JSX.Element {
return <SmartUpdateDialog />;
}
2019-01-14 21:49:58 +00:00
const mapStateToProps = (state: StateType) => {
const showSearch = isSearching(state);
2019-03-12 00:20:16 +00:00
const lists = showSearch ? undefined : getLeftPaneLists(state);
const searchResults = showSearch ? getSearchResults(state) : undefined;
2019-11-07 21:36:16 +00:00
const selectedConversationId = getSelectedConversation(state);
2019-03-12 00:20:16 +00:00
2019-01-14 21:49:58 +00:00
return {
2019-03-12 00:20:16 +00:00
...lists,
searchResults,
2019-11-07 21:36:16 +00:00
selectedConversationId,
2019-03-12 00:20:16 +00:00
showArchived: getShowArchived(state),
2019-01-14 21:49:58 +00:00
i18n: getIntl(state),
renderExpiredBuildDialog,
renderMainHeader,
renderMessageSearchResult,
renderNetworkStatus,
renderRelinkDialog,
renderUpdateDialog,
2019-01-14 21:49:58 +00:00
};
};
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartLeftPane = smart(LeftPane);