diff --git a/web/sidebar/community-drawer-item-handler.react.js b/web/sidebar/community-drawer-item-handler.react.js index 14ff922ca..9a33eb0ca 100644 --- a/web/sidebar/community-drawer-item-handler.react.js +++ b/web/sidebar/community-drawer-item-handler.react.js @@ -1,12 +1,14 @@ // @flow export type CommunityDrawerItemHandler = { +onClick: (event: SyntheticEvent) => void, + +expanded: boolean, + +toggleExpanded: () => void, +isActive: boolean, }; export type CommunityDrawerItemCommunityHandler = { +onClick: (event: SyntheticEvent) => void, +expanded: boolean, +isActive: boolean, }; diff --git a/web/sidebar/community-drawer-item-handlers.react.js b/web/sidebar/community-drawer-item-handlers.react.js index 7cfb13a0c..5db2946b5 100644 --- a/web/sidebar/community-drawer-item-handlers.react.js +++ b/web/sidebar/community-drawer-item-handlers.react.js @@ -1,74 +1,74 @@ // @flow import * as React from 'react'; -import { useDispatch } from 'react-redux'; -import { updateCalendarCommunityFilter } from 'lib/actions/community-actions.js'; import type { ThreadInfo } from 'lib/types/thread-types.js'; import type { CommunityDrawerItemHandler } from './community-drawer-item-handler.react.js'; import { useCommunityIsPickedCalendar } from '../selectors/calendar-selectors.js'; import { useOnClickThread, useThreadIsActive, } from '../selectors/thread-selectors.js'; import type { NavigationTab } from '../types/nav-types.js'; export type HandlerProps = { +setHandler: (handler: CommunityDrawerItemHandler) => void, +threadInfo: ThreadInfo, }; function ChatDrawerItemHandler(props: HandlerProps): React.Node { const { setHandler, threadInfo } = props; const onClick = useOnClickThread(threadInfo); const isActive = useThreadIsActive(threadInfo.id); + const [expanded, setExpanded] = React.useState(false); + const toggleExpanded = React.useCallback(() => { + setExpanded(isExpanded => !isExpanded); + }, []); + const handler = React.useMemo( - () => ({ onClick, isActive }), - [isActive, onClick], + () => ({ onClick, isActive, expanded, toggleExpanded }), + [expanded, isActive, onClick, toggleExpanded], ); React.useEffect(() => { setHandler(handler); }, [handler, setHandler]); return null; } +const onClick = () => {}; +const expanded = false; +const toggleExpanded = () => {}; + function CalendarDrawerItemHandler(props: HandlerProps): React.Node { const { setHandler, threadInfo } = props; - const dispatch = useDispatch(); - - const onClick = React.useCallback(() => { - dispatch({ - type: updateCalendarCommunityFilter, - payload: threadInfo.id, - }); - }, [dispatch, threadInfo.id]); + const isActive = useCommunityIsPickedCalendar(threadInfo.id); const handler = React.useMemo( - () => ({ onClick, isActive }), - [onClick, isActive], + () => ({ onClick, isActive, expanded, toggleExpanded }), + [isActive], ); React.useEffect(() => { setHandler(handler); }, [handler, setHandler]); return null; } const communityDrawerItemHandlers: { +[tab: NavigationTab]: React.ComponentType, } = Object.freeze({ chat: ChatDrawerItemHandler, calendar: CalendarDrawerItemHandler, }); function getCommunityDrawerItemHandler( tab: NavigationTab, ): React.ComponentType { return communityDrawerItemHandlers[tab] ?? ChatDrawerItemHandler; } export { getCommunityDrawerItemHandler };