Converts ConversationHeader to useSelector
This commit is contained in:
parent
d8eaf896b9
commit
21daacd86d
2 changed files with 110 additions and 50 deletions
|
@ -14,6 +14,8 @@ import type {
|
||||||
} from '../../sql/Interface';
|
} from '../../sql/Interface';
|
||||||
import dataInterface from '../../sql/Client';
|
import dataInterface from '../../sql/Client';
|
||||||
import { makeLookup } from '../../util/makeLookup';
|
import { makeLookup } from '../../util/makeLookup';
|
||||||
|
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
||||||
|
import { useBoundActions } from '../../hooks/useBoundActions';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ConversationType,
|
ConversationType,
|
||||||
|
@ -136,6 +138,10 @@ export const actions = {
|
||||||
updateSearchTerm,
|
updateSearchTerm,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useSearchActions = (): BoundActionCreatorsMapObject<
|
||||||
|
typeof actions
|
||||||
|
> => useBoundActions(actions);
|
||||||
|
|
||||||
function startSearch(): StartSearchActionType {
|
function startSearch(): StartSearchActionType {
|
||||||
return {
|
return {
|
||||||
type: 'SEARCH_START',
|
type: 'SEARCH_START',
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// Copyright 2020 Signal Messenger, LLC
|
// Copyright 2020 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { connect } from 'react-redux';
|
import React from 'react';
|
||||||
|
import { useSelector } from 'react-redux';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
import type { ConversationType } from '../ducks/conversations';
|
import type { ConversationType } from '../ducks/conversations';
|
||||||
import type { StateType } from '../reducer';
|
import type { StateType } from '../reducer';
|
||||||
|
@ -16,16 +17,24 @@ import {
|
||||||
isMissingRequiredProfileSharing,
|
isMissingRequiredProfileSharing,
|
||||||
} from '../selectors/conversations';
|
} from '../selectors/conversations';
|
||||||
import { CallMode } from '../../types/Calling';
|
import { CallMode } from '../../types/Calling';
|
||||||
import { getActiveCall, isAnybodyElseInGroupCall } from '../ducks/calling';
|
import {
|
||||||
import { getConversationCallMode } from '../ducks/conversations';
|
getActiveCall,
|
||||||
|
isAnybodyElseInGroupCall,
|
||||||
|
useCallingActions,
|
||||||
|
} from '../ducks/calling';
|
||||||
|
import {
|
||||||
|
getConversationCallMode,
|
||||||
|
useConversationsActions,
|
||||||
|
} from '../ducks/conversations';
|
||||||
import { getHasStoriesSelector } from '../selectors/stories2';
|
import { getHasStoriesSelector } from '../selectors/stories2';
|
||||||
import { getOwn } from '../../util/getOwn';
|
import { getOwn } from '../../util/getOwn';
|
||||||
import { getUserACI, getIntl, getTheme } from '../selectors/user';
|
import { getUserACI, getIntl, getTheme } from '../selectors/user';
|
||||||
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
|
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
|
||||||
import { mapDispatchToProps } from '../actions';
|
|
||||||
import { missingCaseError } from '../../util/missingCaseError';
|
import { missingCaseError } from '../../util/missingCaseError';
|
||||||
import { strictAssert } from '../../util/assert';
|
import { strictAssert } from '../../util/assert';
|
||||||
import { isSignalConversation } from '../../util/isSignalConversation';
|
import { isSignalConversation } from '../../util/isSignalConversation';
|
||||||
|
import { useSearchActions } from '../ducks/search';
|
||||||
|
import { useStoriesActions } from '../ducks/stories';
|
||||||
|
|
||||||
export type OwnProps = {
|
export type OwnProps = {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -64,55 +73,100 @@ const getOutgoingCallButtonStyle = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = (state: StateType, ownProps: OwnProps) => {
|
export function SmartConversationHeader({ id }: OwnProps): JSX.Element {
|
||||||
const { id } = ownProps;
|
const conversationSelector = useSelector(getConversationSelector);
|
||||||
|
const conversation = conversationSelector(id);
|
||||||
const conversation = getConversationSelector(state)(id);
|
|
||||||
if (!conversation) {
|
if (!conversation) {
|
||||||
throw new Error('Could not find conversation');
|
throw new Error('Could not find conversation');
|
||||||
}
|
}
|
||||||
|
const hasStoriesSelector = useSelector(getHasStoriesSelector);
|
||||||
|
const hasStories = hasStoriesSelector(id);
|
||||||
|
|
||||||
const hasStories = getHasStoriesSelector(state)(id);
|
const badgeSelector = useSelector(getPreferredBadgeSelector);
|
||||||
|
const badge = badgeSelector(conversation.badges);
|
||||||
|
const conversationTitle = useSelector(getConversationTitle);
|
||||||
|
const i18n = useSelector(getIntl);
|
||||||
|
const showBackButton = useSelector<StateType, boolean>(
|
||||||
|
state => state.conversations.targetedConversationPanels.length > 0
|
||||||
|
);
|
||||||
|
const outgoingCallButtonStyle = useSelector<
|
||||||
|
StateType,
|
||||||
|
OutgoingCallButtonStyle
|
||||||
|
>(state => getOutgoingCallButtonStyle(conversation, state));
|
||||||
|
const theme = useSelector(getTheme);
|
||||||
|
|
||||||
return {
|
const {
|
||||||
...pick(conversation, [
|
destroyMessages,
|
||||||
'acceptedMessageRequest',
|
onArchive,
|
||||||
'announcementsOnly',
|
onMarkUnread,
|
||||||
'areWeAdmin',
|
onMoveToInbox,
|
||||||
'avatarPath',
|
popPanelForConversation,
|
||||||
'canChangeTimer',
|
pushPanelForConversation,
|
||||||
'color',
|
setDisappearingMessages,
|
||||||
'expireTimer',
|
setMuteExpiration,
|
||||||
'groupVersion',
|
setPinned,
|
||||||
'isArchived',
|
toggleSelectMode,
|
||||||
'isMe',
|
} = useConversationsActions();
|
||||||
'isPinned',
|
const {
|
||||||
'isVerified',
|
onOutgoingAudioCallInConversation,
|
||||||
'left',
|
onOutgoingVideoCallInConversation,
|
||||||
'markedUnread',
|
} = useCallingActions();
|
||||||
'muteExpiresAt',
|
const { searchInConversation } = useSearchActions();
|
||||||
'name',
|
const { viewUserStories } = useStoriesActions();
|
||||||
'phoneNumber',
|
|
||||||
'profileName',
|
|
||||||
'sharedGroupNames',
|
|
||||||
'title',
|
|
||||||
'type',
|
|
||||||
'unblurredAvatarPath',
|
|
||||||
]),
|
|
||||||
badge: getPreferredBadgeSelector(state)(conversation.badges),
|
|
||||||
conversationTitle: getConversationTitle(state),
|
|
||||||
hasStories,
|
|
||||||
isMissingMandatoryProfileSharing:
|
|
||||||
isMissingRequiredProfileSharing(conversation),
|
|
||||||
isSMSOnly: isConversationSMSOnly(conversation),
|
|
||||||
isSignalConversation: isSignalConversation(conversation),
|
|
||||||
i18n: getIntl(state),
|
|
||||||
showBackButton: state.conversations.targetedConversationPanels.length > 0,
|
|
||||||
outgoingCallButtonStyle: getOutgoingCallButtonStyle(conversation, state),
|
|
||||||
theme: getTheme(state),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const smart = connect(mapStateToProps, mapDispatchToProps);
|
return (
|
||||||
|
<ConversationHeader
|
||||||
export const SmartConversationHeader = smart(ConversationHeader);
|
{...pick(conversation, [
|
||||||
|
'acceptedMessageRequest',
|
||||||
|
'announcementsOnly',
|
||||||
|
'areWeAdmin',
|
||||||
|
'avatarPath',
|
||||||
|
'canChangeTimer',
|
||||||
|
'color',
|
||||||
|
'expireTimer',
|
||||||
|
'groupVersion',
|
||||||
|
'isArchived',
|
||||||
|
'isMe',
|
||||||
|
'isPinned',
|
||||||
|
'isVerified',
|
||||||
|
'left',
|
||||||
|
'markedUnread',
|
||||||
|
'muteExpiresAt',
|
||||||
|
'name',
|
||||||
|
'phoneNumber',
|
||||||
|
'profileName',
|
||||||
|
'sharedGroupNames',
|
||||||
|
'title',
|
||||||
|
'type',
|
||||||
|
'unblurredAvatarPath',
|
||||||
|
])}
|
||||||
|
badge={badge}
|
||||||
|
conversationTitle={conversationTitle}
|
||||||
|
destroyMessages={destroyMessages}
|
||||||
|
hasStories={hasStories}
|
||||||
|
i18n={i18n}
|
||||||
|
id={id}
|
||||||
|
isMissingMandatoryProfileSharing={isMissingRequiredProfileSharing(
|
||||||
|
conversation
|
||||||
|
)}
|
||||||
|
isSignalConversation={isSignalConversation(conversation)}
|
||||||
|
isSMSOnly={isConversationSMSOnly(conversation)}
|
||||||
|
onArchive={onArchive}
|
||||||
|
onMarkUnread={onMarkUnread}
|
||||||
|
onMoveToInbox={onMoveToInbox}
|
||||||
|
onOutgoingAudioCallInConversation={onOutgoingAudioCallInConversation}
|
||||||
|
onOutgoingVideoCallInConversation={onOutgoingVideoCallInConversation}
|
||||||
|
outgoingCallButtonStyle={outgoingCallButtonStyle}
|
||||||
|
popPanelForConversation={popPanelForConversation}
|
||||||
|
pushPanelForConversation={pushPanelForConversation}
|
||||||
|
searchInConversation={searchInConversation}
|
||||||
|
setDisappearingMessages={setDisappearingMessages}
|
||||||
|
setMuteExpiration={setMuteExpiration}
|
||||||
|
setPinned={setPinned}
|
||||||
|
showBackButton={showBackButton}
|
||||||
|
theme={theme}
|
||||||
|
toggleSelectMode={toggleSelectMode}
|
||||||
|
viewUserStories={viewUserStories}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue