Page MenuHomePhabricator

D3746.id11521.diff
No OneTemporary

D3746.id11521.diff

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: string) => 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

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

Event Timeline