Skip to content

Commit 910d22f

Browse files
committed
feat: add preview button and rename old to classic
1 parent 2d23579 commit 910d22f

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

js/FeedzyBlock/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const { registerBlockType } = wp.blocks;
1818
* Register block
1919
*/
2020
export default registerBlockType('feedzy-rss-feeds/feedzy-block', {
21-
title: __('Feedzy RSS Feeds', 'feedzy-rss-feeds'),
21+
title: __('Feedzy RSS Feeds (Classic)', 'feedzy-rss-feeds'),
2222
category: 'common',
2323
icon: 'rss',
2424
keywords: [

js/FeedzyLoop/edit.js

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
4646
const blockProps = useBlockProps();
4747

4848
const [isEditing, setIsEditing] = useState(!attributes?.feed?.source);
49+
const [isPreviewing, setIsPreviewing] = useState(false);
4950

5051
const { replaceInnerBlocks, selectBlock } = useDispatch(blockEditorStore);
5152

@@ -108,33 +109,7 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
108109
});
109110
};
110111

111-
if (isEditing) {
112-
return (
113-
<div {...blockProps}>
114-
<Placeholder
115-
attributes={attributes}
116-
setAttributes={setAttributes}
117-
onSaveFeed={onSaveFeed}
118-
/>
119-
</div>
120-
);
121-
}
122-
123-
if (!isSelected && innerBlocksContent) {
124-
return (
125-
<div {...blockProps}>
126-
<ServerSideRender
127-
block="feedzy-rss-feeds/loop"
128-
attributes={{
129-
...attributes,
130-
innerBlocksContent,
131-
}}
132-
/>
133-
</div>
134-
);
135-
}
136-
137-
return (
112+
const Controls = () => (
138113
<>
139114
<BlockControls>
140115
<ToolbarGroup>
@@ -144,6 +119,16 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
144119
onClick={() => setIsEditing(true)}
145120
/>
146121
</ToolbarGroup>
122+
123+
<ToolbarGroup>
124+
<ToolbarButton
125+
onClick={() => setIsPreviewing(!isPreviewing)}
126+
>
127+
{isPreviewing
128+
? __('Hide Preview', 'feedzy-rss-feeds')
129+
: __('Show Preview', 'feedzy-rss-feeds')}
130+
</ToolbarButton>
131+
</ToolbarGroup>
147132
</BlockControls>
148133

149134
<InspectorControls>
@@ -269,6 +254,42 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
269254
/>
270255
</PanelBody>
271256
</InspectorControls>
257+
</>
258+
);
259+
260+
if (isEditing) {
261+
return (
262+
<div {...blockProps}>
263+
<Placeholder
264+
attributes={attributes}
265+
setAttributes={setAttributes}
266+
onSaveFeed={onSaveFeed}
267+
/>
268+
</div>
269+
);
270+
}
271+
272+
if ((!isSelected || isPreviewing) && innerBlocksContent) {
273+
return (
274+
<>
275+
<Controls />
276+
277+
<div {...blockProps}>
278+
<ServerSideRender
279+
block="feedzy-rss-feeds/loop"
280+
attributes={{
281+
...attributes,
282+
innerBlocksContent,
283+
}}
284+
/>
285+
</div>
286+
</>
287+
);
288+
}
289+
290+
return (
291+
<>
292+
<Controls />
272293

273294
<div {...blockProps}>
274295
{hasInnerBlocks ? (

0 commit comments

Comments
 (0)