From 69a1fb757aaf2ac3aa724797adce71875274440b Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Fri, 2 Aug 2024 12:50:16 -0500 Subject: [PATCH] Simplify logic for preview selection and keep in line with editorMode --- .../src/components/preview-dropdown/index.js | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/packages/editor/src/components/preview-dropdown/index.js b/packages/editor/src/components/preview-dropdown/index.js index d5e9d7c34074a..c36ef257b13aa 100644 --- a/packages/editor/src/components/preview-dropdown/index.js +++ b/packages/editor/src/components/preview-dropdown/index.js @@ -127,22 +127,7 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) { }, ]; - /** - * The selected choice. - * - * @type {Object} - */ const previewValue = editorMode === 'zoom-out' ? 'ZoomOut' : deviceType; - let selectedChoice = choices.find( - ( choice ) => choice.value === previewValue - ); - - /** - * If no selected choice is found, default to the first - */ - if ( ! selectedChoice ) { - selectedChoice = choices[ 0 ]; - } /** * Handles the selection of a device type. @@ -150,20 +135,20 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) { * @param {string} value The device type. */ const onSelect = ( value ) => { - setDeviceType( value ); let newEditorMode = originalEditingMode.current; + if ( value === 'ZoomOut' ) { newEditorMode = 'zoom-out'; + setDeviceType( 'Desktop' ); + } else { + setDeviceType( value ); } __unstableSetEditorMode( newEditorMode ); }; const getText = () => { - if ( - deviceType === 'ZoomOut' || - editorMode === 'zoom-out' // This can happen if zoom out is enabled from by other means - like the patterns tab. - ) { + if ( editorMode === 'zoom-out' ) { return __( '50%' ); } @@ -193,7 +178,7 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {