Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3404247
D3748.id11617.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D3748.id11617.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,30 @@
},
};
-const loadingStatusSelector = createLoadingStatusSelector(
- changeThreadSettingsActionTypes,
-);
+const onError = e => {
+ Alert.alert('Unknown error', 'Uhh... try again?', undefined, {
+ cancelable: true,
+ });
+ throw e;
+};
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, 7:32 AM (8 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2613925
Default Alt Text
D3748.id11617.diff (4 KB)
Attached To
Mode
D3748: [native] [refactor] [ENG-991] use usePromoteSidebar hook
Attached
Detach File
Event Timeline
Log In to Comment