Changeset View
Changeset View
Standalone View
Standalone View
web/sidebar/community-drawer.react.js
Show All 9 Lines | import { | ||||
createRecursiveDrawerItemsData, | createRecursiveDrawerItemsData, | ||||
appendSuffix, | appendSuffix, | ||||
} from 'lib/utils/drawer-utils.react'; | } from 'lib/utils/drawer-utils.react'; | ||||
import { useResolvedThreadInfos } from 'lib/utils/entity-helpers'; | import { useResolvedThreadInfos } from 'lib/utils/entity-helpers'; | ||||
import { ThreadListProvider } from '../chat/thread-list-provider'; | import { ThreadListProvider } from '../chat/thread-list-provider'; | ||||
import { useSelector } from '../redux/redux-utils'; | import { useSelector } from '../redux/redux-utils'; | ||||
import CommunityDrawerItemCommunity from './community-drawer-item-community.react'; | import CommunityDrawerItemCommunity from './community-drawer-item-community.react'; | ||||
import { getCommunityDrawerItemHandler } from './community-drawer-item-handlers.react'; | |||||
import css from './community-drawer.css'; | import css from './community-drawer.css'; | ||||
const maxDepth = 2; | const maxDepth = 2; | ||||
const labelStyles = ['titleLevel0', 'titleLevel1', 'titleLevel2']; | const labelStyles = ['titleLevel0', 'titleLevel1', 'titleLevel2']; | ||||
function CommunityDrawer(): React.Node { | function CommunityDrawer(): React.Node { | ||||
const tab = useSelector(state => state.navInfo.tab); | const tab = useSelector(state => state.navInfo.tab); | ||||
const childThreadInfosMap = useSelector(childThreadInfos); | const childThreadInfosMap = useSelector(childThreadInfos); | ||||
Show All 14 Lines | function CommunityDrawer(): React.Node { | ||||
const [openCommunity, setOpenCommunity] = React.useState( | const [openCommunity, setOpenCommunity] = React.useState( | ||||
communitiesSuffixed.length === 1 ? communitiesSuffixed[0].id : null, | communitiesSuffixed.length === 1 ? communitiesSuffixed[0].id : null, | ||||
); | ); | ||||
const setOpenCommunityOrClose = React.useCallback((index: string) => { | const setOpenCommunityOrClose = React.useCallback((index: string) => { | ||||
setOpenCommunity(open => (open === index ? null : index)); | setOpenCommunity(open => (open === index ? null : index)); | ||||
}, []); | }, []); | ||||
const HandlerChat = React.useMemo( | |||||
() => getCommunityDrawerItemHandler('chat'), | |||||
[], | |||||
); | |||||
tomek: This value never changes and is independent from the props, so we can consider it extracting… | |||||
const communitiesComponentsDefault = React.useMemo( | const communitiesComponentsDefault = React.useMemo( | ||||
() => | () => | ||||
drawerItemsData.map(item => ( | drawerItemsData.map(item => ( | ||||
<CommunityDrawerItemCommunity | <CommunityDrawerItemCommunity | ||||
itemData={item} | itemData={item} | ||||
key={`${item.threadInfo.id}_chat`} | key={`${item.threadInfo.id}_chat`} | ||||
toggleExpanded={setOpenCommunityOrClose} | toggleExpanded={setOpenCommunityOrClose} | ||||
expanded={item.threadInfo.id === openCommunity} | expanded={item.threadInfo.id === openCommunity} | ||||
paddingLeft={10} | paddingLeft={10} | ||||
expandable={true} | expandable={true} | ||||
Handler={HandlerChat} | |||||
/> | /> | ||||
)), | )), | ||||
[drawerItemsData, openCommunity, setOpenCommunityOrClose], | [HandlerChat, drawerItemsData, openCommunity, setOpenCommunityOrClose], | ||||
); | |||||
const HandlerCal = React.useMemo( | |||||
() => getCommunityDrawerItemHandler('calendar'), | |||||
[], | |||||
); | ); | ||||
const communitiesComponentsCal = React.useMemo( | const communitiesComponentsCal = React.useMemo( | ||||
() => | () => | ||||
drawerItemsData.map(item => ( | drawerItemsData.map(item => ( | ||||
<CommunityDrawerItemCommunity | <CommunityDrawerItemCommunity | ||||
itemData={item} | itemData={item} | ||||
key={`${item.threadInfo.id}_cal`} | key={`${item.threadInfo.id}_cal`} | ||||
expanded={false} | expanded={false} | ||||
paddingLeft={10} | paddingLeft={10} | ||||
expandable={false} | expandable={false} | ||||
Handler={HandlerCal} | |||||
/> | /> | ||||
)), | )), | ||||
[drawerItemsData], | [drawerItemsData, HandlerCal], | ||||
); | ); | ||||
const defaultStyle = tab === 'calendar' ? css.hidden : null; | const defaultStyle = tab === 'calendar' ? css.hidden : null; | ||||
const calStyle = tab !== 'calendar' ? css.hidden : null; | const calStyle = tab !== 'calendar' ? css.hidden : null; | ||||
return ( | return ( | ||||
<ThreadListProvider> | <ThreadListProvider> | ||||
<div className={css.container}> | <div className={css.container}> | ||||
<div className={defaultStyle}>{communitiesComponentsDefault}</div> | <div className={defaultStyle}>{communitiesComponentsDefault}</div> | ||||
<div className={calStyle}>{communitiesComponentsCal}</div> | <div className={calStyle}>{communitiesComponentsCal}</div> | ||||
</div> | </div> | ||||
</ThreadListProvider> | </ThreadListProvider> | ||||
); | ); | ||||
} | } | ||||
export default CommunityDrawer; | export default CommunityDrawer; |
This value never changes and is independent from the props, so we can consider it extracting from the component