Changeset View
Changeset View
Standalone View
Standalone View
web/sidebar/community-drawer-item-handlers.react.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { useDispatch } from 'react-redux'; | import { useDispatch } from 'react-redux'; | ||||
import { | import { | ||||
updateCalendarThreadFilter, | updateCalendarThreadFilter, | ||||
calendarThreadFilterTypes, | calendarThreadFilterTypes, | ||||
} from 'lib/types/filter-types.js'; | } from 'lib/types/filter-types.js'; | ||||
import type { ThreadInfo } from 'lib/types/thread-types'; | import type { ThreadInfo } from 'lib/types/thread-types'; | ||||
import type { CommunityDrawerItemHandler } from './community-drawer-item-handler.react.js'; | import type { CommunityDrawerItemHandler } from './community-drawer-item-handler.react.js'; | ||||
import { useOnClickThread } from '../selectors/thread-selectors.js'; | import { | ||||
useOnClickThread, | |||||
useThreadIsActive, | |||||
} from '../selectors/thread-selectors.js'; | |||||
import type { NavigationTab } from '../types/nav-types'; | import type { NavigationTab } from '../types/nav-types'; | ||||
type HandlerProps = { | type HandlerProps = { | ||||
+setHandler: (handler: CommunityDrawerItemHandler) => void, | +setHandler: (handler: CommunityDrawerItemHandler) => void, | ||||
+threadInfo: ThreadInfo, | +threadInfo: ThreadInfo, | ||||
}; | }; | ||||
function ChatDrawerItemHandler(props: HandlerProps): React.Node { | function ChatDrawerItemHandler(props: HandlerProps): React.Node { | ||||
const { setHandler, threadInfo } = props; | const { setHandler, threadInfo } = props; | ||||
const onClick = useOnClickThread(threadInfo); | const onClick = useOnClickThread(threadInfo); | ||||
const handler = React.useMemo(() => ({ onClick }), [onClick]); | const isActive = useThreadIsActive(threadInfo.id); | ||||
const handler = React.useMemo(() => ({ onClick, isActive }), [ | |||||
isActive, | |||||
onClick, | |||||
]); | |||||
React.useEffect(() => { | React.useEffect(() => { | ||||
setHandler(handler); | setHandler(handler); | ||||
}, [handler, setHandler]); | }, [handler, setHandler]); | ||||
return null; | return null; | ||||
} | } | ||||
function CalendarDrawerItemHandler(props: HandlerProps): React.Node { | function CalendarDrawerItemHandler(props: HandlerProps): React.Node { | ||||
const { setHandler, threadInfo } = props; | const { setHandler, threadInfo } = props; | ||||
const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
const onClick = React.useCallback( | const onClick = React.useCallback( | ||||
() => | () => | ||||
dispatch({ | dispatch({ | ||||
type: updateCalendarThreadFilter, | type: updateCalendarThreadFilter, | ||||
payload: { | payload: { | ||||
type: calendarThreadFilterTypes.THREAD_LIST, | type: calendarThreadFilterTypes.THREAD_LIST, | ||||
threadIDs: [threadInfo.id], | threadIDs: [threadInfo.id], | ||||
}, | }, | ||||
}), | }), | ||||
[dispatch, threadInfo.id], | [dispatch, threadInfo.id], | ||||
); | ); | ||||
const handler = React.useMemo(() => ({ onClick }), [onClick]); | const isActive = false; | ||||
const handler = React.useMemo(() => ({ onClick, isActive }), [ | |||||
onClick, | |||||
isActive, | |||||
]); | |||||
React.useEffect(() => { | React.useEffect(() => { | ||||
setHandler(handler); | setHandler(handler); | ||||
}, [handler, setHandler]); | }, [handler, setHandler]); | ||||
return null; | return null; | ||||
} | } | ||||
const communityDrawerItemHandlers: { | const communityDrawerItemHandlers: { | ||||
Show All 13 Lines |