Skip to content

Commit

Permalink
Add a site meta generation state
Browse files Browse the repository at this point in the history
  • Loading branch information
arunshenoy99 committed Apr 5, 2024
1 parent 4be2e9d commit 0066d44
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(

const SiteGen = () => {
const [ failedSiteMetaAPIs, setFailedSiteMetaAPIs ] = useState( [] );
const [ isGeneratingSiteMeta, setIsGeneratingSiteMeta ] = useState( false );

const {
currentData,
Expand Down Expand Up @@ -191,6 +192,7 @@ const SiteGen = () => {

if ( siteGenErrorStatus === false ) {
updateSiteGenErrorStatus( true );
setIsGeneratingSiteMeta( false );
}

if ( window.nfdOnboarding.siteGenTimerInterval ) {
Expand All @@ -208,7 +210,7 @@ const SiteGen = () => {
} );
}

// A Identifier request was sucessfuly made with valid response
// A Identifier request was successfully made with valid response
currentData.sitegen.siteGenMetaStatus.currentStatus += 1;

if (
Expand All @@ -217,14 +219,17 @@ const SiteGen = () => {
) {
// Once all requests are completed use cache to get data
currentData.sitegen.skipCache = false;

// Increase count after site meta calls to ensure systematic call of homepages
currentData.sitegen.siteGenMetaStatus.totalCount += 1;
// Get the homepages and set that in flow
const response = await getHomepages(
currentData.sitegen.siteDetails.prompt
);

if ( response.body ) {
currentData.sitegen.homepages.data = response.body;
currentData.sitegen.siteGenMetaStatus.currentStatus += 1;
setIsGeneratingSiteMeta( false );
}
}
// Sync the current request changed to State
Expand All @@ -235,6 +240,7 @@ const SiteGen = () => {
// Start the API Requests when the loader is shown.
if (
true === siteGenErrorStatus ||
true === isGeneratingSiteMeta ||
( ! location.pathname.includes( 'site-logo' ) &&
! location.pathname.includes( 'experience' ) )
) {
Expand All @@ -249,6 +255,8 @@ const SiteGen = () => {
return;
}

setIsGeneratingSiteMeta( true );

if ( ! window.nfdOnboarding?.siteGenTimerInterval ) {
window.nfdOnboarding.siteGenTime = 0;
window.nfdOnboarding.siteGenTimerInterval = setInterval( () => {
Expand Down

0 comments on commit 0066d44

Please sign in to comment.