diff --git a/native/chat/settings/thread-settings-promote-sidebar.react.js b/native/chat/settings/thread-settings-promote-sidebar.react.js index e52e7647a..e6146126d 100644 --- a/native/chat/settings/thread-settings-promote-sidebar.react.js +++ b/native/chat/settings/thread-settings-promote-sidebar.react.js @@ -1,135 +1,96 @@ // @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'; type BaseProps = { +threadInfo: ThreadInfo, +buttonStyle: ViewStyle, }; 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, + +promoteSidebar: () => mixed, }; class ThreadSettingsPromoteSidebar extends React.PureComponent { render() { const { panelIosHighlightUnderlay, panelForegroundSecondaryLabel, } = this.props.colors; const loadingIndicator = this.props.loadingStatus === 'loading' ? ( ) : null; return ( ); } - - 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 = { button: { flexDirection: 'row', paddingHorizontal: 12, paddingVertical: 10, }, container: { backgroundColor: 'panelForeground', paddingHorizontal: 12, }, text: { color: 'panelForegroundSecondaryLabel', flex: 1, fontSize: 16, }, }; -const loadingStatusSelector = createLoadingStatusSelector( - changeThreadSettingsActionTypes, -); +const onError = () => { + Alert.alert('Unknown error', 'Uhh... try again?', undefined, { + cancelable: true, + }); +}; const ConnectedThreadSettingsPromoteSidebar: React.ComponentType = React.memo( 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 ( ); }, ); export default ConnectedThreadSettingsPromoteSidebar;