Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
srtfisher committed Jul 9, 2024
1 parent 51c367d commit e1bb447
Show file tree
Hide file tree
Showing 16 changed files with 1,019 additions and 410 deletions.
17 changes: 0 additions & 17 deletions .scaffolder/plugin-feature/config.yml

This file was deleted.

27 changes: 0 additions & 27 deletions .scaffolder/plugin-feature/feature.php.hbs

This file was deleted.

25 changes: 0 additions & 25 deletions .scaffolder/plugin-feature/test.php.hbs

This file was deleted.

33 changes: 0 additions & 33 deletions blocks/README.md

This file was deleted.

107 changes: 107 additions & 0 deletions entries/command-palette/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { Command, CommandMenu, useCommandLoader } from '@wordpress/commands';
import { arrowRight } from '@wordpress/icons';

// import {
// post, page, layout, symbolFilled,
// } from '@wordpress/icons';
import { useCallback } from 'react';

function App() {
console.log('aaa');

const settingsPageLinks = useCallback(() => {
const links = document.querySelectorAll('#adminmenu a');
const index: Command[] = [];

Array.from(links).forEach((link) => {
const url = link.getAttribute('href');
let label = link.textContent;

if (url?.endsWith('edit-comments.php')) {
label = 'Comments';
}

if (url && label) {
index.push({
label: `Go to Settings: ${label}`,
url,
name: url,
icon: arrowRight,
callback: (args: any) => {
console.log('the args', args);

window.location.href = url;
},
});
}
});

return index;
}, []);

// function usePageSearchCommandLoader({ search }) {
// console.log('search', search);

// return {
// commands: settingsPageLinks(),
// isLoading: false,
// };
// // // Retrieve the pages for the "search" term.
// // const { records, isLoading } = useSelect( ( select ) => {
// // const { getEntityRecords } = select( coreStore );
// // const query = {
// // search: !! search ? search : undefined,
// // per_page: 10,
// // orderby: search ? 'relevance' : 'date',
// // };
// // return {
// // records: getEntityRecords( 'postType', 'page', query ),
// // isLoading: ! select( coreStore ).hasFinishedResolution(
// // 'getEntityRecords',
// // 'postType', 'page', query ]
// // ),
// // };
// // }, [ search ] );

// // // Create the commands.
// // const commands = useMemo( () => {
// // return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
// // return {
// // name: record.title?.rendered + ' ' + record.id,
// // label: record.title?.rendered
// // ? record.title?.rendered
// // : __( '(no title)' ),
// // icon: icons[ postType ],
// // callback: ( { close } ) => {
// // const args = {
// // postType,
// // postId: record.id,
// // ...extraArgs,
// // };
// // document.location = addQueryArgs( 'site-editor.php', args );
// // close();
// // },
// // };
// // } );
// // }, [ records, history ] );

// // return {
// // commands,
// // isLoading,
// // };
// }

useCommandLoader({
name: 'wp-command-palette',
hook: () => ({
commands: settingsPageLinks(),
isLoading: false,
}),
});

return (
<CommandMenu />
);
}

export default App;
12 changes: 12 additions & 0 deletions entries/command-palette/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './app';

// Create a root from a new div appended to the document body
const root = createRoot(document.body.appendChild(document.createElement('div')));

root.render(
<StrictMode>
<App />
</StrictMode>,
);
Loading

0 comments on commit e1bb447

Please sign in to comment.