Page MenuHomePhabricator

D6287.id21073.diff
No OneTemporary

D6287.id21073.diff

diff --git a/web/sidebar/community-drawer-item-handler.react.js b/web/sidebar/community-drawer-item-handler.react.js
new file mode 100644
--- /dev/null
+++ b/web/sidebar/community-drawer-item-handler.react.js
@@ -0,0 +1,5 @@
+// @flow
+
+export type CommunityDrawerItemHandler = {
+ +onClick: (event: SyntheticEvent<HTMLElement>) => void,
+};
diff --git a/web/sidebar/community-drawer-item-handlers.react.js b/web/sidebar/community-drawer-item-handlers.react.js
new file mode 100644
--- /dev/null
+++ b/web/sidebar/community-drawer-item-handlers.react.js
@@ -0,0 +1,70 @@
+// @flow
+
+import * as React from 'react';
+import { useDispatch } from 'react-redux';
+
+import {
+ updateCalendarThreadFilter,
+ calendarThreadFilterTypes,
+} from 'lib/types/filter-types';
+import type { ThreadInfo } from 'lib/types/thread-types';
+
+import { useOnClickThread } from '../selectors/thread-selectors';
+import type { NavigationTab } from '../types/nav-types';
+import type { CommunityDrawerItemHandler } from './community-drawer-item-handler.react';
+
+type HandlerProps = {
+ +setHandler: (handler: CommunityDrawerItemHandler) => void,
+ +threadInfo: ThreadInfo,
+};
+
+function ChatDrawerItemHandler(props: HandlerProps): React.Node {
+ const { setHandler, threadInfo } = props;
+ const onClick = useOnClickThread(threadInfo);
+ const handler = React.useMemo(() => ({ onClick }), [onClick]);
+
+ React.useEffect(() => {
+ setHandler(handler);
+ }, [handler, setHandler]);
+
+ return null;
+}
+
+function CalendarDrawerItemHandler(props: HandlerProps): React.Node {
+ const { setHandler, threadInfo } = props;
+ const dispatch = useDispatch();
+
+ const onClick = React.useCallback(
+ () =>
+ dispatch({
+ type: updateCalendarThreadFilter,
+ payload: {
+ type: calendarThreadFilterTypes.THREAD_LIST,
+ threadIDs: [threadInfo.id],
+ },
+ }),
+ [dispatch, threadInfo.id],
+ );
+ const handler = React.useMemo(() => ({ onClick }), [onClick]);
+
+ React.useEffect(() => {
+ setHandler(handler);
+ }, [handler, setHandler]);
+
+ return null;
+}
+
+const communityDrawerItemHandlers: {
+ +[tab: NavigationTab]: React.ComponentType<HandlerProps>,
+} = Object.freeze({
+ chat: ChatDrawerItemHandler,
+ calendar: CalendarDrawerItemHandler,
+});
+
+function getCommunityDrawerItemHandler(
+ tab: NavigationTab,
+): React.ComponentType<HandlerProps> {
+ return communityDrawerItemHandlers[tab] ?? ChatDrawerItemHandler;
+}
+
+export { getCommunityDrawerItemHandler };

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 28, 9:36 PM (21 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2594961
Default Alt Text
D6287.id21073.diff (2 KB)

Event Timeline