diff --git a/web/sidebar/community-drawer-item.react.js b/web/sidebar/community-drawer-item.react.js index 4d7bc9252..93a22670a 100644 --- a/web/sidebar/community-drawer-item.react.js +++ b/web/sidebar/community-drawer-item.react.js @@ -1,135 +1,128 @@ // @flow import classnames from 'classnames'; import * as React from 'react'; import type { CommunityDrawerItemData } from 'lib/utils/drawer-utils.react.js'; import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js'; +import { getCommunityDrawerItemHandler } from './community-drawer-item-handlers.react.js'; import css from './community-drawer-item.css'; import { ExpandButton } from './expand-buttons.react.js'; import SubchannelsButton from './subchannels-button.react.js'; import { useSelector } from '../redux/redux-utils.js'; -import { - useOnClickThread, - useThreadIsActive, -} from '../selectors/thread-selectors.js'; export type DrawerItemProps = { +itemData: CommunityDrawerItemData, +toggleExpanded: (threadID: string) => void, +expanded: boolean, }; function CommunityDrawerItem(props: DrawerItemProps): React.Node { const { itemData: { threadInfo, itemChildren, hasSubchannelsButton, labelStyle }, expanded, toggleExpanded, } = props; const children = React.useMemo(() => { if (!expanded) { return null; } if (hasSubchannelsButton) { return (
); } if (!itemChildren) { return null; } return itemChildren.map(item => ( )); }, [expanded, hasSubchannelsButton, itemChildren, threadInfo]); const onExpandToggled = React.useCallback( () => toggleExpanded(threadInfo.id), [toggleExpanded, threadInfo.id], ); const itemExpandButton = React.useMemo(() => { if (itemChildren?.length === 0 && !hasSubchannelsButton) { return (
); } return (
); }, [itemChildren?.length, hasSubchannelsButton, onExpandToggled, expanded]); - const active = useThreadIsActive(threadInfo.id); - const isCreateMode = useSelector( - state => state.navInfo.chatMode === 'create', - ); - const onClick = useOnClickThread(threadInfo); - const selectItemIfNotActiveCreation = React.useCallback( - (event: SyntheticEvent) => { - if (!isCreateMode || !active) { - onClick(event); - } - }, - [isCreateMode, active, onClick], + const Handler = useSelector(state => + getCommunityDrawerItemHandler(state.navInfo.tab), ); + const [handler, setHandler] = React.useState({ + // eslint-disable-next-line no-unused-vars + onClick: event => {}, + }); + const { uiName } = useResolvedThreadInfo(threadInfo); const titleLabel = classnames(css.title, css[labelStyle]); return ( <> +
{itemExpandButton} - +
{uiName}
{children}
); } export type CommunityDrawerItemChatProps = { +itemData: CommunityDrawerItemData, }; function CommunityDrawerItemChat( props: CommunityDrawerItemChatProps, ): React.Node { const [expanded, setExpanded] = React.useState(false); const toggleExpanded = React.useCallback(() => { setExpanded(isExpanded => !isExpanded); }, []); return (
); } const MemoizedCommunityDrawerItemChat: React.ComponentType = React.memo( CommunityDrawerItemChat, ); const MemoizedCommunityDrawerItem: React.ComponentType = React.memo( CommunityDrawerItem, ); export default MemoizedCommunityDrawerItem;