diff --git a/src/account-info/AwayStatusSwitch.js b/src/account-info/AwayStatusSwitch.js index 2c31f41deac..bdc7e1d2056 100644 --- a/src/account-info/AwayStatusSwitch.js +++ b/src/account-info/AwayStatusSwitch.js @@ -2,10 +2,10 @@ import React from 'react'; import type { Node } from 'react'; -import { useSelector, useDispatch } from '../react-redux'; +import { useSelector } from '../react-redux'; import { SwitchRow } from '../common'; -import { getSelfUserAwayStatus } from '../selectors'; -import { updateUserAwayStatus } from '../user-status/userStatusActions'; +import { getAuth, getSelfUserAwayStatus } from '../selectors'; +import * as api from '../api'; type Props = $ReadOnly<{||}>; @@ -15,15 +15,15 @@ type Props = $ReadOnly<{||}>; * * allows by switching it to control the `away` status */ export default function AwayStatusSwitch(props: Props): Node { + const auth = useSelector(getAuth); const awayStatus = useSelector(getSelfUserAwayStatus); - const dispatch = useDispatch(); return ( { - dispatch(updateUserAwayStatus(away)); + api.updateUserStatus(auth, { away }); }} /> ); diff --git a/src/actions.js b/src/actions.js index 88b04f2b4c9..207f7574133 100644 --- a/src/actions.js +++ b/src/actions.js @@ -10,8 +10,6 @@ export * from './outbox/outboxActions'; export * from './session/sessionActions'; export * from './settings/settingsActions'; export * from './streams/streamsActions'; -export * from './subscriptions/subscriptionsActions'; export * from './topics/topicActions'; export * from './typing/typingActions'; export * from './users/usersActions'; -export * from './user-status/userStatusActions'; diff --git a/src/streams/CreateStreamScreen.js b/src/streams/CreateStreamScreen.js index 3e3ceb2af07..9728c52a644 100644 --- a/src/streams/CreateStreamScreen.js +++ b/src/streams/CreateStreamScreen.js @@ -5,11 +5,12 @@ import type { Node } from 'react'; import type { RouteProp } from '../react-navigation'; import type { AppNavigationProp } from '../nav/AppNavigator'; import * as NavigationService from '../nav/NavigationService'; -import { useSelector, useDispatch } from '../react-redux'; -import { createNewStream, navigateBack } from '../actions'; -import { getOwnEmail } from '../selectors'; +import { useSelector } from '../react-redux'; +import { navigateBack } from '../actions'; +import { getAuth, getOwnEmail } from '../selectors'; import { Screen } from '../common'; import EditStreamCard from './EditStreamCard'; +import * as api from '../api'; type Props = $ReadOnly<{| navigation: AppNavigationProp<'create-stream'>, @@ -17,15 +18,15 @@ type Props = $ReadOnly<{| |}>; export default function CreateStreamScreen(props: Props): Node { - const dispatch = useDispatch(); + const auth = useSelector(getAuth); const ownEmail = useSelector(getOwnEmail); const handleComplete = useCallback( (name: string, description: string, isPrivate: boolean) => { - dispatch(createNewStream(name, description, [ownEmail], isPrivate)); + api.createStream(auth, name, description, [ownEmail], isPrivate); NavigationService.dispatch(navigateBack()); }, - [ownEmail, dispatch], + [auth, ownEmail], ); return ( diff --git a/src/streams/StreamSettingsScreen.js b/src/streams/StreamSettingsScreen.js index 7f46aa5548a..809a5921da5 100644 --- a/src/streams/StreamSettingsScreen.js +++ b/src/streams/StreamSettingsScreen.js @@ -6,18 +6,14 @@ import { View } from 'react-native'; import type { RouteProp } from '../react-navigation'; import type { AppNavigationProp } from '../nav/AppNavigator'; import * as NavigationService from '../nav/NavigationService'; -import { useDispatch, useSelector } from '../react-redux'; +import { useSelector } from '../react-redux'; import { delay } from '../utils/async'; import { SwitchRow, Screen, ZulipButton } from '../common'; import { getSettings } from '../directSelectors'; import { getAuth, getIsAdmin, getStreamForId } from '../selectors'; import StreamCard from './StreamCard'; import { IconPin, IconMute, IconNotifications, IconEdit, IconPlusSquare } from '../common/Icons'; -import { - setSubscriptionProperty, - navigateToEditStream, - navigateToStreamSubscribers, -} from '../actions'; +import { navigateToEditStream, navigateToStreamSubscribers } from '../actions'; import styles from '../styles'; import { getSubscriptionsById } from '../subscriptions/subscriptionSelectors'; import * as api from '../api'; @@ -29,8 +25,6 @@ type Props = $ReadOnly<{| |}>; export default function StreamSettingsScreen(props: Props): Node { - const dispatch = useDispatch(); - const auth = useSelector(getAuth); const isAdmin = useSelector(getIsAdmin); const stream = useSelector(state => getStreamForId(state, props.route.params.streamId)); @@ -41,16 +35,16 @@ export default function StreamSettingsScreen(props: Props): Node { const handleTogglePinStream = useCallback( (newValue: boolean) => { - dispatch(setSubscriptionProperty(stream.stream_id, 'pin_to_top', newValue)); + api.setSubscriptionProperty(auth, stream.stream_id, 'pin_to_top', newValue); }, - [dispatch, stream], + [auth, stream], ); const handleToggleMuteStream = useCallback( (newValue: boolean) => { - dispatch(setSubscriptionProperty(stream.stream_id, 'is_muted', newValue)); + api.setSubscriptionProperty(auth, stream.stream_id, 'is_muted', newValue); }, - [dispatch, stream], + [auth, stream], ); const handlePressEdit = useCallback(() => { @@ -71,8 +65,8 @@ export default function StreamSettingsScreen(props: Props): Node { const handleToggleStreamPushNotification = useCallback(() => { const currentValue = getIsNotificationEnabled(subscription, userSettingStreamNotification); - dispatch(setSubscriptionProperty(stream.stream_id, 'push_notifications', !currentValue)); - }, [dispatch, stream, subscription, userSettingStreamNotification]); + api.setSubscriptionProperty(auth, stream.stream_id, 'push_notifications', !currentValue); + }, [auth, stream, subscription, userSettingStreamNotification]); return ( diff --git a/src/streams/streamsActions.js b/src/streams/streamsActions.js index e4275f0ce20..b6b4414362f 100644 --- a/src/streams/streamsActions.js +++ b/src/streams/streamsActions.js @@ -3,15 +3,6 @@ import type { Stream, ThunkAction } from '../types'; import * as api from '../api'; import { getAuth, getZulipFeatureLevel } from '../selectors'; -export const createNewStream = ( - name: string, - description: string, - principals: string[], - isPrivate: boolean, -): ThunkAction> => async (dispatch, getState) => { - await api.createStream(getAuth(getState()), name, description, principals, isPrivate); -}; - export const updateExistingStream = ( id: number, initialValues: Stream, diff --git a/src/subscriptions/subscriptionsActions.js b/src/subscriptions/subscriptionsActions.js deleted file mode 100644 index 119686e7744..00000000000 --- a/src/subscriptions/subscriptionsActions.js +++ /dev/null @@ -1,13 +0,0 @@ -/* @flow strict-local */ -import type { ThunkAction } from '../types'; -import { getAuth } from '../selectors'; -import type { SubscriptionProperty } from '../api/subscriptions/setSubscriptionProperty'; -import * as api from '../api'; - -export const setSubscriptionProperty = ( - streamId: number, - property: SubscriptionProperty, - value: boolean, -): ThunkAction> => async (dispatch, getState) => { - await api.setSubscriptionProperty(getAuth(getState()), streamId, property, value); -}; diff --git a/src/user-status/UserStatusScreen.js b/src/user-status/UserStatusScreen.js index 0af77962799..bf283d7cea8 100644 --- a/src/user-status/UserStatusScreen.js +++ b/src/user-status/UserStatusScreen.js @@ -8,13 +8,13 @@ import { createStyleSheet } from '../styles'; import type { RouteProp } from '../react-navigation'; import type { AppNavigationProp } from '../nav/AppNavigator'; import * as NavigationService from '../nav/NavigationService'; -import { useSelector, useDispatch } from '../react-redux'; +import { useSelector } from '../react-redux'; import { Input, SelectableOptionRow, Screen, ZulipButton } from '../common'; -import { getSelfUserStatusText } from '../selectors'; +import { getAuth, getSelfUserStatusText } from '../selectors'; import { IconCancel, IconDone } from '../common/Icons'; import statusSuggestions from './userStatusTextSuggestions'; -import { updateUserStatusText } from './userStatusActions'; import { navigateBack } from '../nav/navActions'; +import * as api from '../api'; const styles = createStyleSheet({ statusTextInput: { @@ -35,7 +35,7 @@ type Props = $ReadOnly<{| |}>; export default function UserStatusScreen(props: Props): Node { - const dispatch = useDispatch(); + const auth = useSelector(getAuth); const userStatusText = useSelector(getSelfUserStatusText); const [statusText, setStatusText] = useState(userStatusText); @@ -43,10 +43,10 @@ export default function UserStatusScreen(props: Props): Node { const sendToServer = useCallback( (_statusText: string) => { - dispatch(updateUserStatusText(_statusText)); + api.updateUserStatus(auth, { status_text: _statusText }); NavigationService.dispatch(navigateBack()); }, - [dispatch], + [auth], ); const handlePressUpdate = useCallback(() => { diff --git a/src/user-status/userStatusActions.js b/src/user-status/userStatusActions.js deleted file mode 100644 index eba5a21432e..00000000000 --- a/src/user-status/userStatusActions.js +++ /dev/null @@ -1,20 +0,0 @@ -/* @flow strict-local */ -import type { ThunkAction } from '../types'; -import * as api from '../api'; -import { getAuth } from '../selectors'; - -export const updateUserAwayStatus = (away: boolean): ThunkAction> => async ( - dispatch, - getState, -) => { - const auth = getAuth(getState()); - api.updateUserStatus(auth, { away }); -}; - -export const updateUserStatusText = (statusText: string): ThunkAction> => async ( - dispatch, - getState, -) => { - const auth = getAuth(getState()); - api.updateUserStatus(auth, { status_text: statusText }); -};