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

69 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
2021-10-05 16:47:06 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { useSelector } from 'react-redux';
import type { StateType } from '../reducer';
import { ConversationPanel } from './ConversationPanel';
import { ConversationView } from '../../components/conversation/ConversationView';
import { SmartCompositionArea } from './CompositionArea';
import { SmartConversationHeader } from './ConversationHeader';
import { SmartTimeline } from './Timeline';
2023-01-02 21:34:41 +00:00
import {
getActivePanel,
getIsPanelAnimating,
2023-01-02 21:34:41 +00:00
getSelectedConversationId,
2023-03-20 22:23:53 +00:00
getSelectedMessageIds,
2023-01-02 21:34:41 +00:00
} from '../selectors/conversations';
import { useComposerActions } from '../ducks/composer';
import { useConversationsActions } from '../ducks/conversations';
2021-10-05 16:47:06 +00:00
2023-01-02 21:34:41 +00:00
export function SmartConversationView(): JSX.Element {
const conversationId = useSelector(getSelectedConversationId);
if (!conversationId) {
throw new Error('SmartConversationView: No selected conversation');
}
2021-10-05 16:47:06 +00:00
const { toggleSelectMode } = useConversationsActions();
2023-03-20 22:23:53 +00:00
const selectedMessageIds = useSelector(getSelectedMessageIds);
const isSelectMode = selectedMessageIds != null;
const { processAttachments } = useComposerActions();
const hasOpenModal = useSelector((state: StateType) => {
return (
state.globalModals.forwardMessagesProps != null ||
state.globalModals.deleteMessagesProps != null ||
state.globalModals.hasConfirmationModal
);
2023-03-20 22:23:53 +00:00
});
const shouldHideConversationView = useSelector((state: StateType) => {
const activePanel = getActivePanel(state);
const isAnimating = getIsPanelAnimating(state);
return activePanel && !isAnimating;
});
return (
<ConversationView
conversationId={conversationId}
hasOpenModal={hasOpenModal}
isSelectMode={isSelectMode}
onExitSelectMode={() => {
toggleSelectMode(false);
}}
processAttachments={processAttachments}
renderCompositionArea={() => <SmartCompositionArea id={conversationId} />}
renderConversationHeader={() => (
<SmartConversationHeader id={conversationId} />
)}
renderTimeline={() => (
<SmartTimeline key={conversationId} id={conversationId} />
)}
renderPanel={() => <ConversationPanel conversationId={conversationId} />}
shouldHideConversationView={shouldHideConversationView}
/>
);
}