|
| 1 | +/** |
| 2 | + * WordPress dependencies. |
| 3 | + */ |
| 4 | +import { __ } from '@wordpress/i18n'; |
| 5 | + |
| 6 | +import { BlockControls, InspectorControls } from '@wordpress/block-editor'; |
| 7 | + |
| 8 | +import { |
| 9 | + Button, |
| 10 | + PanelBody, |
| 11 | + RangeControl, |
| 12 | + SelectControl, |
| 13 | + ToolbarButton, |
| 14 | + ToolbarGroup, |
| 15 | +} from '@wordpress/components'; |
| 16 | + |
| 17 | +/** |
| 18 | + * Internal dependencies. |
| 19 | + */ |
| 20 | +import ConditionsControl from '../Conditions/ConditionsControl'; |
| 21 | + |
| 22 | +const Controls = ({ |
| 23 | + attributes, |
| 24 | + isEditing, |
| 25 | + isPreviewing, |
| 26 | + setAttributes, |
| 27 | + onChangeLayout, |
| 28 | + onChangeQuery, |
| 29 | + setIsEditing, |
| 30 | + setIsPreviewing, |
| 31 | +}) => ( |
| 32 | + <> |
| 33 | + <BlockControls> |
| 34 | + <ToolbarGroup> |
| 35 | + <ToolbarButton |
| 36 | + icon="edit" |
| 37 | + title={__('Edit Feed', 'feedzy-rss-feeds')} |
| 38 | + onClick={() => setIsEditing(true)} |
| 39 | + /> |
| 40 | + </ToolbarGroup> |
| 41 | + |
| 42 | + <ToolbarGroup> |
| 43 | + <ToolbarButton onClick={() => setIsPreviewing(!isPreviewing)}> |
| 44 | + {isPreviewing |
| 45 | + ? __('Hide Preview', 'feedzy-rss-feeds') |
| 46 | + : __('Show Preview', 'feedzy-rss-feeds')} |
| 47 | + </ToolbarButton> |
| 48 | + </ToolbarGroup> |
| 49 | + </BlockControls> |
| 50 | + |
| 51 | + <InspectorControls> |
| 52 | + {!isEditing && ( |
| 53 | + <PanelBody |
| 54 | + initialOpen={false} |
| 55 | + title={__('Feed Source', 'feedzy-rss-feeds')} |
| 56 | + key="source" |
| 57 | + > |
| 58 | + <Button |
| 59 | + variant="secondary" |
| 60 | + onClick={() => setIsEditing(true)} |
| 61 | + style={{ |
| 62 | + width: '100%', |
| 63 | + justifyContent: 'center', |
| 64 | + }} |
| 65 | + > |
| 66 | + {__('Edit Feed', 'feedzy-rss-feeds')} |
| 67 | + </Button> |
| 68 | + </PanelBody> |
| 69 | + )} |
| 70 | + |
| 71 | + <PanelBody |
| 72 | + title={__('Settings', 'feedzy-rss-feeds')} |
| 73 | + key="settings" |
| 74 | + > |
| 75 | + <RangeControl |
| 76 | + label={__('Column Count', 'feedzy-rss-feeds')} |
| 77 | + value={attributes?.layout?.columnCount || 1} |
| 78 | + onChange={(value) => |
| 79 | + onChangeLayout({ type: 'columnCount', value }) |
| 80 | + } |
| 81 | + min={1} |
| 82 | + max={5} |
| 83 | + /> |
| 84 | + |
| 85 | + <RangeControl |
| 86 | + label={__('Number of Items', 'feedzy-rss-feeds')} |
| 87 | + value={attributes?.query?.max || 5} |
| 88 | + onChange={(value) => onChangeQuery({ type: 'max', value })} |
| 89 | + min={1} |
| 90 | + max={20} |
| 91 | + /> |
| 92 | + |
| 93 | + <SelectControl |
| 94 | + label={__('Sorting Order', 'feedzy-rss-feeds')} |
| 95 | + value={attributes?.query?.sort} |
| 96 | + options={[ |
| 97 | + { |
| 98 | + label: __('Default', 'feedzy-rss-feeds'), |
| 99 | + value: 'default', |
| 100 | + }, |
| 101 | + { |
| 102 | + label: __('Date Descending', 'feedzy-rss-feeds'), |
| 103 | + value: 'date_desc', |
| 104 | + }, |
| 105 | + { |
| 106 | + label: __('Date Ascending', 'feedzy-rss-feeds'), |
| 107 | + value: 'date_asc', |
| 108 | + }, |
| 109 | + { |
| 110 | + label: __('Title Descending', 'feedzy-rss-feeds'), |
| 111 | + value: 'title_desc', |
| 112 | + }, |
| 113 | + { |
| 114 | + label: __('Title Ascending', 'feedzy-rss-feeds'), |
| 115 | + value: 'title_asc', |
| 116 | + }, |
| 117 | + ]} |
| 118 | + onChange={(value) => onChangeQuery({ type: 'sort', value })} |
| 119 | + /> |
| 120 | + |
| 121 | + <SelectControl |
| 122 | + label={__('Feed Caching Time', 'feedzy-rss-feeds')} |
| 123 | + value={attributes?.query?.refresh || '12_hours'} |
| 124 | + options={[ |
| 125 | + { |
| 126 | + label: __('1 Hour', 'feedzy-rss-feeds'), |
| 127 | + value: '1_hours', |
| 128 | + }, |
| 129 | + { |
| 130 | + label: __('2 Hours', 'feedzy-rss-feeds'), |
| 131 | + value: '3_hours', |
| 132 | + }, |
| 133 | + { |
| 134 | + label: __('12 Hours', 'feedzy-rss-feeds'), |
| 135 | + value: '12_hours', |
| 136 | + }, |
| 137 | + { |
| 138 | + label: __('1 Day', 'feedzy-rss-feeds'), |
| 139 | + value: '1_days', |
| 140 | + }, |
| 141 | + { |
| 142 | + label: __('3 Days', 'feedzy-rss-feeds'), |
| 143 | + value: '3_days', |
| 144 | + }, |
| 145 | + { |
| 146 | + label: __('15 Days', 'feedzy-rss-feeds'), |
| 147 | + value: '15_days', |
| 148 | + }, |
| 149 | + ]} |
| 150 | + onChange={(value) => |
| 151 | + onChangeQuery({ type: 'refresh', value }) |
| 152 | + } |
| 153 | + /> |
| 154 | + </PanelBody> |
| 155 | + |
| 156 | + <PanelBody |
| 157 | + title={[ |
| 158 | + __('Filter items', 'feedzy-rss-feeds'), |
| 159 | + !window.feedzyData.isPro && ( |
| 160 | + <span className="fz-pro-label">Pro</span> |
| 161 | + ), |
| 162 | + ]} |
| 163 | + initialOpen={false} |
| 164 | + key="filters" |
| 165 | + className={ |
| 166 | + window.feedzyData.isPro |
| 167 | + ? 'feedzy-item-filter' |
| 168 | + : 'feedzy-item-filter fz-locked' |
| 169 | + } |
| 170 | + > |
| 171 | + <ConditionsControl |
| 172 | + conditions={ |
| 173 | + attributes?.conditions || { |
| 174 | + conditions: [], |
| 175 | + match: 'all', |
| 176 | + } |
| 177 | + } |
| 178 | + setConditions={(conditions) => { |
| 179 | + setAttributes({ conditions }); |
| 180 | + }} |
| 181 | + /> |
| 182 | + </PanelBody> |
| 183 | + </InspectorControls> |
| 184 | + </> |
| 185 | +); |
| 186 | + |
| 187 | +export default Controls; |
0 commit comments