signal-desktop/ts/state/smart/Inbox.tsx
Jamie Kyle 27b55e472d
Refactor smart components
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
2024-03-13 13:44:13 -07:00

75 lines
2.4 KiB
TypeScript

// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { memo } from 'react';
import { useSelector } from 'react-redux';
import type { StateType } from '../reducer';
import { Inbox } from '../../components/Inbox';
import { getIntl } from '../selectors/user';
import { SmartCustomizingPreferredReactionsModal } from './CustomizingPreferredReactionsModal';
import { getIsCustomizingPreferredReactions } from '../selectors/preferredReactions';
import type { SmartNavTabsProps } from './NavTabs';
import { SmartNavTabs } from './NavTabs';
import { SmartStoriesTab } from './StoriesTab';
import { SmartCallsTab } from './CallsTab';
import { useItemsActions } from '../ducks/items';
import { getNavTabsCollapsed } from '../selectors/items';
import { SmartChatsTab } from './ChatsTab';
function renderChatsTab() {
return <SmartChatsTab />;
}
function renderCallsTab() {
return <SmartCallsTab />;
}
function renderCustomizingPreferredReactionsModal() {
return <SmartCustomizingPreferredReactionsModal />;
}
function renderNavTabs(props: SmartNavTabsProps) {
return <SmartNavTabs {...props} />;
}
function renderStoriesTab() {
return <SmartStoriesTab />;
}
export const SmartInbox = memo(function SmartInbox(): JSX.Element {
const i18n = useSelector(getIntl);
const isCustomizingPreferredReactions = useSelector(
getIsCustomizingPreferredReactions
);
const envelopeTimestamp = useSelector(
(state: StateType) => state.inbox.envelopeTimestamp
);
const firstEnvelopeTimestamp = useSelector(
(state: StateType) => state.inbox.firstEnvelopeTimestamp
);
const { hasInitialLoadCompleted } = useSelector(
(state: StateType) => state.app
);
const navTabsCollapsed = useSelector(getNavTabsCollapsed);
const { toggleNavTabsCollapse } = useItemsActions();
return (
<Inbox
envelopeTimestamp={envelopeTimestamp}
firstEnvelopeTimestamp={firstEnvelopeTimestamp}
hasInitialLoadCompleted={hasInitialLoadCompleted}
i18n={i18n}
isCustomizingPreferredReactions={isCustomizingPreferredReactions}
navTabsCollapsed={navTabsCollapsed}
onToggleNavTabsCollapse={toggleNavTabsCollapse}
renderChatsTab={renderChatsTab}
renderCallsTab={renderCallsTab}
renderCustomizingPreferredReactionsModal={
renderCustomizingPreferredReactionsModal
}
renderNavTabs={renderNavTabs}
renderStoriesTab={renderStoriesTab}
/>
);
});