Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3404082
D3748.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D3748.diff
View Options
diff --git a/native/chat/settings/thread-settings-promote-sidebar.react.js b/native/chat/settings/thread-settings-promote-sidebar.react.js
--- a/native/chat/settings/thread-settings-promote-sidebar.react.js
+++ b/native/chat/settings/thread-settings-promote-sidebar.react.js
@@ -1,28 +1,13 @@
// @flow
import * as React from 'react';
-import { Text, Alert, ActivityIndicator, View } from 'react-native';
+import { Text, ActivityIndicator, View, Alert } from 'react-native';
-import {
- changeThreadSettingsActionTypes,
- changeThreadSettings,
-} from 'lib/actions/thread-actions';
-import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors';
+import { usePromoteSidebar } from 'lib/hooks/promote-sidebar.react';
import type { LoadingStatus } from 'lib/types/loading-types';
-import {
- type ThreadInfo,
- type UpdateThreadRequest,
- type ChangeThreadSettingsPayload,
- threadTypes,
-} from 'lib/types/thread-types';
-import {
- type DispatchActionPromise,
- useServerCall,
- useDispatchActionPromise,
-} from 'lib/utils/action-utils';
+import type { ThreadInfo } from 'lib/types/thread-types';
import Button from '../../components/button.react';
-import { useSelector } from '../../redux/redux-utils';
import { type Colors, useColors, useStyles } from '../../themes/colors';
import type { ViewStyle } from '../../types/styles';
@@ -32,16 +17,10 @@
};
type Props = {
...BaseProps,
- // Redux state
+loadingStatus: LoadingStatus,
+colors: Colors,
+styles: typeof unboundStyles,
- // Redux dispatch functions
- +dispatchActionPromise: DispatchActionPromise,
- // async functions that hit server APIs
- +changeThreadSettings: (
- request: UpdateThreadRequest,
- ) => Promise<ChangeThreadSettingsPayload>,
+ +promoteSidebar: () => mixed,
};
class ThreadSettingsPromoteSidebar extends React.PureComponent<Props> {
render() {
@@ -56,7 +35,7 @@
return (
<View style={this.props.styles.container}>
<Button
- onPress={this.onPress}
+ onPress={this.props.promoteSidebar}
style={[this.props.styles.button, this.props.buttonStyle]}
iosFormat="highlight"
iosHighlightUnderlayColor={panelIosHighlightUnderlay}
@@ -67,28 +46,6 @@
</View>
);
}
-
- onPress = () => {
- this.props.dispatchActionPromise(
- changeThreadSettingsActionTypes,
- this.changeThreadSettings(),
- );
- };
-
- async changeThreadSettings() {
- const threadID = this.props.threadInfo.id;
- try {
- return await this.props.changeThreadSettings({
- threadID,
- changes: { type: threadTypes.COMMUNITY_OPEN_SUBTHREAD },
- });
- } catch (e) {
- Alert.alert('Unknown error', 'Uhh... try again?', undefined, {
- cancelable: true,
- });
- throw e;
- }
- }
}
const unboundStyles = {
@@ -108,25 +65,29 @@
},
};
-const loadingStatusSelector = createLoadingStatusSelector(
- changeThreadSettingsActionTypes,
-);
+const onError = () => {
+ Alert.alert('Unknown error', 'Uhh... try again?', undefined, {
+ cancelable: true,
+ });
+};
const ConnectedThreadSettingsPromoteSidebar: React.ComponentType<BaseProps> = React.memo<BaseProps>(
function ConnectedThreadSettingsPromoteSidebar(props: BaseProps) {
- const loadingStatus = useSelector(loadingStatusSelector);
+ const { threadInfo } = props;
const colors = useColors();
const styles = useStyles(unboundStyles);
- const dispatchActionPromise = useDispatchActionPromise();
- const callChangeThreadSettings = useServerCall(changeThreadSettings);
+ const { onPromoteSidebar, loading } = usePromoteSidebar(
+ threadInfo,
+ onError,
+ );
+
return (
<ThreadSettingsPromoteSidebar
{...props}
- loadingStatus={loadingStatus}
colors={colors}
styles={styles}
- dispatchActionPromise={dispatchActionPromise}
- changeThreadSettings={callChangeThreadSettings}
+ promoteSidebar={onPromoteSidebar}
+ loadingStatus={loading}
/>
);
},
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 4, 6:24 AM (8 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2612109
Default Alt Text
D3748.diff (3 KB)
Attached To
Mode
D3748: [native] [refactor] [ENG-991] use usePromoteSidebar hook
Attached
Detach File
Event Timeline
Log In to Comment