Skip to content
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

feat: [#173248858] "Update IO" CTA web URL fallback added + fixed component method #2491

Merged
merged 10 commits into from
Dec 14, 2020

Conversation

DavideValdo
Copy link
Contributor

@DavideValdo DavideValdo commented Dec 3, 2020

List of changes proposed in this pull request

  • In case for some reason the native store links don't work, we try to open the store in the browser
  • The error is now actually hidden after the delay
  • The component has been refactored to a function component to properly hide back the error message as a component effect, instead of treating setState as a sync operation

How to test

  • Change src/payloads/backend.ts in the dev server with:
export const backendInfo = {
  min_app_version: { android: "10.0.0", ios: "10.0.0" },
  min_app_version_pagopa: { android: "0.0.0", ios: "0.0.0" },
  version: "2.1.2"
};
  • Run the app and tap the CTA
  • Changing the Linking.openURL(variable) calls to Linking.openURL("dummy") lets us fake failure cases

Behavior

  • On iOS simulator, opening the native URL always fails and the browser is opened instead.
  • On Android 9.1 Xiaomi Redmi S2, the first openURL() call fails, but the second call somehow triggers the Play Store app to open (?). I did confirm the first call fails by replacing webStoreURL.android with https://www.google.it and it did open the Google homepage. Good for us. My guess is this is env-related.

@pagopa-github-bot pagopa-github-bot changed the title [#173248858] "Update IO" CTA web URL fallback added + fixed component method feat: [#173248858] "Update IO" CTA web URL fallback added + fixed component method Dec 3, 2020
@pagopa-github-bot
Copy link
Collaborator

pagopa-github-bot commented Dec 3, 2020

Affected stories

  • 🌟 #173248858: Aggiungere dei testi-link nella schermata di aggiornamento dell'app

Generated by 🚫 dangerJS against 1b17061

@codecov
Copy link

codecov bot commented Dec 3, 2020

Codecov Report

Merging #2491 (1b17061) into master (70d1ca6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2491   +/-   ##
=======================================
  Coverage   50.64%   50.64%           
=======================================
  Files         708      708           
  Lines       20156    20157    +1     
  Branches     3878     3880    +2     
=======================================
+ Hits        10208    10209    +1     
  Misses       9902     9902           
  Partials       46       46           
Impacted Files Coverage Δ
ts/utils/appVersion.ts 90.00% <100.00%> (+0.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70d1ca6...1b17061. Read the comment docs.

@DavideValdo DavideValdo requested a review from debiff December 3, 2020 16:57
});

// Play/App store native URL
// eslint-disable-next-line
Copy link
Contributor

@CrisTofani CrisTofani Dec 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may avoid to disable linting here just refactor below lines of code as follows:

    // Play/App store native URL
    Linking.openURL(storeUrl)
      // Try to fallback to the web URL
      .catch(() => Linking.openURL(webStoreURL))
      // No URL could be opened, show an error message
      .catch(() =>
        this.setError()
          // Hide the error after 5 seconds
          .then(() =>
            setTimeout(
              () =>
                this.setState({
                  hasError: false
                }),
              timeoutErrorMsg
            )
          )
      );

public componentDidMount() {
BackHandler.addEventListener("hardwareBackPress", this.handleBackPress);
}
const AppleFooter: FC<FooterProps> = ({ onOpenAppStore }: FooterProps) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe renaming this to IosFooter is better what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say I like it, "iOS" is the correct spelling, not "Ios", but if you've chosen "Ios" all over the codebase let's give priority to coherence.

android: this.renderAndroidFooter()
});
}
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a common hook for this case useHardwareBackButton let's try this one 😄


useEffect(() => {
if (error) {
setTimeout(() => setError(false), ERROR_MESSAGE_TIMEOUT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please handle the clear of this setTimeout to avoid possible warnings

setError(true);
}
}
}, [setError]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho useCallback in this case maybe not so useful, since we are passing setError function as a dependency this would never be regenerated and anyway here there's no need to memoize the function.

I would suggest a more simple implementation of the function as follows:

const openAppStore = async () =>
    Linking.openURL(storeUrl).catch(() => {
      openWebUrl(webStoreURL, () => setError(true));
    });

you can find openWebUrl implementation here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, setters are guaranteed to be always the same, but shouldn't useCallback prevent the function from being recreated? setError is related to the component so I think it should be just removed from the dep. list

<Text style={styles.text}>{I18n.t("messageUpdateApp")}</Text>
<Image
style={styles.img}
source={require("../../../img/icons/update-icon.png")}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to use the same pattern of all the codebase move this to the top of the component and use the import pattern:
import imageName from "../../../img/icons/update-icon.png"

@CrisTofani CrisTofani merged commit 99a9209 into master Dec 14, 2020
@CrisTofani CrisTofani deleted the 173248858-properly-handle-update-app-CTA branch December 14, 2020 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants