From e019c926b70239a3ade4826dd1d9edad27424f94 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:22:28 +0100 Subject: [PATCH] proof of concept: freeze modal while trashing bulk items (this is meant to be reverted or built upon; I just wanted to share my concept) --- .../src/components/post-actions/actions.js | 241 ++++++++++-------- 1 file changed, 130 insertions(+), 111 deletions(-) diff --git a/packages/editor/src/components/post-actions/actions.js b/packages/editor/src/components/post-actions/actions.js index 0a10448a9ff53f..bb58ab58822e37 100644 --- a/packages/editor/src/components/post-actions/actions.js +++ b/packages/editor/src/components/post-actions/actions.js @@ -8,7 +8,7 @@ import { decodeEntities } from '@wordpress/html-entities'; import { store as coreStore } from '@wordpress/core-data'; import { __, _n, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; -import { useMemo, useState } from '@wordpress/element'; +import { useMemo, useState, useRef } from '@wordpress/element'; import { Button, @@ -25,6 +25,12 @@ function getItemTitle( item ) { return decodeEntities( item.title?.rendered || '' ); } +function WithFrozenChildren( { shouldFreeze, children } ) { + const cachedChildren = useRef( children ); + if ( ! shouldFreeze ) cachedChildren.current = children; + return cachedChildren.current; +} + export const trashPostAction = { id: 'move-to-trash', label: __( 'Move to Trash' ), @@ -39,127 +45,140 @@ export const trashPostAction = { const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); const { deleteEntityRecord } = useDispatch( coreStore ); + const [ shouldFreeze, setShouldFreeze ] = useState( false ); return ( - - - { posts.length === 1 - ? sprintf( - // translators: %s: The page's title. - __( 'Are you sure you want to delete "%s"?' ), - getItemTitle( posts[ 0 ] ) - ) - : sprintf( - // translators: %d: The number of pages (2 or more). - _n( - 'Are you sure you want to delete %d page?', - 'Are you sure you want to delete %d pages?', + + + + { posts.length === 1 + ? sprintf( + // translators: %s: The page's title. + __( + 'Are you sure you want to delete "%s"?' + ), + getItemTitle( posts[ 0 ] ) + ) + : sprintf( + // translators: %d: The number of pages (2 or more). + _n( + 'Are you sure you want to delete %d page?', + 'Are you sure you want to delete %d pages?', + posts.length + ), posts.length - ), - posts.length - ) } - - - - + - - + if ( onActionPerformed ) { + onActionPerformed( posts ); + } + closeModal(); + } } + > + { __( 'Delete' ) } + + + + ); }, };