Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Make the core save button work #14

Merged
merged 1 commit into from
Jan 19, 2023
Merged

Conversation

johnstonphilip
Copy link
Contributor

This PR un-hides the "Save" button in the pattern editor, and makes it work.

What this PR does not do:

  • It does not change any saving logic
  • It does not remove the existing top toolbar


const editorDirty = useRef( false );
const [ siteEditorDirty, setSiteEditorDirty ] = useState( false );
const [ requestPatternRefresh, setRequestPatternRefresh ] =
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 also removed some dead code here relating to the site editor

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@kienstra kienstra left a comment

Choose a reason for hiding this comment

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

Hi @johnstonphilip,
Nice work!

Saving from within the editor works:

the-bsdf


useEffect( () => {
const saveButtons = document.getElementsByClassName(
'editor-post-publish-panel__toggle'
Copy link
Contributor

Choose a reason for hiding this comment

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

This class could change, but it's better than importing the whole testing-library to search for the button text.

}

// While the above event listeners handle interrupting save button clicks, this also handles keyboard shortcut saves (like cmd+s).
subscribe( () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be nice if Gutenberg and React had a better event hook system, but this is what we have.

@@ -30,21 +30,8 @@ export default function usePatterns( initialPatterns: Patterns ) {
window.addEventListener(
'message',
( event ) => {
if ( event.data === 'patternmanager_site_editor_dirty' ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for removing the FSES-specific code.

@johnstonphilip johnstonphilip merged commit 62d9d21 into main Jan 19, 2023
@johnstonphilip johnstonphilip deleted the try/use-core-save-button branch January 19, 2023 15:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants