-
Notifications
You must be signed in to change notification settings - Fork 293
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
Implement auto refresh for TwG setup publication step #5532
Comments
The IB here looks good, but the logic involved in "listening for a timeout after tab blur, then running a function" seems useful and clearly we want to use it in at least one place so far. Would it be straightforward to extract into a reusable hook? I think so, and I think we could do it as part of this issue without too much more effort. A hook with this API would be good: const reset = useCallback(() => {
// Do not reset if account status has not been determined yet, or
// if the account is approved.
if (undefined === accountStatus || ACCOUNT_STATUS_READY === accountStatus) {
return;
}
// Unset any potential error.
clearError();
// Reset all data to force re-fetch.
resetAccounts();
resetAlerts();
resetClients();
resetSites();
});
// Reset all data to force re-fetch after this tab is not focused for at least
// 15 seconds.
useRefocus(reset, 15000); We should do that as part of this issue, including refactoring the AdSense component. If that will only increase the estimate to 11-15, I think it's worth doing here. |
That's a good idea. Thanks, @tofumatt. I have updated the IB. |
Looks good, thanks for the addition of the hook 👍🏻 IB ✅ |
QA Update: ✅Verified:
ScreencastsTwG: twg.mp4AdSense: adsense.mp4 |
The Thank with Google setup's first step about setting up the publication should support automatic refresh behavior similar to the AdSense module's setup flow: If you navigate away for a certain amount of time and then return to the tab, it should automatically re-run the relevant API requests, to see if maybe something on the TwG API side has changed. This is crucial since all write actions happen within the TwG service UI and are therefore unknown to Site Kit.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
resetPublications()
data store action.publicationID
module setting (which only happens after the user clicks the button to proceed to the second step of the setup flow for the customization).Implementation Brief
In
assets/js/modules/thank-with-google/datastore/publications.js
, add the following details:RESET_PUBLICATIONS
.baseActions
object and add a newresetPublications
action to it.payload
with an empty object andtype
withRESET_PUBLICATIONS
action type.actions.clearErrors()
action fromassets/js/googlesitekit/data/create-error-store.js
.getPublications
to theclearErrors()
action.getPublications
selector usinginvalidateResolutionForStoreSelector
action ofMODULES_THANK_WITH_GOOGLE
store.baseReducer
function with the case for theRESET_PUBLICATIONS
action type.publications
state with thebaseInitialState.publications
.baseActions
andbaseReducer
to the store.Create a reusable hook
useRefocus
that will be used in the TwG and Adsense setup to auto-refocus.In
assets/js/hooks
, create a file calleduseRefocus.js
and add the following:useRefocus
that takes a callbackreset
and a timeoutmilliseconds
as arguments.useEffect
hook, it should extract most of the logic from the AdSense setup flow except thereset
function sinceuseRefocus
will receive it as an argument. See:site-kit-wp/assets/js/modules/adsense/components/setup/v2/SetupMain.js
Lines 212 to 265 in 16aefc7
countIdleTime
should use themilliseconds
argument to calculate the time since the last time the tab was focused.countIdleTime
andreset
should be passed to the event listeners for the tab blur and focus events, respectively.In
assets/js/modules/thank-with-google/components/setup/SetupMain.js
, add the following logic to reset the publications data when the user returns to the tab after 15 seconds:Get the
publicationID
from thegetPublicationID
selector ofmodules/thank-with-google
store.Create a
reset
callback function usinguseCallback
to reset when the user re-focuses after 15 seconds or more with the following logic:publicationID
is not set. So, within thereset
function, return early if thepublicationID
is set.resetPublications
action to reset the publications data.clearError
action to clear the publications error.Call the
useRefocus
hook and pass thereset
callback function and15000
milliseconds as arguments.In
assets/js/modules/adsense/components/setup/v2/SetupMain.js
, refactor the existing logic to use theuseRefocus
hook:reset
function to its callback using theuseCallback
hook.useRefocus
hook and pass thereset
function and15000
milliseconds as arguments.useEffect
hook that contains all the logic to reset and refocus.Test Coverage
resetPublications
action.useRefocus
hook.QA Brief
Verify the Thank with Google reset behaviour:
twgModule
feature flag.Regression test the AdSense reset behaviour:
adsenseSetupV2
feature flag.none
orready
.Changelog entry
The text was updated successfully, but these errors were encountered: