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

Improved message when clicking "Launch Course Builder" with unsaved changes #211

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/js/sidebar/course-builder/toolbar-launch-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @version 2.5.1
*/

import { select } from '@wordpress/data';
import { select, subscribe } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

const buttonId = 'llms-launch-course-builder-top-button';
Expand All @@ -18,6 +18,7 @@ const buttonId = 'llms-launch-course-builder-top-button';
* WordPress is installed in a subdirectory.
*/
export const addToolbarLaunchButton = () => {
let hasUnsavedChanges = false;
const editPostHeaderToolbarLeft = document.getElementsByClassName(
'edit-post-header-toolbar__left'
)[ 0 ];
Expand All @@ -42,8 +43,25 @@ export const addToolbarLaunchButton = () => {
button.className = 'llms-button-primary';
button.style.marginLeft = '16px';
button.innerHTML = __( 'Launch Course Builder', 'lifterlms' );
button.addEventListener( 'click', ( event ) => {
if (hasUnsavedChanges) {
event.preventDefault();

alert( __( 'You have unsaved changes. Please save your changes before launching the course builder.', 'lifterlms' ) );
}
} );

editPostHeaderToolbarLeft.appendChild( button );
}, 1 );

subscribe(() => {
const postEdits = select('core/editor').getPostEdits();

if (Object.keys(postEdits).length) {
hasUnsavedChanges = true;
} else {
hasUnsavedChanges = false;
}
});
};

Loading