From 5e0387a7975e6d4bc596b15a6424e7620ede9f14 Mon Sep 17 00:00:00 2001 From: Austin Riba Date: Thu, 10 Mar 2022 09:13:49 -0800 Subject: [PATCH] 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 --- src/streams/CreateStreamScreen.js | 4 ++-- src/streams/EditStreamCard.js | 2 +- src/streams/EditStreamScreen.js | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/streams/CreateStreamScreen.js b/src/streams/CreateStreamScreen.js index 62d8f66cebe..97de116be81 100644 --- a/src/streams/CreateStreamScreen.js +++ b/src/streams/CreateStreamScreen.js @@ -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], diff --git a/src/streams/EditStreamCard.js b/src/streams/EditStreamCard.js index 72f9c437358..53e3cb3c748 100644 --- a/src/streams/EditStreamCard.js +++ b/src/streams/EditStreamCard.js @@ -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, |}>; type State = {| diff --git a/src/streams/EditStreamScreen.js b/src/streams/EditStreamScreen.js index cf0479d8529..7454b9f81c3 100644 --- a/src/streams/EditStreamScreen.js +++ b/src/streams/EditStreamScreen.js @@ -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'; @@ -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],