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

EditGravatar: Add image editor step #9317

Merged
merged 1 commit into from
Nov 16, 2016
Merged

EditGravatar: Add image editor step #9317

merged 1 commit into from
Nov 16, 2016

Conversation

v18
Copy link
Contributor

@v18 v18 commented Nov 11, 2016

This PR adds the ability to edit and crop an image to a square before uploading it to Gravatar. Here's what it looks like:

image-editor-v2

Steps to test

  1. Run using ENABLE_FEATURES=me/edit-gravatar make run
  2. Get a bearer token using this script:
    curl -# -X POST --data-urlencode "grant_type=password" --data-urlencode "client_id=appid" --data-urlencode "client_secret=appsecret" --data-urlencode "username=username" --data-urlencode "password=password" https://public-api.wordpress.com/oauth2/token
    
    You can use Calypso's app ID & secret, found here.
    If you have 2FA enabled, you can add this extra parameter to the call: --data-urlencode "wpcom_otp=one-time-password", or you can create a new application password to use instead.
  3. Save the bearer token to localStorage using localStorage.setItem('bearerToken', 'your_bearer_token');
  4. Go to /me and upload a new Gravatar, see that you can edit it before uploading

Still to do:

  • Add error handling for unsupported file extensions
  • Add error handling for response from image editor

@v18 v18 added [Feature] User & Account Settings (/me) Settings and tools for managing your WordPress.com user account. [Status] In Progress labels Nov 11, 2016
@matticbot
Copy link
Contributor

@v18 v18 force-pushed the add/gravatar-image-editor branch 2 times, most recently from 1e5bbcd to 224b054 Compare November 13, 2016 00:00
@v18 v18 added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Nov 13, 2016
isEditingImage: true,
image: imageObjectUrl
} );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a semicolon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 added

translate( "We couldn't save that image, please try another one" )
);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also a semicolon here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you mean for the onImageEditorDone function - if so, added.

@@ -21,14 +25,26 @@ import {
} from 'state/current-user/gravatar-status/selectors';
import { isOffline } from 'state/application/selectors';
import Spinner from 'components/spinner';
import { uploadGravatar } from 'state/current-user/gravatar-status/actions';
import {
receiveImageFailed,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should rename this to receiveGravatarImageFailed in gravatar-status/actions in case we move toward global actions too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like it. Updated!

receiveImageFailed: receiveImageFailedAction,
translate
} = this.props;
const extension = path.extname( files[ 0 ].name ).toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to remove the leading . here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, done.

} else {
debug( 'Oops - no bearer token.' );
}
}

hideImageEditor = ( imageEditorProps ) => {
const { resetAllImageEditorState } = imageEditorProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a heads up that we'll likely refactor this in the future so callers need to import the resetAllImageEditorState action instead of being passed back in the callback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, thanks for the heads up. I updated it to use the action directly now.

@@ -20,3 +20,31 @@
left: 50%;
transform: translate(-50%, -50%);
}

.edit-gravatar-modal.dialog.card {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need all 3 classes here to override the default specificity? Or can we get away with just .edit-gravatar-modal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, looks like we do. The reason is because the original CSS uses both classes in components/dialog/style.scss and we need to override some things.

import useMockery from 'test/helpers/use-mockery';
import { useSandbox } from 'test/helpers/use-sinon';

describe( 'EditGravatar', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I didn't bring this up earlier, but our component test docs are severely out of date. We now generally try to use shallow enzyme renders to test.

A good recent example of a component test can be seen at #9150 Ping me with any extra questions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We chatted over this. Since I'm using mockery only for mocking event, matches-selector and lib/oauth-token, and shallow for the tests, we're all set.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup sorry, misread that last night

@gwwar
Copy link
Contributor

gwwar commented Nov 15, 2016

Looking good so far 👍 I did notice that I'm not seeing an error message if the bearer token is missing.

@v18 v18 force-pushed the add/gravatar-image-editor branch from 224b054 to de6c9e0 Compare November 15, 2016 22:04
@v18
Copy link
Contributor Author

v18 commented Nov 15, 2016

Thanks! Added an error message when the bearer token is missing.

@gwwar
Copy link
Contributor

gwwar commented Nov 15, 2016

Great Job! :shipit:

@gwwar gwwar added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Nov 15, 2016
@v18 v18 merged commit 5aa5f35 into master Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] User & Account Settings (/me) Settings and tools for managing your WordPress.com user account.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants