// @ts-check /* global blockLabMigration */ /** * External dependencies */ import * as React from 'react'; /** * WordPress dependencies */ import { speak } from '@wordpress/a11y'; import apiFetch from '@wordpress/api-fetch'; import { Spinner } from '@wordpress/components'; import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import { Step, StepContent, StepFooter, StepIcon } from '../'; /** * @typedef {Object} MigrateBlocksProps The component props. * @property {Function} goToNext Goes to the next step. * @property {boolean} isStepActive Whether this step is active. * @property {boolean} isStepComplete Whether this step is complete. * @property {number} stepIndex The step index of this step. */ /** * The step that migrates the blocks. * * @param {MigrateBlocksProps} Props The component props. * @return {React.ReactElement} The component to prompt to migrate the post content. */ const MigrateBlocks = ( { isStepActive, isStepComplete, stepIndex } ) => { const [currentBlockMigrationStep, setCurrentBlockMigrationStep] = useState(0); const [isInProgress, setIsInProgress] = useState(false); const [isError, setIsError] = useState(false); const [errorMessage, setErrorMessage] = useState(''); const [isSuccess, setIsSuccess] = useState(false); const migrationLabels = [ __('Migrating your blocks…', 'block-lab'), __('Migrating your post content…', 'block-lab'), ]; const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const migrateCpt = async () => { await apiFetch({ path: '/block-lab/migrate-post-type', method: 'POST', }).then(async () => { setCurrentBlockMigrationStep(1); await migratePostContent(); }).catch((result) => { if (result.hasOwnProperty('message')) { setErrorMessage(result.message); } speak(__('The migration failed in the CPT migration', 'block-lab')); setIsError(true); setIsInProgress(false); }); }; const migratePostContent = async () => { const batchSize = 10; // Adjust the batch size as needed const timeoutErrorCode = 'invalid_json'; let batchIndex = 0; let hasMoreBatches = true; while (hasMoreBatches) { await apiFetch({ path: `/block-lab/migrate-post-content?batch=${batchIndex}&size=${batchSize}`, method: 'POST', }).then(() => { speak(__('The migration batch was successful!', 'block-lab')); batchIndex++; hasMoreBatches = true; // Update this based on the response }).catch(async (result) => { if (result.hasOwnProperty('code') && timeoutErrorCode === result.code) { await delay(2000); // Wait for 2 seconds before retrying await migratePostContent(); return; } else if (result.hasOwnProperty('message')) { setErrorMessage(result.message); } speak(__('The migration failed in the post content migration', 'block-lab')); setIsError(true); hasMoreBatches = false; }); await delay(5000); // Wait for 5 seconds between batches to avoid rate limits } if (!isError) { setIsSuccess(true); } }; const migrate = async () => { speak(__('The migration is now in progress', 'block-lab')); setErrorMessage(''); setIsInProgress(true); await migrateCpt(); setIsInProgress(false); }; return ( {!isSuccess &&

{__("Okay! Everything is ready. Let's do this. While the migration is underway, don't leave this page.", 'block-lab')}

} {!!errorMessage && (

{__('The following error ocurred:', 'block-lab')}

{errorMessage}

)} {isInProgress && ( <>

{migrationLabels[currentBlockMigrationStep]}

)} {!isInProgress && !isSuccess && ( )} {isSuccess && ( <>

🎉   {__('The migration completed successfully! Time to say goodbye to Block Lab (it’s been fun!) and step into the FUTURE', 'block-lab')}   {__('FUTURE', 'block-lab')}   {__('FUTURE', 'block-lab')}.

{ /* @ts-ignore */ } {__('Go To Genesis Custom Blocks', 'block-lab')} )}
); }; export default MigrateBlocks; Cum Swallow – Fapdrop

Tag: Cum Swallow

  • 0
  • 0
  • 0
  • 0
  • 1