-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add audible messages to confirm the "move block" actions #24894
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ import { | |
getTemplate, | ||
isValidTemplate, | ||
getSelectionStart, | ||
getSettings, | ||
} from './selectors'; | ||
|
||
/** | ||
|
@@ -66,6 +67,57 @@ export function validateBlocksToTemplate( action, store ) { | |
} | ||
} | ||
|
||
/** | ||
* Announces when a block is moved. | ||
* | ||
* @param {Object} state The current state. | ||
* @param {string} direction The direction the block was moved in. | ||
*/ | ||
export function announceBlockMoved( state, direction ) { | ||
const blockCount = getSelectedBlockCount( state ); | ||
let message; | ||
|
||
switch ( direction ) { | ||
case 'up': | ||
/* translators: %s: number of selected blocks */ | ||
message = _n( | ||
'%s block moved up.', | ||
'%s blocks moved up.', | ||
blockCount | ||
); | ||
break; | ||
case 'down': | ||
/* translators: %s: number of selected blocks */ | ||
message = _n( | ||
'%s block moved down.', | ||
'%s blocks moved down.', | ||
blockCount | ||
); | ||
break; | ||
case 'left': | ||
/* translators: %s: number of selected blocks */ | ||
message = _n( | ||
'%s block moved left.', | ||
'%s blocks moved left.', | ||
blockCount | ||
); | ||
break; | ||
case 'right': | ||
/* translators: %s: number of selected blocks */ | ||
message = _n( | ||
'%s block moved right.', | ||
'%s blocks moved right.', | ||
blockCount | ||
); | ||
break; | ||
default: | ||
/* translators: %s: number of selected blocks */ | ||
message = _n( '%s block moved.', '%s blocks moved.', blockCount ); | ||
} | ||
|
||
speak( sprintf( message, blockCount, direction ), 'assertive' ); | ||
} | ||
|
||
export default { | ||
MERGE_BLOCKS( action, store ) { | ||
const { dispatch } = store; | ||
|
@@ -219,6 +271,30 @@ export default { | |
) | ||
); | ||
}, | ||
MOVE_BLOCKS_DOWN: ( action, { getState } ) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move away from effects and instead implement these action creator as "generators"? see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I follow. Maybe I lack context or it's a terminology thing 🙂 In this PR we just reused actions that already exist. Are you suggesting a major refactoring in the way these actions are created? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're slowly moving away from using "effects" (see effects.js file and the https://github.com/aduth/refx middleware) and instead we're trying to replace them with "generator" actions (consistency with resolvers). These are just two technologies that allow the same thing: writing complex actions with side effects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know. Is this documented anywhere? How new contributors are supposed to be informed about this? 🙂 If it's not documented, I'd say it's a barrier to new contributors... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it should be. We were hoping we could get rid of these files which remove the confusion but the refactor efforts staled. |
||
const state = getState(); | ||
const settings = getSettings( state ); | ||
|
||
let direction = 'down'; | ||
|
||
if ( action.orientation === 'horizontal' ) { | ||
direction = settings.isRTL ? 'left' : 'right'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? Wouldn't the actual move actions still be accurate given left moves to the left regardless of RTL? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is correct. "down" moves the block to the "following" position, whether it's vertical or horizontal. In LTR, the "following" horizontal position is right, while in RTL is left. |
||
} | ||
|
||
announceBlockMoved( state, direction ); | ||
}, | ||
MOVE_BLOCKS_UP: ( action, { getState } ) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's odd to read an action type of "UP" while orientation changes it to right / left within. It'd be better to have a single "MOVE_BLOCKS" type and handle all cardinals within. (Alternatively, there could be four action types.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just uses the existing actions. Actually, there are no specific actions for "left" and "right". Not opposed to improvements but the current actions implementation is out of the scope of this issue. |
||
const state = getState(); | ||
const settings = getSettings( state ); | ||
|
||
let direction = 'up'; | ||
|
||
if ( action.orientation === 'horizontal' ) { | ||
direction = settings.isRTL ? 'right' : 'left'; | ||
} | ||
|
||
announceBlockMoved( state, direction ); | ||
}, | ||
RESET_BLOCKS: [ validateBlocksToTemplate ], | ||
MULTI_SELECT: ( action, { getState } ) => { | ||
const blockCount = getSelectedBlockCount( getState() ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems all these could be inlined and don't need the extra abstraction of
announceBlockMoved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd disagree. Seems to me it's way more readable this way.