Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3402002
D3746.id11613.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D3746.id11613.diff
View Options
diff --git a/lib/hooks/promote-sidebar.react.js b/lib/hooks/promote-sidebar.react.js
new file mode 100644
--- /dev/null
+++ b/lib/hooks/promote-sidebar.react.js
@@ -0,0 +1,58 @@
+// @flow
+
+import * as React from 'react';
+
+import {
+ changeThreadSettingsActionTypes,
+ changeThreadSettings,
+} from '../actions/thread-actions';
+import { createLoadingStatusSelector } from '../selectors/loading-selectors';
+import type { LoadingStatus } from '../types/loading-types';
+import { threadTypes, type ThreadInfo } from '../types/thread-types';
+import { useServerCall, useDispatchActionPromise } from '../utils/action-utils';
+import { useSelector } from '../utils/redux-utils';
+
+type PromoteSidebarType = {
+ +onPromoteSidebar: () => mixed,
+ +loading: LoadingStatus,
+};
+
+function usePromoteSidebar(
+ threadInfo: ThreadInfo,
+ onError?: (error: Error) => mixed,
+): PromoteSidebarType {
+ const dispatchActionPromise = useDispatchActionPromise();
+ const callChangeThreadSettings = useServerCall(changeThreadSettings);
+ const loadingStatusSelector = createLoadingStatusSelector(
+ changeThreadSettingsActionTypes,
+ );
+ const loadingStatus = useSelector(loadingStatusSelector);
+
+ const onClick = React.useCallback(() => {
+ try {
+ dispatchActionPromise(
+ changeThreadSettingsActionTypes,
+ (async () => {
+ return await callChangeThreadSettings({
+ threadID: threadInfo.id,
+ changes: { type: threadTypes.COMMUNITY_OPEN_SUBTHREAD },
+ });
+ })(),
+ );
+ } catch (e) {
+ onError?.(e);
+ }
+ }, [threadInfo.id, callChangeThreadSettings, dispatchActionPromise, onError]);
+
+ const returnValues = React.useMemo(
+ () => ({
+ onPromoteSidebar: onClick,
+ loading: loadingStatus,
+ }),
+ [onClick, loadingStatus],
+ );
+
+ return returnValues;
+}
+
+export { usePromoteSidebar };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 2:54 PM (3 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2612076
Default Alt Text
D3746.id11613.diff (1 KB)
Attached To
Mode
D3746: [lib] [feat] [ENG-991] add usePromoteThread hook
Attached
Detach File
Event Timeline
Log In to Comment