Jake Vanderwerf
2026-01-01 1d5c574e6efc88a32a76f645c27f459aad0e65df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
 * WordPress dependencies
 */
import { __ } from '@wordpress/i18n';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { SelectControl, ToggleControl, PanelBody } from '@wordpress/components';
 
/**
 * Styles
 */
import './editor.scss';
 
/**
 * Edit function for Directory List Block
 */
export default function Edit({ attributes, setAttributes }) {
    const blockProps = useBlockProps();
 
    // Access the localized list types from the global window object
    const listTypeOptions = window.jvbListTypes ? window.jvbListTypes.map(type => {
        return {
            label: type.title,
            value: type.slug
        };
    }) : [];
 
    // Find the selected list type details
    const selectedType = window.jvbListTypes ?
        window.jvbListTypes.find(type => type.slug === attributes.listType) || {}
        : {};
 
    return (
        <div {...blockProps}>
            <InspectorControls>
                <PanelBody title={__('List Settings', 'jvb')}>
                    <SelectControl
                        label={__('List Type', 'jvb')}
                        value={attributes.listType}
                        options={listTypeOptions}
                        onChange={(value) => setAttributes({ listType: value })}
                    />
                    <ToggleControl
                        label={__('Refresh Cache', 'jvb')}
                        help={__('Enable to regenerate the list data on page load', 'jvb')}
                        checked={attributes.refreshCache}
                        onChange={(value) => setAttributes({ refreshCache: value })}
                    />
                </PanelBody>
            </InspectorControls>
 
            <div className="jvb-list-preview">
                <h3>{__('Directory List', 'jvb')}</h3>
                <div className="jvb-list-preview-info">
                    <p><strong>{__('Selected List Type:', 'jvb')}</strong> {selectedType.title}</p>
                    <p><strong>{__('Type:', 'jvb')}</strong> {selectedType.type}</p>
                    {selectedType.links && (
                        <p><strong>{__('Links:', 'jvb')}</strong> {selectedType.links.join(', ')}</p>
                    )}
                    <p><strong>{__('Cache Status:', 'jvb')}</strong>
                        {attributes.refreshCache ?
                            __('Will refresh on load', 'jvb') :
                            __('Using cached data', 'jvb')}
                    </p>
                </div>
                <p className="jvb-list-preview-note">
                    {__('This alphabetical list will be rendered on the frontend.', 'jvb')}
                </p>
            </div>
        </div>
    );
}