-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from wp-graphql/issue-4-hooks
First pass at creating a more extensible plugin
- Loading branch information
Showing
7 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
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,24 @@ | ||
# Actions & Filters | ||
|
||
-> [Original documentation](https://www.wpgraphql.com/docs/customizing-wpgraphiql) | ||
|
||
_legend_ 🎉 = new | ||
|
||
## PHP Actions | ||
|
||
- `wpgraphqlide_enqueue_script` ([enqueue_graphiql_extension](https://www.wpgraphql.com/docs/customizing-wpgraphiql#enqueue_graphiql_extension)) | ||
|
||
## PHP Filters | ||
|
||
- `wpgraphqlide_capability_required` 🎉 | ||
- `wpgraphqlide_context` 🎉 | ||
- `wpgraphqlide_external_fragments` ([graphiql_external_fragments](https://www.wpgraphql.com/docs/customizing-wpgraphiql#graphiql_external_fragments)) | ||
|
||
## JavaScript Actions | ||
|
||
- `wpgraphqlide_destroyed` 🎉 | ||
- `wpgraphqlide_rendered` ([graphiql_rendered](https://www.wpgraphql.com/docs/customizing-wpgraphiql#graphiql_rendered)) | ||
|
||
## JavaScript Filters | ||
|
||
... |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,15 +1,45 @@ | ||
import { useState } from '@wordpress/element'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
import { EditorDrawer } from './components/EditorDrawer'; | ||
import { Editor } from './components/Editor'; | ||
|
||
// Assuming wp.hooks is globally available through WordPress's script enqueueing mechanism. | ||
const { doAction } = wp.hooks; | ||
|
||
/** | ||
* The main application component. | ||
* | ||
* @returns {JSX.Element} The application component. | ||
*/ | ||
export function App() { | ||
const [ drawerOpen, setDrawerOpen ] = useState( false ); | ||
|
||
return ( | ||
<div className="AppRoot"> | ||
<EditorDrawer open={ drawerOpen } setDrawerOpen={ setDrawerOpen }> | ||
<Editor setDrawerOpen={ setDrawerOpen } /> | ||
</EditorDrawer> | ||
</div> | ||
); | ||
const [drawerOpen, setDrawerOpen] = useState(false); | ||
|
||
useEffect(() => { | ||
/** | ||
* Perform actions on component mount. | ||
* | ||
* Triggers a custom action 'wpgraphqlide_rendered' when the App component mounts, | ||
* allowing plugins or themes to hook into this event. The action passes | ||
* the current state of `drawerOpen` to any listeners, providing context | ||
* about the application's UI state. | ||
*/ | ||
doAction('wpgraphqlide_rendered', drawerOpen); | ||
|
||
/** | ||
* Cleanup action on component unmount. | ||
* | ||
* Returns a cleanup function that triggers the 'wpgraphqlide_destroyed' action, | ||
* signaling that the App component is about to unmount. This allows for | ||
* any necessary cleanup or teardown operations in response to the App | ||
* component's lifecycle. | ||
*/ | ||
return () => doAction('wpgraphqlide_destroyed'); | ||
}, [drawerOpen]); | ||
|
||
return ( | ||
<div className="AppRoot"> | ||
<EditorDrawer open={ drawerOpen } setDrawerOpen={ setDrawerOpen }> | ||
<Editor setDrawerOpen={setDrawerOpen} /> | ||
</EditorDrawer> | ||
</div> | ||
); | ||
} |
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