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

fixes #5 Feature: Sending Images #6

Merged
merged 3 commits into from
Feb 16, 2022
Merged

fixes #5 Feature: Sending Images #6

merged 3 commits into from
Feb 16, 2022

Conversation

DillonKylePortfolio
Copy link
Owner

Description

fixes #5

We can now attach and send multiple or single image messages along with any accompanying text.

Some other ways we could have handled this

  1. Our current implementation is on the simple side. We could give the user more of an indication that the image they have uploaded was successfully uploaded by adding a preview of each uploaded image right before the user submits the message.

Drawbacks: This would have complicated the render() function and made it a bit harder to read.

  1. We could have extracted out our upload functionality to a separate component in order to make the render() function of the component a little cleaner.

Drawbacks: This would have created the necessity to pass urls as props back up to the component via a function prop, which would have made it harder to track what was happening functionally.

Screenshot

ImagesExample1

Copy link
Collaborator

@FilipeGorodscy FilipeGorodscy left a comment

Choose a reason for hiding this comment

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

Thank you for your work on this PR.

Let us know when the changes are implemented by using the "/hatchy pr" command on Slack again and another reviewer will come by to give this PR another look and give you approval 👍🏻

Comment on lines 87 to 88
if(imageUrlInput.current.files && imageUrlInput.current.files.length === 1) {
const file = imageUrlInput.current.files[0];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will limit the user to send only one image at a time, we want to give the user the ability to upload multiple images at once 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you for all the great feedback!

Comment on lines 89 to 91
const formData = new FormData();
formData.append("file", file);
formData.append("upload_preset", "zm201ktq");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest hiding sensitive information in a .env file.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good call!

Comment on lines 92 to 102
const OPTIONS = {
method: "POST",
body: formData
}
fetch("https://api.cloudinary.com/v1_1/hatchypicturesticket/image/upload", OPTIONS)
.then(response => response.json())
.then(json => {
setPhotoUrl(json);
})
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of using .then() I suggest using async/await to stay consistent with the codebase
Instead of using fetch I suggest using axios with the transformRequest to stay consistent with the rest of the codebase :)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Consistency is key! I'll change that over


const setPhotoUrl = (response) => {
photoUrls.current = [...photoUrls.current, response.secure_url];
console.log(photoUrls.current);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should avoid having unnecessary console.log statements in your PRs 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

Whoops! Taken care of!

/>
</FormControl>
</form>
<div className={classes.attatchFileContainer}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should not mix JSX with Material UI components. Every div should be replaced by Box or Grid.

{ modalOpen && (
<form type="submit" onSubmit={(e) => handleUpload(e)} className={classes.photoForm}>
<input ref={imageUrlInput} type="file" accept="image/png, image/jpg" className={classes.chooseFilesButton}/>
<button className={classes.sendButton}>Upload</button>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above 🙂

Copy link
Owner Author

Choose a reason for hiding this comment

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

I was able to change out the <form> and <button> elements to use MUI but I wasn't able to find a solution for the <input> element within MUI for uploading files. Here is a link to the MUI GitHub page regarding the issue:

mui/material-ui#9716

Dropzone, an external npm package is apparently an option, but the brief mentioned no external packages were allowed:

https://www.npmjs.com/package/material-ui-dropzone

So I just used the default <input> element instead.

Comment on lines -15 to +17
<SenderBubble key={message.id} text={message.text} time={time} />
<SenderBubble key={message.id} text={message.text} attachments={message.attachments} time={time} />
) : (
<OtherUserBubble key={message.id} text={message.text} time={time} otherUser={otherUser} />
<OtherUserBubble key={message.id} text={message.text} attachments={message.attachments} time={time} otherUser={otherUser} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

💯

<Box className={classes.bubble}>
<Typography className={classes.text}>{text}</Typography>
</Box>
<div className={classes.paperContainer}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above 🙂

Comment on lines 45 to 63
{ attachments && attachments.length > 0 &&
<Box className={classes.attachmentsBox}>
{ attachments.map(photoUrl => {
return (
<Paper variant="outlined" key={photoUrl} className={classes.attachmentsPaper}>
<img src={photoUrl}
className={classes.imageThumbnail}
alt="thumbnail of sent"
aria-label="thumbnail of sent"/>
</Paper>
)
})}
</Box>
}
{ text !== "" &&
<Box className={classes.bubble}>
<Typography className={classes.text}>{text}</Typography>
</Box>
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

When sending multiple images, the message text should be displayed above the messages.
When sending multiple images, the image size should be reduced.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Copy that!

Copy link
Owner Author

Choose a reason for hiding this comment

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

I took screenshots of the changes but I forgot to add them! Here's a screenshot of sending the images:

ChangesMade

Here's a screenshot of receiving those same images:

ChangesMadeFromTheOtherSide

Comment on lines 54 to 74
<div className={classes.paperContainer}>
{ attachments && attachments.length > 0 &&
<Box className={classes.attachmentsBox}>
{ attachments.map(photoUrl => {
return (
<Paper variant="outlined" key={photoUrl} className={classes.attachmentsPaper}>
<img src={photoUrl}
className={classes.imageThumbnail}
alt="thumbnail of sent"
aria-label="thumbnail of sent"/>
</Paper>
)
})}
</Box>
}
{ text !== "" &&
<Box className={classes.bubble}>
<Typography className={classes.text}>{text}</Typography>
</Box>
}
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above 🙂

DillonKyleDev added 2 commits February 15, 2022 20:34
…ns. Removed conflicting JSX from render. Changed Fetch to axios for consistency. Added ability to upload multiple files at once.
Copy link
Collaborator

@Tahoum Tahoum left a comment

Choose a reason for hiding this comment

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

Thank you for implementing the changes 👍🏽
This PR is ready to be merged ✅

@DillonKylePortfolio DillonKylePortfolio merged commit 37961b3 into main Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Sending images - front end
3 participants