janboddez / share-on-mastodon

Easily share WordPress posts on Mastodon.
https://jan.boddez.net/wordpress/share-on-mastodon
GNU General Public License v3.0
39 stars 5 forks source link

Gutenberg sidebar panel #72

Closed janboddez closed 12 months ago

janboddez commented 1 year ago

We can move the checkbox / link to the resulting Mastodon status to a custom sidebar.

To set the default checkbox state (opt-out or opt-in), we can use https://make.wordpress.org/core/2020/08/04/registering-default-values-for-meta-data/. To not have this affect the classic editor, we can use get_metadata_raw() there. (I think.)

The link bit / "unlink" button will be "tricky," but only because I refuse to "learn" (or write) JSX.

janboddez commented 1 year ago

The link bit / "unlink" button will be "tricky," but only because I refuse to "learn" (or write) JSX.

Think I got it working using a REST API call... (Simply setting the meta field, using useEntityProp, etc., to '' has no immediate effect.)

Thing I'm struggling with next is having the link show right away, after publishing (i.e., instead of after an actual page refresh). Think I can check for a change in post status, but I'm not sure how to fetch the updated meta (if that's even possible).

janboddez commented 1 year ago

Guess it doesn't show because it takes ~a second or two for sharing to take place (that's if no delay is set) so we should probably listen for a change in post status (to publish) and then add a couple seconds delay. And then somehow ensure the meta are updated/refetched.

janboddez commented 1 year ago

Guess it doesn't show because it takes ~a second or two for sharing to take place (that's if no delay is set) so we should probably listen for a change in post status (to publish) and then add a couple seconds delay. And then somehow ensure the meta are updated/refetched.

Turns out this is ... not very easy. So instead of, e.g., forcing a full page refresh, may look into Gutenberg's notices instead.

janboddez commented 1 year ago

Maybe I could also, instead of depend on React's render logic and so on, simply create a completely separate script that listens (how?) for a publish or so event and then refreshes only the link, using good ol' AJAX.

janboddez commented 1 year ago

[M]ay look into Gutenberg's notices instead.

https://developer.wordpress.org/block-editor/reference-guides/components/notice/

Thing is, once more, how do we trigger these?

Plus, much like "classic" notices, they're pretty useless when delayed posting is in action.

Also, I have tried something like this: https://wordpress.stackexchange.com/questions/413949/display-notice-in-block-editor-after-wp-insert-post-data-hook in order to trigger a timer which would then change state in order to refetch meta but that doesn't seem to happen. Fetching the value on its own (custom API endpoint or regular AJAX call) may very well work.

janboddez commented 12 months ago

And, it's merged.

The missing bits, like showing errors the way we show a URL if sharing was successful (and, later on, using a notice?) will have to come later.