import { __ } from '@wordpress/i18n'; import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; import { PanelBody, TextControl, ToggleControl, SelectControl, CheckboxControl } from '@wordpress/components'; import { useEffect, useState } from '@wordpress/element'; import apiFetch from '@wordpress/api-fetch'; import './editor.scss'; export default function Edit({ attributes, setAttributes }) { const blockProps = useBlockProps(); const [availableTypes, setAvailableTypes] = useState({}); useEffect(() => { apiFetch({ path: '/jvb/v1/types' }).then(types => { setAvailableTypes(JSON.parse(types)); }); }, []); return ( <> setAttributes({ title })} /> setAttributes({ inheritQuery })} /> {!attributes.inheritQuery && (

{__('Content Types', 'jvb')}

{Object.entries(availableTypes).map(([id, label]) => ( { const newTypes = isChecked ? [...attributes.contentTypes, id] : attributes.contentTypes.filter(t => t !== id); setAttributes({contentTypes: newTypes}); }} /> ))}
{ setAttributes({ contentTypes: isChecked ? Object.keys(availableTypes) : [] }); }} />
)} setAttributes({itemsPerPage: parseInt(itemsPerPage)})} /> setAttributes({ defaultOrder })} />

{attributes.title}

{attributes.contentTypes.map(type => ( {availableTypes[type]} ))}
{[...Array(6)].map((_, i) => (
))}
); }