diff --git a/web/sidebar/community-drawer-item.css b/web/sidebar/community-drawer-item.css index ab77b9688..8a1f2ea0d 100644 --- a/web/sidebar/community-drawer-item.css +++ b/web/sidebar/community-drawer-item.css @@ -1,66 +1,61 @@ .threadEntry { display: flex; flex-direction: row; - margin-top: 8px; - margin-bottom: 8px; + padding-top: 8px; + padding-bottom: 8px; } .threadListContainer { display: flex; flex-direction: column; } .titleWrapper { overflow: hidden; + width: 100%; } .title { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; color: var(--drawer-item-color); line-height: 24px; } .titleLevel0 { font-size: var(--l-font-18); font-weight: var(--semi-bold); } .titleLevel1, .titleLevel2 { font-size: var(--m-font-16); font-weight: var(--semi-bold); } .buttonContainer { width: 24px; align-items: center; justify-content: center; display: flex; } -.chatItem { - margin-left: 16px; -} - .communityBase { padding: 2px; - padding-right: 24px; - padding-left: 8px; + padding-right: 4px; overflow: hidden; } .communityExpanded { background-color: var(--drawer-open-community-bg); border-top-right-radius: 8px; border-bottom-right-radius: 8px; } .subchannelsButton { - margin-left: 24px; margin-bottom: 6px; margin-top: 4px; display: flex; align-items: center; } diff --git a/web/sidebar/community-drawer-item.react.js b/web/sidebar/community-drawer-item.react.js index 93a22670a..3d202e682 100644 --- a/web/sidebar/community-drawer-item.react.js +++ b/web/sidebar/community-drawer-item.react.js @@ -1,128 +1,139 @@ // @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, +expanded: boolean, + +paddingLeft: number, }; +const indentation = 14; +const subchannelsButtonIndentation = 24; + function CommunityDrawerItem(props: DrawerItemProps): React.Node { const { itemData: { threadInfo, itemChildren, hasSubchannelsButton, labelStyle }, expanded, toggleExpanded, + paddingLeft, } = 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, threadInfo]); + }, [expanded, hasSubchannelsButton, itemChildren, paddingLeft, 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 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, }; 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.react.js b/web/sidebar/community-drawer.react.js index 9513e69e7..f7f22f7a0 100644 --- a/web/sidebar/community-drawer.react.js +++ b/web/sidebar/community-drawer.react.js @@ -1,67 +1,68 @@ // @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 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 communitiesComponents = React.useMemo( () => drawerItemsData.map(item => ( )), [drawerItemsData, openCommunity, setOpenCommunityOrClose], ); return (
{communitiesComponents}
); } export default CommunityDrawer;