-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Handle remote editor load failure (#27)
* feat: Handle remote editor load failure Empower the user to continue editing with the default, local editor capable of editing core blocks and notify them of the load failure. * feat: Allow retrying remote editor load Empower users to resolve issues themselves. * feat: Update editor load notice message Increase the utility of the message. * refactor: Reduce `useEditorLoadNotice` API surface area Simplify hook usage. * task: Capture build results * task: Capture build output
- Loading branch information
Showing
15 changed files
with
143 additions
and
57 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
Demo-Android/Gutenberg/src/main/assets/assets/remote-hV9R00EW.css
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Notice } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
|
||
export default function EditorLoadNotice() { | ||
const { notice, clearNotice } = useEditorLoadNotice(); | ||
|
||
const actions = [ | ||
{ | ||
label: 'Retry', | ||
onClick: () => (window.location.href = 'remote.html'), | ||
variant: 'primary', | ||
}, | ||
{ | ||
label: 'Dismiss', | ||
onClick: clearNotice, | ||
variant: 'secondary', | ||
}, | ||
]; | ||
|
||
if (!notice) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="editor-load-notice"> | ||
<Notice actions={actions} status="warning" isDismissible={false}> | ||
{notice} | ||
</Notice> | ||
</div> | ||
); | ||
} | ||
|
||
function useEditorLoadNotice() { | ||
const [notice, setNotice] = useState(null); | ||
|
||
useEffect(() => { | ||
const url = new URL(window.location.href); | ||
const error = url.searchParams.get('error'); | ||
|
||
let message = null; | ||
switch (error) { | ||
case REMOTE_EDITOR_LOAD_ERROR: | ||
message = __( | ||
"Oops! We couldn't load your site's editor and plugins. Don't worry, you can use the default editor for now." | ||
); | ||
break; | ||
default: | ||
message = null; | ||
} | ||
|
||
setNotice(message); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (notice) { | ||
const timeout = setTimeout(() => { | ||
setNotice(null); | ||
}, 20000); | ||
return () => clearTimeout(timeout); | ||
} | ||
}, [notice]); | ||
|
||
return { notice, clearNotice: () => setNotice(null) }; | ||
} | ||
|
||
const REMOTE_EDITOR_LOAD_ERROR = 'remote_editor_load_error'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.