Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streams: Display error if stream update fails. #5289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also preemptively add a try/catch and show a toast here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good thought -- let's handle this the same way.

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