Skip to content

Commit f2fc9db

Browse files
author
Dan Carbonell
committed
added comments, removed await
1 parent c93fa27 commit f2fc9db

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/components/MessageInput.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class MessageInput extends PureComponent {
130130
);
131131
this.state = {
132132
...state,
133-
asyncIds: Immutable([]),
134-
asyncUploads: Immutable({}),
133+
asyncIds: Immutable([]), // saves data for images that resolve after hitting send
134+
asyncUploads: Immutable({}), // saves data for images that resolve after hitting send
135135
sending: false,
136136
};
137137
}
@@ -339,12 +339,12 @@ class MessageInput extends PureComponent {
339339

340340
componentDidUpdate(prevProps) {
341341
if (Object.keys(this.state.asyncUploads).length) {
342+
/**
343+
* When successful image upload response occurs after hitting send,
344+
* send a follow up message with the image
345+
*/
342346
this.setState({ sending: true });
343-
344-
this.state.asyncIds.forEach((id) => {
345-
this.sendMessageAsync(id);
346-
});
347-
347+
this.state.asyncIds.forEach((id) => this.sendMessageAsync(id));
348348
this.setState({ sending: false });
349349
}
350350

@@ -478,6 +478,10 @@ class MessageInput extends PureComponent {
478478
if (image.state === FileState.UPLOADING) {
479479
// TODO: show error to user that they should wait until image is uploaded
480480
if (this.props.sendImageAsync) {
481+
/**
482+
* If user hit send before image uploaded, push ID into a queue to later
483+
* be matched with the successful CDN response
484+
*/
481485
this.setState((prevState) => ({
482486
asyncIds: [...prevState.asyncIds, id],
483487
}));
@@ -539,7 +543,7 @@ class MessageInput extends PureComponent {
539543
this.setState({ sending: false });
540544
} else {
541545
try {
542-
await this.props.sendMessage({
546+
this.props.sendMessage({
543547
text,
544548
parent: this.props.parent,
545549
mentioned_users: uniq(this.state.mentioned_users),
@@ -761,6 +765,7 @@ class MessageInput extends PureComponent {
761765
.sendImage(file.uri, null, contentType)
762766
.then((res) => {
763767
if (this.state.asyncIds.includes(id)) {
768+
// Evaluates to true if user hit send before image successfully uploaded
764769
this.setState((prevState) => ({
765770
asyncUploads: prevState.asyncUploads
766771
.setIn([id, 'state'], FileState.UPLOADED)

0 commit comments

Comments
 (0)