HEX
Server: LiteSpeed
System: Linux s12873.lon1.stableserver.net 5.14.0-611.11.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Dec 3 09:47:37 EST 2025 x86_64
User: jairicem (1242)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /home/jairicem/basicconceptenergy.com/wp-content/plugins/mas-static-content/src/index.js
const { registerBlockType } = wp.blocks;
const { SelectControl, Spinner } = wp.components;
const { useSelect } = wp.data;

registerBlockType('mas-static-content/navigation-static-content', {
    title: 'MegaMenu',
    icon: 'screenoptions',
    category: 'widgets',
    attributes: {
        staticContentId: { type: 'number' },
    },
    edit: (props) => {
        const { attributes, setAttributes } = props;

        const posts = useSelect((select) => {
            return select('core').getEntityRecords('postType', 'mas_static_content', { per_page: -1 });
        }, [wp.data.select('core').getEntityRecords]); 

        

        const options = posts.map((post) => ({
            label: post.title.rendered,
            value: post.id,
        }));

        // Optional: add a default option
        options.unshift({ label: 'Select Static Content', value: 0 });

        return (
            <SelectControl
                label="Select Static Content"
                value={attributes.staticContentId || 0}
                options={options}
                onChange={(value) => setAttributes({ staticContentId: parseInt(value) })}
            />
        );
    },
    save: () => null, // Server-rendered
});