2023-08-09 00:53:06 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo, useCallback } from 'react';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import type { NavTabPanelProps } from '../../components/NavTabs';
|
|
|
|
import { NavTabs } from '../../components/NavTabs';
|
|
|
|
import { getIntl, getTheme } from '../selectors/user';
|
|
|
|
import {
|
|
|
|
getAllConversationsUnreadStats,
|
|
|
|
getMe,
|
|
|
|
} from '../selectors/conversations';
|
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
|
|
|
import {
|
|
|
|
getHasAnyFailedStorySends,
|
|
|
|
getStoriesNotificationCount,
|
|
|
|
} from '../selectors/stories';
|
|
|
|
import { showSettings } from '../../shims/Whisper';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { useUpdatesActions } from '../ducks/updates';
|
|
|
|
import { getStoriesEnabled } from '../selectors/items';
|
|
|
|
import { getSelectedNavTab } from '../selectors/nav';
|
|
|
|
import type { NavTab } from '../ducks/nav';
|
|
|
|
import { useNavActions } from '../ducks/nav';
|
2023-08-14 23:28:47 +00:00
|
|
|
import { getHasPendingUpdate } from '../selectors/updates';
|
|
|
|
import { getCallHistoryUnreadCount } from '../selectors/callHistory';
|
2023-08-09 00:53:06 +00:00
|
|
|
|
|
|
|
export type SmartNavTabsProps = Readonly<{
|
|
|
|
navTabsCollapsed: boolean;
|
|
|
|
onToggleNavTabsCollapse(navTabsCollapsed: boolean): void;
|
|
|
|
renderCallsTab(props: NavTabPanelProps): JSX.Element;
|
|
|
|
renderChatsTab(props: NavTabPanelProps): JSX.Element;
|
|
|
|
renderStoriesTab(props: NavTabPanelProps): JSX.Element;
|
|
|
|
}>;
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartNavTabs = memo(function SmartNavTabs({
|
2023-08-09 00:53:06 +00:00
|
|
|
navTabsCollapsed,
|
|
|
|
onToggleNavTabsCollapse,
|
|
|
|
renderCallsTab,
|
|
|
|
renderChatsTab,
|
|
|
|
renderStoriesTab,
|
|
|
|
}: SmartNavTabsProps): JSX.Element {
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const selectedNavTab = useSelector(getSelectedNavTab);
|
|
|
|
const { changeNavTab } = useNavActions();
|
|
|
|
const me = useSelector(getMe);
|
|
|
|
const badge = useSelector(getPreferredBadgeSelector)(me.badges);
|
|
|
|
const theme = useSelector(getTheme);
|
|
|
|
const storiesEnabled = useSelector(getStoriesEnabled);
|
|
|
|
const unreadConversationsStats = useSelector(getAllConversationsUnreadStats);
|
|
|
|
const unreadStoriesCount = useSelector(getStoriesNotificationCount);
|
2023-08-14 23:28:47 +00:00
|
|
|
const unreadCallsCount = useSelector(getCallHistoryUnreadCount);
|
2023-08-09 00:53:06 +00:00
|
|
|
const hasFailedStorySends = useSelector(getHasAnyFailedStorySends);
|
2023-08-14 23:28:47 +00:00
|
|
|
const hasPendingUpdate = useSelector(getHasPendingUpdate);
|
2023-08-09 00:53:06 +00:00
|
|
|
|
|
|
|
const { toggleProfileEditor } = useGlobalModalActions();
|
|
|
|
const { startUpdate } = useUpdatesActions();
|
|
|
|
|
|
|
|
const onNavTabSelected = useCallback(
|
|
|
|
(tab: NavTab) => {
|
|
|
|
// For some reason react-aria will call this more often than the tab
|
|
|
|
// actually changing.
|
|
|
|
if (tab !== selectedNavTab) {
|
|
|
|
changeNavTab(tab);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[changeNavTab, selectedNavTab]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NavTabs
|
|
|
|
badge={badge}
|
|
|
|
hasFailedStorySends={hasFailedStorySends}
|
|
|
|
hasPendingUpdate={hasPendingUpdate}
|
|
|
|
i18n={i18n}
|
|
|
|
me={me}
|
|
|
|
navTabsCollapsed={navTabsCollapsed}
|
|
|
|
onShowSettings={showSettings}
|
|
|
|
onStartUpdate={startUpdate}
|
|
|
|
onNavTabSelected={onNavTabSelected}
|
|
|
|
onToggleNavTabsCollapse={onToggleNavTabsCollapse}
|
|
|
|
onToggleProfileEditor={toggleProfileEditor}
|
|
|
|
renderCallsTab={renderCallsTab}
|
|
|
|
renderChatsTab={renderChatsTab}
|
|
|
|
renderStoriesTab={renderStoriesTab}
|
|
|
|
selectedNavTab={selectedNavTab}
|
|
|
|
storiesEnabled={storiesEnabled}
|
|
|
|
theme={theme}
|
2023-08-14 23:28:47 +00:00
|
|
|
unreadCallsCount={unreadCallsCount}
|
2023-08-09 00:53:06 +00:00
|
|
|
unreadConversationsStats={unreadConversationsStats}
|
|
|
|
unreadStoriesCount={unreadStoriesCount}
|
|
|
|
/>
|
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
});
|