Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3380087
D6287.id21020.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6287.id21020.diff
View Options
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,72 @@
+// @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 { CommunityDrawerItemHandlerSpec } from './community-drawer-item-spec.react';
+
+type HandlerProps = {
+ +setHandler: (handler: CommunityDrawerItemHandlerSpec) => 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, onClick, 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);
+ }, [dispatch, handler, onClick, setHandler, threadInfo.id]);
+
+ return null;
+}
+
+const communityDrawerItemHandlers: {
+ [tab: string]: React.ComponentType<HandlerProps>,
+} = Object.freeze({
+ default: ChatDrawerItemHandler,
+ chat: ChatDrawerItemHandler,
+ calendar: CalendarDrawerItemHandler,
+});
+
+function getCommunityDrawerItemHandler(
+ tab: string,
+): React.ComponentType<HandlerProps> {
+ return (
+ communityDrawerItemHandlers[tab] ?? communityDrawerItemHandlers['default']
+ );
+}
+
+export { getCommunityDrawerItemHandler };
diff --git a/web/sidebar/community-drawer-item-spec.react.js b/web/sidebar/community-drawer-item-spec.react.js
new file mode 100644
--- /dev/null
+++ b/web/sidebar/community-drawer-item-spec.react.js
@@ -0,0 +1,5 @@
+// @flow
+
+export type CommunityDrawerItemHandlerSpec = {
+ +onClick: (event: SyntheticEvent<HTMLElement>) => void,
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 8:56 PM (21 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2594900
Default Alt Text
D6287.id21020.diff (2 KB)
Attached To
Mode
D6287: [web] Add community drawer item handlers
Attached
Detach File
Event Timeline
Log In to Comment