@@ -46,6 +46,7 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
46
46
const blockProps = useBlockProps ( ) ;
47
47
48
48
const [ isEditing , setIsEditing ] = useState ( ! attributes ?. feed ?. source ) ;
49
+ const [ isPreviewing , setIsPreviewing ] = useState ( false ) ;
49
50
50
51
const { replaceInnerBlocks, selectBlock } = useDispatch ( blockEditorStore ) ;
51
52
@@ -108,33 +109,7 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
108
109
} ) ;
109
110
} ;
110
111
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 = ( ) => (
138
113
< >
139
114
< BlockControls >
140
115
< ToolbarGroup >
@@ -144,6 +119,16 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
144
119
onClick = { ( ) => setIsEditing ( true ) }
145
120
/>
146
121
</ 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 >
147
132
</ BlockControls >
148
133
149
134
< InspectorControls >
@@ -269,6 +254,42 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
269
254
/>
270
255
</ PanelBody >
271
256
</ 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 />
272
293
273
294
< div { ...blockProps } >
274
295
{ hasInnerBlocks ? (
0 commit comments