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

Add Gutenberg prepublish panel to Autotweet post #44

Merged
merged 34 commits into from
Sep 27, 2019

Conversation

johnwatkins0
Copy link
Member

@johnwatkins0 johnwatkins0 commented Sep 17, 2019

This is intended to resolve #13. It depends on #37.

Description of the Change

This adds a PrePublishPanel to the Gutenberg editor when the user is working on a new post in a post type supporting autotweet.

While publishing, the user sees:

Screen Shot 2019-09-17 at 5 07 36 PM

After publication, we also add a PostStatusInfo message resembling the message that shown in the pre-Gutenberg implementation:

Screen Shot 2019-09-17 at 5 07 56 PM

Alternate Designs

Although #13 mentions PluginPostPublishPanel, I instead used Plugin*Pre*PublishPanel because the pre-publish panel allows us to re-use most of the existing backend code. The existing backend code sends the Tweet on post save; for a post-publish panel, we might have to create a whole different REST endpoint to handle a separate request to publish the post.

I also subjectively feel the prepublish panel is a better UX because it allows the user to think about the tweet along with the post content rather than as an afterthought. If there is a good reason to use PluginPostPublishPanel, however, the work in this PR would not need to be adjusted very much.

Benefits

Pre-5.0 functionality provided by this plugin is now provided via the Gutenberg editor.

Possible Drawbacks

A few things have come up that I believe should be added as to-dos for the next release:

  • After publication, there is no way to Tweet a post if a user initially opted out of tweeting or accidentally neglected to tweet.
  • There is also no way to Tweet a post that was already Tweeted, which it's possible to imagine some users wanting to do.
  • A user creating a new post doesn't see anything Autotweet-related until after clicking the Publish button, which could be confusing for new plugin users.

Verification Process

  • Verify that existing functionality still works when using a pre-Gutenberg version of WordPress
  • Using the Gutenberg editor, create a new post of a post type supporting Autotweet
  • When publishing a post, look for the prepublish panel related to Autotweet.
  • Opt in to autotweet. Override the message if desired
  • Verify that featured images are included in all scenarios
  • After publishing the post (both with and without tweeting the post), verify that the appropriate post status info message shows

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Adds Autotweet functionality to the Gutenberg editor.

package.json Outdated
@@ -4,7 +4,7 @@
"description": "Automatically tweets a post title, URL, and optional description.",
"scripts": {
"watch": "webpack -wd",
"build": "webpack -p",
"build": "webpack src/js/externals/api-fetch.js -o dist/api-fetch.js -p --module-bind js=babel-loader && webpack -p --config webpack.gutenberg.config.js",
Copy link
Member Author

Choose a reason for hiding this comment

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

Building the external api-fetch script via webpack CLI.

Choose a reason for hiding this comment

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

can we add a separate build:externals command, and keep the main build simpler? We would ideally store this in a more persistent externals output location and only rebuild when a new version of some external package is released.

src/js/index.js Outdated
const AutotweetPrePublishPanelPlugin = () => {
const [ enabledText, setEnabledText ] = useState( '' );

useEffect( () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need to use class components for the earlier 5.* WP versions that don't have React with hooks?

Choose a reason for hiding this comment

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

Right, we do need to make this work with WP 5.0 & 5.1 for now, which means classes for state.

@jeffpaul jeffpaul added the type:enhancement New feature or request. label Sep 17, 2019
@jeffpaul jeffpaul added this to the 1.0.0 milestone Sep 17, 2019
@adamsilverstein
Copy link

@johnwatkins0 Thank you for the work here! A few notes:

After publication, there is no way to Tweet a post if a user initially opted out of tweeting or accidentally neglected to tweet.

Would changing the status to draft then re-publishing give you that opportunity?

There is also no way to Tweet a post that was already Tweeted, which it's possible to imagine some users wanting to do.

Outside the scope of this issue

PluginPrePublishPanel

Yes, this makes more sense. Thanks.

I am going to do more testing with this. Some initial feedback:

  • I am prevented from typing more than 280 characters. Instead lets match the existing behavior: turn the counter red. It may be better to prevent typing more as you have it, so lets open a separate issue to discuss that and hopefully get some UX feedback (the whole counter component needs some refinement). cc: @oszkarnagy

  • the counter number needs a little whitespace to its left after the colon:

image

export const STORE = '10up/autotweet';

export function createAutotweetStore() {
const store = registerStore( STORE, { reducer, actions, selectors } );

Choose a reason for hiding this comment

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

Nice!

$failed_filter = function( $data, $id, $key ) use ( $post ) {
if ( intval( $post ) === intval( $id ) && $key === TWITTER_STATUS_KEY ) {
return [
'status' => 'error',

Choose a reason for hiding this comment

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

nitpick: extra space here before ->

$unknown_filter = function( $data, $id, $key ) use ( $post ) {
if ( intval( $post ) === intval( $id ) && $key === TWITTER_STATUS_KEY ) {
return [
'status' => 'unknown',

Choose a reason for hiding this comment

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

space

$other_filter = function( $data, $id, $key ) use ( $post ) {
if ( intval( $post ) === intval( $id ) && $key === TWITTER_STATUS_KEY ) {
return [
'status' => 'other',

Choose a reason for hiding this comment

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

space

@@ -0,0 +1,112 @@
<?php
/**
* Tests functions admin/post-meta.php.

Choose a reason for hiding this comment

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

Nice, thanks for adding these tests.

@adamsilverstein
Copy link

It would be great to display a confirmation and link to the tweet when a post is tweeted in the post publication section:

image

@adamsilverstein
Copy link

Note trying to tweet with the text field full it failed:

image

@adamsilverstein
Copy link

A user creating a new post doesn't see anything Autotweet-related until after clicking the Publish button, which could be confusing for new plugin users.

Another good follow up issue: might be as simple as adding a Gutenberg section in the Readme.

@@ -1,3 +1,3 @@
import apiFetch from '@wordpress/api-fetch';

wp.apiFetch = apiFetch;
global.wp.apiFetch = apiFetch;

Choose a reason for hiding this comment

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

why is global needed here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not. I left it there by accident. Removing it.

filename: '[name].js',
path: path.resolve( './dist' ),
},
externals: {

Choose a reason for hiding this comment

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

Excellent!

@adamsilverstein
Copy link

@johnwatkins0 Excellent! This is looking really good.

Reusing the PluginPostStatusInfo is perfect and it makes sense that it would work here.

I left a few small comments/questions and am going to test this locally then will approve.

label={
<span className="autotweet-prepublish__message-label">
<span>{ __( 'Custom message:', 'autotweet' ) }</span>
<span id="tenup-auto-tweet-counter-wrap" className={ overrideLengthClass() }>{ tweetText.length }</span>
Copy link

@adamsilverstein adamsilverstein Sep 27, 2019

Choose a reason for hiding this comment

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

The space is collapsing between the text and the count. (https://cl.ly/4f04884a8b03) fix by keeping closing span and opening span on same line with space (</span> <span>...)

Copy link
Member Author

Choose a reason for hiding this comment

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

I struggled with this a bit trying to make this suggestion work, and ended up using &nbsp; inside the first span.

Choose a reason for hiding this comment

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

that works! React loves to collapse whitespace, it usually preserves it if on the same line.

@@ -52,6 +94,11 @@ span#tenup-auto-tweet-counter-wrap{
background: rgba(0, 0, 0, 0.07);
font-family: Consolas, Monaco, monospace;
}

span.near-limit{
color: orange;

Choose a reason for hiding this comment

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

improve the contrast, orange was hard to see

Suggested change
color: orange;
color: darkorange;

// and save data when they update.
this.state = { autotweetEnabled: null, tweetText: null };

this.saveData = debounce( this.saveData.bind( this ), 1000 );

Choose a reason for hiding this comment

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

Let's lower the debounce to 250. I was able to click the tweet this checkbox then the publish button in under a second and the post didn't publish :) https://cl.ly/6ac0e9399675

Suggested change
this.saveData = debounce( this.saveData.bind( this ), 1000 );
this.saveData = debounce( this.saveData.bind( this ), 250 );

Copy link

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

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

Excellent work here @johnwatkins0 - this is looking really good and worked well in my testing. I left a few small core change requests, once these are in I will approve for merge!

@adamsilverstein adamsilverstein mentioned this pull request Sep 27, 2019
12 tasks
@johnwatkins0
Copy link
Member Author

@adamsilverstein Thanks @adamsilverstein . Pushed a few very tiny commits based on your most recent round of feedback. Let me know if you see anything else.

@johnwatkins0
Copy link
Member Author

I'll look at those conflicts.

@johnwatkins0
Copy link
Member Author

@adamsilverstein I've fixed the conflicts following the merging of #42

Copy link

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

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

Fantastic!

@johnwatkins0 johnwatkins0 merged commit 77c22e6 into develop Sep 27, 2019
@johnwatkins0 johnwatkins0 deleted the feature/publish-panel branch September 27, 2019 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement New feature or request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a publish metabox app for Gutenberg [8 hrs.]
3 participants