Skip to content

Commit 5e0387a

Browse files
committed
streams: Display error if stream update fails.
Displays a toast containing an error string if a call to updateExistingStream returns a failed promise. Fixes: #5286
1 parent 11cbbd1 commit 5e0387a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/streams/CreateStreamScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export default function CreateStreamScreen(props: Props): Node {
2222
const ownEmail = useSelector(getOwnEmail);
2323

2424
const handleComplete = useCallback(
25-
(name: string, description: string, isPrivate: boolean) => {
26-
api.createStream(auth, name, description, [ownEmail], isPrivate);
25+
async (name: string, description: string, isPrivate: boolean) => {
26+
await api.createStream(auth, name, description, [ownEmail], isPrivate);
2727
NavigationService.dispatch(navigateBack());
2828
},
2929
[auth, ownEmail],

src/streams/EditStreamCard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Props = $ReadOnly<{|
2424
description: string,
2525
invite_only: boolean,
2626
|},
27-
onComplete: (name: string, description: string, isPrivate: boolean) => void,
27+
onComplete: (name: string, description: string, isPrivate: boolean) => Promise<void>,
2828
|}>;
2929

3030
type State = {|

src/streams/EditStreamScreen.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as NavigationService from '../nav/NavigationService';
88
import { useSelector, useDispatch } from '../react-redux';
99
import { updateExistingStream, navigateBack } from '../actions';
1010
import { getStreamForId } from '../selectors';
11+
import { showToast } from '../utils/info';
1112
import Screen from '../common/Screen';
1213
import EditStreamCard from './EditStreamCard';
1314

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

2324
const handleComplete = useCallback(
24-
(name: string, description: string, isPrivate: boolean) => {
25-
dispatch(updateExistingStream(stream.stream_id, stream, { name, description, isPrivate }));
25+
async (name: string, description: string, isPrivate: boolean) => {
26+
try {
27+
await dispatch(
28+
updateExistingStream(stream.stream_id, stream, { name, description, isPrivate }),
29+
);
30+
} catch (error) {
31+
showToast(error.message);
32+
}
2633
NavigationService.dispatch(navigateBack());
2734
},
2835
[stream, dispatch],

0 commit comments

Comments
 (0)