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

114 lines
3.2 KiB
TypeScript
Raw Normal View History

// Copyright 2019-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { CSSProperties } from 'react';
2019-01-14 21:49:58 +00:00
import { connect } from 'react-redux';
import { mapDispatchToProps } from '../actions';
import {
LeftPane,
LeftPaneMode,
PropsType as LeftPanePropsType,
} from '../../components/LeftPane';
2019-01-14 21:49:58 +00:00
import { StateType } from '../reducer';
2019-03-12 00:20:16 +00:00
import { getSearchResults, isSearching } from '../selectors/search';
import { getIntl, getRegionCode } from '../selectors/user';
2019-11-07 21:36:16 +00:00
import {
getComposeContacts,
getComposerContactSearchTerm,
2019-11-07 21:36:16 +00:00
getLeftPaneLists,
getSelectedConversationId,
getSelectedMessage,
2019-11-07 21:36:16 +00:00
getShowArchived,
isComposing,
2019-11-07 21:36:16 +00:00
} 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,
style: CSSProperties
): JSX.Element {
return <FilteredSmartMessageSearchResult id={id} style={style} />;
}
function renderNetworkStatus(): JSX.Element {
return <SmartNetworkStatus />;
}
function renderRelinkDialog(): JSX.Element {
return <SmartRelinkDialog />;
}
function renderUpdateDialog(): JSX.Element {
return <SmartUpdateDialog />;
}
const getModeSpecificProps = (
state: StateType
): LeftPanePropsType['modeSpecificProps'] => {
if (isComposing(state)) {
return {
mode: LeftPaneMode.Compose,
composeContacts: getComposeContacts(state),
regionCode: getRegionCode(state),
searchTerm: getComposerContactSearchTerm(state),
};
}
if (getShowArchived(state)) {
const { archivedConversations } = getLeftPaneLists(state);
return {
mode: LeftPaneMode.Archive,
archivedConversations,
};
}
if (isSearching(state)) {
return {
mode: LeftPaneMode.Search,
...getSearchResults(state),
};
}
2019-01-14 21:49:58 +00:00
return {
mode: LeftPaneMode.Inbox,
...getLeftPaneLists(state),
};
};
2019-03-12 00:20:16 +00:00
const mapStateToProps = (state: StateType) => {
2019-01-14 21:49:58 +00:00
return {
modeSpecificProps: getModeSpecificProps(state),
selectedConversationId: getSelectedConversationId(state),
selectedMessageId: getSelectedMessage(state)?.id,
2019-03-12 00:20:16 +00:00
showArchived: getShowArchived(state),
2019-01-14 21:49:58 +00:00
i18n: getIntl(state),
regionCode: getRegionCode(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);