Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/editor/src/components/preview-dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ActionItem } from '@wordpress/interface';
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { store as blockEditorStore } from '@wordpress/block-editor';
import PostPreviewButton from '../post-preview-button';

export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
Expand All @@ -44,6 +45,12 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
};
}, [] );
const { setDeviceType } = useDispatch( editorStore );
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );

const handleDevicePreviewChange = ( newDeviceType ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add doc comment for the new function?
This is what I was thinking:

/**
* Handles the selection of a device type from preview dropdown.
*
* Turns off the zoom out mode after setting the device type.
*
* @param {string} newDeviceType The selected device type.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AhmarZaidi

I think there are no clear rules about JSDoc, but this is an internal function that is not exposed, and the process it performs is just two lines.

I personally don't think JSDoc is necessary because we can see what it's doing at a glance and I feel like JSDoc is a bit over the top. 😄

setDeviceType( newDeviceType );
__unstableSetEditorMode( 'edit' );
};

const isMobile = useViewportMatch( 'medium', '<' );
if ( isMobile ) {
Expand Down Expand Up @@ -113,7 +120,7 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
<MenuItemsChoice
choices={ choices }
value={ deviceType }
onSelect={ setDeviceType }
onSelect={ handleDevicePreviewChange }
/>
</MenuGroup>
{ isTemplate && (
Expand Down