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

Unprofile: add avatar image upload #37

Closed
wants to merge 4 commits into from

Conversation

rorysaur
Copy link
Contributor

@rorysaur rorysaur commented Jun 7, 2022

  • Uses react-image-file-resizer to auto-resize image to a max of 500x500. I can probably do it without the library (via canvas), but it would be rather verbose.
  • Shows avatar in Explorer
  • Unrelated extra: adds link from Unprofile success alert to Explorer

Addresses #15

Empty state:
Screen Shot 2022-06-07 at 1 17 55 AM

Populated state:
Screen Shot 2022-06-07 at 1 17 36 AM

Explorer:
Screen Shot 2022-06-07 at 1 52 08 AM

@rorysaur rorysaur added explorer feature New feature or request unprofile labels Jun 7, 2022
@rorysaur rorysaur requested review from mgorkove and simonkernel June 7, 2022 05:53
Copy link
Contributor

@simonkernel simonkernel left a comment

Choose a reason for hiding this comment

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

Main comment around ensuring file size is <1MB and removing the external dep.

@@ -17,6 +17,7 @@
"ethers": "5.6.8",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-image-file-resizer": "^0.4.8",
Copy link
Contributor

Choose a reason for hiding this comment

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

This library doesn't add enough value to warrant adding it IMHO.

const payload = target.type === 'checkbox' ? target.checked : target.value
dispatch({ type, payload })
} catch (error) {
console.log(error)
}
}

const onAvatarChange = (dispatch, target) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you should define fns before they are called ex. this is called in change and then defined later. It should be switched.


import AppConfig from 'App.config'

const AVATAR_CONFIG = {
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this ensure the size stays below a limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you mean the file size, it doesn't, and neither would a straightforward canvas implementation. I figure there is an upper bound to how large of a file a 500x500 image can be, and resizing it by height/width would keep it reasonably small in the vast majority of cases (or maybe in all cases if there's not some way that a 500x500 image can be huge). Since you didn't seem to be attached to a specific hard limit, it didn't feel necessary to sink more effort into enforcing both a max height/width and a max file size.

Copy link
Contributor

Choose a reason for hiding this comment

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

File size is my primary concern and it should definitely be checked.


if (type === 'avatar') {
onAvatarChange(dispatch, target)
target.value = null // reset so onChange will fire even for same image
Copy link
Contributor

Choose a reason for hiding this comment

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

the dom cannot directly be manipulated in react.

I recommend you read up on controlled vs uncontrolled components:
https://reactjs.org/docs/uncontrolled-components.html

</label>

<div className='mb-2 text-sm text-gray-700'>
Upload a JPEG or PNG. Recommended size is 500 x 500.
Copy link
Contributor

Choose a reason for hiding this comment

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

why jpeg and png?

Copy link
Contributor Author

@rorysaur rorysaur Jun 10, 2022

Choose a reason for hiding this comment

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

Those are just the ones I know should render properly for everyone.

className='px-6 py-3 w-full bg-kernel-eggplant-mid text-white rounded text-center cursor-pointer'
>
<input
type='file' accept='image/png, image/jpeg'
Copy link
Contributor

Choose a reason for hiding this comment

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

we should use image/* so mobile phones allow you to take a picture with the camera

see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept#unique_file_type_specifiers

@rorysaur
Copy link
Contributor Author

Closing this as I won't be able to finish it; anyone is welcome to pick up the branch and proceed!

@rorysaur rorysaur closed this Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
explorer feature New feature or request unprofile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants