2021-02-23 20:34:28 +00:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
import React, { CSSProperties } from 'react';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { mapDispatchToProps } from '../actions';
|
2021-02-23 20:34:28 +00:00
|
|
|
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';
|
2021-02-23 20:34:28 +00:00
|
|
|
import { getIntl, getRegionCode } from '../selectors/user';
|
2019-11-07 21:36:16 +00:00
|
|
|
import {
|
2021-02-23 20:34:28 +00:00
|
|
|
getComposeContacts,
|
|
|
|
getComposerContactSearchTerm,
|
2019-11-07 21:36:16 +00:00
|
|
|
getLeftPaneLists,
|
2021-02-12 21:58:14 +00:00
|
|
|
getSelectedConversationId,
|
2021-02-23 20:34:28 +00:00
|
|
|
getSelectedMessage,
|
2019-11-07 21:36:16 +00:00
|
|
|
getShowArchived,
|
2021-02-23 20:34:28 +00:00
|
|
|
isComposing,
|
2019-11-07 21:36:16 +00:00
|
|
|
} from '../selectors/conversations';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
import { SmartExpiredBuildDialog } from './ExpiredBuildDialog';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { SmartMainHeader } from './MainHeader';
|
2019-08-09 00:46:49 +00:00
|
|
|
import { SmartMessageSearchResult } from './MessageSearchResult';
|
2020-02-12 21:30:58 +00:00
|
|
|
import { SmartNetworkStatus } from './NetworkStatus';
|
2020-04-16 19:20:52 +00:00
|
|
|
import { SmartRelinkDialog } from './RelinkDialog';
|
2020-02-12 21:30:58 +00:00
|
|
|
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
|
2020-09-14 21:56:35 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2019-08-09 00:46:49 +00:00
|
|
|
const FilteredSmartMessageSearchResult = SmartMessageSearchResult as any;
|
2020-09-14 21:56:35 +00:00
|
|
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
function renderExpiredBuildDialog(): JSX.Element {
|
2020-10-26 21:32:46 +00:00
|
|
|
return <SmartExpiredBuildDialog />;
|
2020-02-12 21:30:58 +00:00
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
function renderMainHeader(): JSX.Element {
|
2020-10-26 21:32:46 +00:00
|
|
|
return <SmartMainHeader />;
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
function renderMessageSearchResult(
|
|
|
|
id: string,
|
|
|
|
style: CSSProperties
|
|
|
|
): JSX.Element {
|
|
|
|
return <FilteredSmartMessageSearchResult id={id} style={style} />;
|
2019-08-09 00:46:49 +00:00
|
|
|
}
|
2020-02-12 21:30:58 +00:00
|
|
|
function renderNetworkStatus(): JSX.Element {
|
2020-10-26 21:32:46 +00:00
|
|
|
return <SmartNetworkStatus />;
|
2020-02-12 21:30:58 +00:00
|
|
|
}
|
2020-04-16 19:20:52 +00:00
|
|
|
function renderRelinkDialog(): JSX.Element {
|
2020-10-26 21:32:46 +00:00
|
|
|
return <SmartRelinkDialog />;
|
2020-04-16 19:20:52 +00:00
|
|
|
}
|
|
|
|
function renderUpdateDialog(): JSX.Element {
|
2020-10-26 21:32:46 +00:00
|
|
|
return <SmartUpdateDialog />;
|
2020-04-16 19:20:52 +00:00
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
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
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
return {
|
|
|
|
mode: LeftPaneMode.Inbox,
|
|
|
|
...getLeftPaneLists(state),
|
|
|
|
};
|
|
|
|
};
|
2019-03-12 00:20:16 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
const mapStateToProps = (state: StateType) => {
|
2019-01-14 21:49:58 +00:00
|
|
|
return {
|
2021-02-23 20:34:28 +00:00
|
|
|
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),
|
2021-02-23 20:34:28 +00:00
|
|
|
regionCode: getRegionCode(state),
|
2020-02-12 21:30:58 +00:00
|
|
|
renderExpiredBuildDialog,
|
2019-05-31 22:42:01 +00:00
|
|
|
renderMainHeader,
|
2019-08-09 00:46:49 +00:00
|
|
|
renderMessageSearchResult,
|
2020-02-12 21:30:58 +00:00
|
|
|
renderNetworkStatus,
|
2020-04-16 19:20:52 +00:00
|
|
|
renderRelinkDialog,
|
2020-02-12 21:30:58 +00:00
|
|
|
renderUpdateDialog,
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
export const SmartLeftPane = smart(LeftPane);
|