-
Notifications
You must be signed in to change notification settings - Fork 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
Migration Flow: Fix multiple stickers being added simultaneously when navigating to the "DIY" option #95612
Migration Flow: Fix multiple stickers being added simultaneously when navigating to the "DIY" option #95612
Changes from all commits
df6a9e0
682f844
0252787
a9fd24e
eff54d4
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { StepContainer } from '@automattic/onboarding'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { FC, useMemo } from 'react'; | ||
import { FC, useMemo, useState } from 'react'; | ||
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. And I thought of another scenario where we could have the same race condition issue. If we rebase this PR, we could also add the loader for this scenario (when creating the first "pending" sticker). If we follow the suggestion of the other comment, I think it would assume this behavior automatically. 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. I think I've managed to fix this scenario but I'm facing an issue with the component loading first and then the loader appearing. aAeTa2.mp4Can I fix this without having an extra state in the component? 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. Hm! I noticed that it's because this fetch depends on the 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. Could you take a look at this approach? I wasn't able to avoid the site loading because of this check. Do you think it's good enough? 🙂 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 approach looks good to me! But I just noticed another flickering after clicking on the options ("Do it for me", for example). It finishes the loading (the sticker creating that comes from the click), and displays the step again very quickly before calling the Screen.Recording.2024-10-28.at.13.02.34.movI think we'll probably need an extra state here, similar to your previous approach. Maybe something that we set as loading after clicking and keep this state unchanged, so 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. Oh, I didn't noticed that one. I've fixed it here following your suggestion. Thank you for your patience! |
||
import DocumentHead from 'calypso/components/data/document-head'; | ||
import FormattedHeader from 'calypso/components/formatted-header'; | ||
import { LoadingEllipsis } from 'calypso/components/loading-ellipsis'; | ||
import { useAnalyzeUrlQuery } from 'calypso/data/site-profiler/use-analyze-url-query'; | ||
import { useHostingProviderQuery } from 'calypso/data/site-profiler/use-hosting-provider-query'; | ||
import { HOW_TO_MIGRATE_OPTIONS } from 'calypso/landing/stepper/constants'; | ||
|
@@ -62,28 +63,42 @@ const SiteMigrationHowToMigrate: FC< Props > = ( props ) => { | |
urlData | ||
); | ||
|
||
const { setPendingMigration } = usePendingMigrationStatus( { onSubmit: navigation.submit } ); | ||
const { setPendingMigration, isLoading: isUpdatingMigrationStatus } = usePendingMigrationStatus( { | ||
onSubmit: navigation.submit, | ||
} ); | ||
|
||
const [ isSubmitting, setIsSubmitting ] = useState( false ); | ||
const handleClick = async ( value: string ) => { | ||
setIsSubmitting( true ); | ||
|
||
try { | ||
await setPendingMigration( value ); | ||
} finally { | ||
setIsSubmitting( false ); | ||
} | ||
}; | ||
|
||
const hostingProviderSlug = hostingProviderData?.hosting_provider?.slug; | ||
const shouldDisplayHostIdentificationMessage = | ||
hostingProviderSlug && | ||
hostingProviderSlug !== 'unknown' && | ||
hostingProviderSlug !== 'automattic'; | ||
|
||
const stepContent = ( | ||
<> | ||
const stepContent = | ||
isSubmitting || isUpdatingMigrationStatus ? ( | ||
<LoadingEllipsis className="how-to-migrate__loader" /> | ||
) : ( | ||
<div className="how-to-migrate__list"> | ||
{ options.map( ( option, i ) => ( | ||
<FlowCard | ||
key={ i } | ||
title={ option.label } | ||
text={ option.description } | ||
onClick={ () => setPendingMigration( option.value ) } | ||
onClick={ () => handleClick( option.value ) } | ||
/> | ||
) ) } | ||
</div> | ||
</> | ||
); | ||
); | ||
|
||
const platformText = shouldDisplayHostIdentificationMessage | ||
? translate( 'Your WordPress site is hosted with %(hostingProviderName)s.', { | ||
|
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.
The component
SiteMigrationHowToMigrate
is getting a little complex (big). I started extracting part of the logic to another hook here. I think it would be nice to base this PR there and also add the loading logic there, returning the loading state. WDYT?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.
Sounds good!
I've updated the code but I'm a bit unsure if my implementation is aligned with your vision. 😅 Could you give it a look again?
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.
Yes! That looks great!