Skip to content

Add attachment picker to Expensify Chat - #463

Merged
tgolen merged 20 commits into
masterfrom
joe-attachments
Sep 21, 2020
Merged

tgolen merged 20 commits into
masterfrom
joe-attachments

Conversation

@Jag96

@Jag96 Jag96 commented Sep 11, 2020 •

Copy link
Copy Markdown
Contributor

@tgolen @AndrewGable will you please review this?

Fixes #87

Details

This PR adds support for uploading images on iOS/Android, and files on web.
This issue still exists on React Native version 0.63+, so to fix this I've added the patch-package dependency to allow us to apply the 1 line fix for this issue rather than dealing with reverting the RN version to 0.62.2, which requires that we manually manage pods in the podfile instead of using use_react_native!(:path => config["reactNativePath"]) to manage all of them. Once the fix for the RN issue is merged, we can simply remove the patch-package line in package.json, and remove the patch directory.

Tests

  1. Go to a report on web and hit the attachment icon, confirm a file picker shows.
  2. Upload a file, confirm you see the attachment loading placeholder.
  3. Confirm after the file uploads, the thumbnail image displays properly
  4. Hit the attachment icon on iOS/Android, confirm you can upload an image from the photo library, and the attachment loading placeholder shows while the file is uploading
  5. Hit the attachment icon on iOS/Android, confirm you can upload an image by taking a picture, and the attachment loading placeholder shows while the file is uploading

@Jag96 Jag96 self-assigned this Sep 11, 2020

@tgolen tgolen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just an initial review

}

const ImagePicker = {
showImagePicker(options, callback) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this const is an object with just one property, I think the object is unnecessary. This should just be:

const ImagePicker = (options, callback) => ....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ended up adding one more property here, but this is good to know 👍

updateComment(newComment) {
this.setState({
comment: newComment,
onAttachmentButtonTapped(e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rename to uploadAttachment() (methods should be named for what they do, not what they handle)

e.preventDefault();
}

const reportID = this.props.reportID;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unnecessary variable

this.setState({
comment: newComment,
onAttachmentButtonTapped(e) {
if (e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think there is a case where there wouldn't be an event, would there?

@Jag96

Jag96 commented Sep 12, 2020

Copy link
Copy Markdown
Contributor Author

This is mostly done, I just need to work around the upload issue on 0.63+ so this runs without a local fix. Going to try to change the RN version to 0.62.2 which was the last working version before this issue.

After a quick npm install it seems that the react_native_pods lib we require in the first line of our Podfile isn't in 0.62.2 (or is named something different), so the pod install script fails. I'll have a look at this next week, and once that's done this will be ready for review.

const propTypes = {
// The URL to open
href: PropTypes.string.isRequired,
href: PropTypes.string,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was causing a warning on iOS/Android, so I updated it to match web

@Jag96
Jag96 requested a review from AndrewGable September 15, 2020 03:42
@Jag96 Jag96 changed the title [WIP] Add attachment picker to Expensify Chat Add attachment picker to Expensify Chat Sep 15, 2020
@Jag96

Jag96 commented Sep 15, 2020

Copy link
Copy Markdown
Contributor Author

This is off WIP and ready for review. I've added some context in the description for why I opted to use patch-package instead of reverting the RN version to 0.62.2 to get this working. If there's any questions lmk!

Comment thread src/lib/ImagePicker/index.js Outdated

const ImagePicker = {
showImagePicker(options, callback) {
const {files} = input;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This destructuring really isn't valuable IMO since it's only referenced once.

Comment thread src/lib/ImagePicker/index.js Outdated
input.value = '';
}

function onfocus() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have been avoiding nested functions in this code, so I would recommend just using an anonymous function when the event listener is added.

Comment thread src/lib/ImagePicker/index.js Outdated
showImagePicker(options, callback) {
const {files} = input;

// Clear previously saved files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than having to deal with previously saved files, and also ensuring that the onFocus event is removed, I think it would simplify the code a little bit and prevent side-effects if the input was created and destroyed every time showImagePicker() is called.

Comment thread src/lib/ImagePicker/index.js Outdated
body.removeEventListener('focus', onfocus, true);

// Add a 500 millisecond delay here to ensure input.files is set before checking it
_.delay(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've been looking at this, trying to figure out why the delay is necessary. My gut tells me that it shouldn't be necessary, and the comment above doesn't really explain why input.files wouldn't be set. Maybe listening to the change event would be better? I'd love to see you find a way to remove this delay completely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'll have a look and see if I can get it working without a delay

/**
* Handle the attachment icon being tapped
*
* @param {SyntheticEvent} [e]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param {SyntheticEvent} [e]
* @param {SyntheticEvent} e

Looks like it's required

showImagePicker(options, callback) {
const input = document.createElement('input');
input.type = 'file';
input.onchange = function () {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated this to use the onchange event which simplified this a ton, the only caveat being that we don't know when the user hits cancel since this event doesn't fire on cancel. However, we aren't looking to take any specific actions on cancel, so I think this is fine.

I did some testing with other events as well and I wasn't able to find a good solution that was able to tell if the user canceled without adding some sort of delay. There were a few StackOverflow posts that used jQuery and claimed that the onChange event fired on cancel, but it didn't work in testing.

@Jag96

Jag96 commented Sep 18, 2020

Copy link
Copy Markdown
Contributor Author

Updated and re-tested, this is ready for another look. I also confirmed that the image picker and take photo functionality work on my iOS device (@AndrewGable tested on an Android device).

@tgolen
tgolen merged commit c5eb359 into master Sep 21, 2020
@tgolen
tgolen deleted the joe-attachments branch September 21, 2020 15:10
@mallenexpensify

Copy link
Copy Markdown
Contributor

Experiencing two issues.

  1. The grey upload spinny 'image' isn't disappearing some times, even after the image is uploaded
  2. When uploading an image (use a larger file to test), if I type in text while it's uploading, it sometimes disappears, or appears shortly then disappears.

Both can be seen in this video.
https://www.screencast.com/t/r64X1W8y6c

To Reproduce

  1. Click paperclip to upload file, ideally choose larger file
  2. Start typing a message immediately after the file starts to upload
  3. watch to see if any text disappears
  4. Also see if the grey spinny 'image' disappears.

@Jag96

Jag96 commented Sep 21, 2020

Copy link
Copy Markdown
Contributor Author

Created an issue here and assigned myself to investigate

@mallenexpensify

Copy link
Copy Markdown
Contributor

The above was on Desktop v.62. I just tested on web (after clearing cookies) and had the exact same issues

@tgolen

tgolen commented Sep 21, 2020

Copy link
Copy Markdown
Contributor

Just a heads up, but that issue with the spinner not disappearing is almost certainly caused by the same thing being discussed in #466 which requires a pretty extensive fix.

@Jag96

Jag96 commented Sep 21, 2020

Copy link
Copy Markdown
Contributor Author

Ah thanks for the info, that makes sense as I didn't see anything obvious in my additions that would be causing that. I'll close the spinner issue and leave a note to only reopen if we can reproduce after #466 is merged.

sajal101agrawal pushed a commit to sajal101agrawal/expensify-app that referenced this pull request Sep 16, 2026
Add attachment picker to Expensify Chat
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.

Add image attachments

4 participants