From d51169c512f8623e46518f7751f96059ecec44fe Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Wed, 4 Sep 2024 19:11:00 -0300 Subject: [PATCH] AI Client: add logo generator placeholder components (#39244) * introduce isLoadingHistory on store. Set it from hook and main modal * introduce logo presenter placeholder component while loading the logos * introduce placeholder for history carousel * add changelog entry --- .../fix-ai-logo-generator-loading-states | 4 ++++ .../components/generator-modal.tsx | 7 ++++++- .../components/history-carousel.tsx | 9 ++++++++- .../components/logo-presenter.tsx | 20 ++++++++++++++----- .../hooks/use-logo-generator.ts | 5 +++++ .../src/logo-generator/store/actions.ts | 8 ++++++++ .../src/logo-generator/store/constants.ts | 1 + .../src/logo-generator/store/reducer.ts | 12 +++++++++++ .../src/logo-generator/store/selectors.ts | 10 ++++++++++ .../src/logo-generator/store/types.ts | 2 ++ 10 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 projects/js-packages/ai-client/changelog/fix-ai-logo-generator-loading-states diff --git a/projects/js-packages/ai-client/changelog/fix-ai-logo-generator-loading-states b/projects/js-packages/ai-client/changelog/fix-ai-logo-generator-loading-states new file mode 100644 index 0000000000000..ae20912bc8efe --- /dev/null +++ b/projects/js-packages/ai-client/changelog/fix-ai-logo-generator-loading-states @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +AI Client: add placeholders for Logo Generator modal commponents diff --git a/projects/js-packages/ai-client/src/logo-generator/components/generator-modal.tsx b/projects/js-packages/ai-client/src/logo-generator/components/generator-modal.tsx index d5de13dd495ed..485d8c7b318b6 100644 --- a/projects/js-packages/ai-client/src/logo-generator/components/generator-modal.tsx +++ b/projects/js-packages/ai-client/src/logo-generator/components/generator-modal.tsx @@ -52,7 +52,8 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( { } ) => { const { tracks } = useAnalytics(); const { recordEvent: recordTracksEvent } = tracks; - const { setSiteDetails, fetchAiAssistantFeature, loadLogoHistory } = useDispatch( STORE_NAME ); + const { setSiteDetails, fetchAiAssistantFeature, loadLogoHistory, setIsLoadingHistory } = + useDispatch( STORE_NAME ); const { getIsRequestingAiAssistantFeature } = select( STORE_NAME ); const [ loadingState, setLoadingState ] = useState< 'loadingFeature' | 'analyzing' | 'generating' | null @@ -129,6 +130,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( { return; } + setIsLoadingHistory( true ); // Load the logo history and clear any deleted media. await clearDeletedMedia( String( siteId ) ); loadLogoHistory( siteId ); @@ -136,6 +138,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( { // If there is any logo, we do not need to generate a first logo again. if ( ! isLogoHistoryEmpty( String( siteId ) ) ) { setLoadingState( null ); + setIsLoadingHistory( false ); return; } @@ -144,6 +147,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( { } catch ( error ) { debug( 'Error fetching feature', error ); setLoadingState( null ); + setIsLoadingHistory( false ); } }, [ feature, @@ -170,6 +174,7 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( { setNeedsMoreRequests( false ); clearErrors(); setLogoAccepted( false ); + setIsLoadingHistory( false ); recordTracksEvent( EVENT_MODAL_CLOSE, { context, placement } ); }; diff --git a/projects/js-packages/ai-client/src/logo-generator/components/history-carousel.tsx b/projects/js-packages/ai-client/src/logo-generator/components/history-carousel.tsx index d82b34b82d2df..81ab193affe19 100644 --- a/projects/js-packages/ai-client/src/logo-generator/components/history-carousel.tsx +++ b/projects/js-packages/ai-client/src/logo-generator/components/history-carousel.tsx @@ -7,6 +7,7 @@ import clsx from 'clsx'; /** * Internal dependencies */ +import loader from '../assets/images/loader.gif'; import { EVENT_NAVIGATE } from '../constants.js'; import useLogoGenerator from '../hooks/use-logo-generator.js'; import './history-carousel.scss'; @@ -18,7 +19,8 @@ import type React from 'react'; export const HistoryCarousel: React.FC = () => { const { tracks } = useAnalytics(); const { recordEvent: recordTracksEvent } = tracks; - const { logos, selectedLogo, setSelectedLogoIndex, context } = useLogoGenerator(); + const { logos, selectedLogo, setSelectedLogoIndex, context, isLoadingHistory } = + useLogoGenerator(); const handleClick = ( index: number ) => { recordTracksEvent( EVENT_NAVIGATE, { @@ -41,6 +43,11 @@ export const HistoryCarousel: React.FC = () => { return (
+ { ! logos.length && isLoadingHistory && ( + + ) } { logos.map( ( logo, index ) => (