diff --git a/web/sidebar/community-drawer-item.react.js b/web/sidebar/community-drawer-item.react.js index 3d202e682..489fffcb2 100644 --- a/web/sidebar/community-drawer-item.react.js +++ b/web/sidebar/community-drawer-item.react.js @@ -1,139 +1,159 @@ // @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'; export type DrawerItemProps = { +itemData: CommunityDrawerItemData, - +toggleExpanded: (threadID: string) => void, + +toggleExpanded?: (threadID: string) => void, +expanded: boolean, +paddingLeft: number, + +expandable?: boolean, }; const indentation = 14; const subchannelsButtonIndentation = 24; function CommunityDrawerItem(props: DrawerItemProps): React.Node { const { itemData: { threadInfo, itemChildren, hasSubchannelsButton, labelStyle }, expanded, toggleExpanded, paddingLeft, + expandable = true, } = props; const children = React.useMemo(() => { if (!expanded) { return null; } if (hasSubchannelsButton) { const buttonPaddingLeft = paddingLeft + subchannelsButtonIndentation; return (
); } if (!itemChildren) { return null; } return itemChildren.map(item => ( )); - }, [expanded, hasSubchannelsButton, itemChildren, paddingLeft, threadInfo]); + }, [ + expanded, + hasSubchannelsButton, + itemChildren, + paddingLeft, + expandable, + threadInfo, + ]); const onExpandToggled = React.useCallback( - () => toggleExpanded(threadInfo.id), + () => (toggleExpanded ? toggleExpanded(threadInfo.id) : null), [toggleExpanded, threadInfo.id], ); const itemExpandButton = React.useMemo(() => { + if (!expandable) { + return null; + } if (itemChildren?.length === 0 && !hasSubchannelsButton) { return (
); } return (
); - }, [itemChildren?.length, hasSubchannelsButton, onExpandToggled, expanded]); + }, [ + expandable, + itemChildren?.length, + hasSubchannelsButton, + onExpandToggled, + expanded, + ]); 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]); const style = React.useMemo(() => ({ paddingLeft }), [paddingLeft]); return ( <>
{itemExpandButton}
{uiName}
{children}
); } export type CommunityDrawerItemChatProps = { +itemData: CommunityDrawerItemData, +paddingLeft: number, + +expandable?: boolean, }; 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; diff --git a/web/sidebar/community-drawer.css b/web/sidebar/community-drawer.css index 337fa488c..981e23002 100644 --- a/web/sidebar/community-drawer.css +++ b/web/sidebar/community-drawer.css @@ -1,10 +1,14 @@ .container { background-color: var(--drawer-bg); display: flex; overflow-y: auto; flex-direction: column; padding-right: 8px; padding-top: 8px; padding-bottom: 8px; align-self: flex-start; } + +.hidden { + display: none; +} diff --git a/web/sidebar/community-drawer.react.js b/web/sidebar/community-drawer.react.js index f7f22f7a0..51f208aa5 100644 --- a/web/sidebar/community-drawer.react.js +++ b/web/sidebar/community-drawer.react.js @@ -1,68 +1,90 @@ // @flow import * as React from 'react'; import { childThreadInfos, communityThreadSelector, } from 'lib/selectors/thread-selectors.js'; import { createRecursiveDrawerItemsData, appendSuffix, } from 'lib/utils/drawer-utils.react.js'; import { useResolvedThreadInfos } from 'lib/utils/entity-helpers.js'; import CommunityDrawerItemCommunity from './community-drawer-item-community.react.js'; import css from './community-drawer.css'; import { ThreadListProvider } from '../chat/thread-list-provider.js'; import { useSelector } from '../redux/redux-utils.js'; const maxDepth = 2; const labelStyles = ['titleLevel0', 'titleLevel1', 'titleLevel2']; function CommunityDrawer(): React.Node { + const tab = useSelector(state => state.navInfo.tab); const childThreadInfosMap = useSelector(childThreadInfos); const communities = useSelector(communityThreadSelector); const resolvedCommunities = useResolvedThreadInfos(communities); const communitiesSuffixed = React.useMemo( () => appendSuffix(resolvedCommunities), [resolvedCommunities], ); const drawerItemsData = createRecursiveDrawerItemsData( childThreadInfosMap, communitiesSuffixed, labelStyles, maxDepth, ); const [openCommunity, setOpenCommunity] = React.useState( communitiesSuffixed.length === 1 ? communitiesSuffixed[0].id : null, ); - const setOpenCommunityOrClose = React.useCallback((communityID: string) => { - setOpenCommunity(open => (open === communityID ? null : communityID)); + const setOpenCommunityOrClose = React.useCallback((index: string) => { + setOpenCommunity(open => (open === index ? null : index)); }, []); - const communitiesComponents = React.useMemo( + const communitiesComponentsDefault = React.useMemo( () => drawerItemsData.map(item => ( )), [drawerItemsData, openCommunity, setOpenCommunityOrClose], ); + const communitiesComponentsCal = React.useMemo( + () => + drawerItemsData.map(item => ( + + )), + [drawerItemsData], + ); + + const defaultStyle = tab === 'calendar' ? css.hidden : null; + const calStyle = tab !== 'calendar' ? css.hidden : null; + return ( -
{communitiesComponents}
+
+
{communitiesComponentsDefault}
+
{communitiesComponentsCal}
+
); } export default CommunityDrawer;