Page MenuHomePhabricator

D3746.id11517.diff
No OneTemporary

D3746.id11517.diff

diff --git a/lib/hooks/promote-thread.react.js b/lib/hooks/promote-thread.react.js
new file mode 100644
--- /dev/null
+++ b/lib/hooks/promote-thread.react.js
@@ -0,0 +1,51 @@
+// @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 PromoteThreadType = {
+ onClick: () => void,
+ loading: LoadingStatus,
+ error: any,
+};
+
+function usePromoteThread(threadInfo: ThreadInfo): PromoteThreadType {
+ const dispatchActionPromise = useDispatchActionPromise();
+ const [error, setError] = React.useState(null);
+ 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) {
+ setError(e);
+ console.error(e);
+ }
+ }, [threadInfo.id, callChangeThreadSettings, dispatchActionPromise]);
+
+ return { onClick, loading: loadingStatus, error };
+}
+
+export { usePromoteThread };

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 2:56 PM (3 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2612080
Default Alt Text
D3746.id11517.diff (1 KB)

Event Timeline