Skip to content

Commit

Permalink
streams: Display error if stream update fails.
Browse files Browse the repository at this point in the history
Displays a toast containing an error string if a call to
updateExistingStream returns a failed promise.

Fixes: #5286
  • Loading branch information
Fingel committed Mar 10, 2022
1 parent 11cbbd1 commit 5e0387a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/streams/CreateStreamScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default function CreateStreamScreen(props: Props): Node {
const ownEmail = useSelector(getOwnEmail);

const handleComplete = useCallback(
(name: string, description: string, isPrivate: boolean) => {
api.createStream(auth, name, description, [ownEmail], isPrivate);
async (name: string, description: string, isPrivate: boolean) => {
await api.createStream(auth, name, description, [ownEmail], isPrivate);
NavigationService.dispatch(navigateBack());
},
[auth, ownEmail],
Expand Down
2 changes: 1 addition & 1 deletion src/streams/EditStreamCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Props = $ReadOnly<{|
description: string,
invite_only: boolean,
|},
onComplete: (name: string, description: string, isPrivate: boolean) => void,
onComplete: (name: string, description: string, isPrivate: boolean) => Promise<void>,
|}>;

type State = {|
Expand Down
11 changes: 9 additions & 2 deletions src/streams/EditStreamScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as NavigationService from '../nav/NavigationService';
import { useSelector, useDispatch } from '../react-redux';
import { updateExistingStream, navigateBack } from '../actions';
import { getStreamForId } from '../selectors';
import { showToast } from '../utils/info';
import Screen from '../common/Screen';
import EditStreamCard from './EditStreamCard';

Expand All @@ -21,8 +22,14 @@ export default function EditStreamScreen(props: Props): Node {
const stream = useSelector(state => getStreamForId(state, props.route.params.streamId));

const handleComplete = useCallback(
(name: string, description: string, isPrivate: boolean) => {
dispatch(updateExistingStream(stream.stream_id, stream, { name, description, isPrivate }));
async (name: string, description: string, isPrivate: boolean) => {
try {
await dispatch(
updateExistingStream(stream.stream_id, stream, { name, description, isPrivate }),
);
} catch (error) {
showToast(error.message);
}
NavigationService.dispatch(navigateBack());
},
[stream, dispatch],
Expand Down

0 comments on commit 5e0387a

Please sign in to comment.