From aa65a3170713e4a61eee87871ef1859a922a2e76 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 23 Sep 2019 19:42:36 +0200 Subject: [PATCH] fix: No console.warn when amplitude key undefined (#217) * fix: No console.warn when amplitude key undefined * Fix ts errors * Use double quote --- App/App.tsx | 38 ++++++++++++++++------------- App/Screens/About/About.tsx | 5 +++- App/Screens/Details/Details.tsx | 2 +- App/Screens/Search/Search.tsx | 2 +- App/util/amplitude.ts | 5 ++++ app.example.json | 1 - package.json | 6 ++--- yarn.lock | 42 ++++++++++++++++----------------- 8 files changed, 57 insertions(+), 44 deletions(-) diff --git a/App/App.tsx b/App/App.tsx index df36fef3..f3222245 100644 --- a/App/App.tsx +++ b/App/App.tsx @@ -40,27 +40,33 @@ if (Constants.manifest.extra.sentryPublicDsn) { } } -// Add Amplitude if available -if (Constants.manifest.extra.amplitudeApiKey) { - Amplitude.initialize(Constants.manifest.extra.amplitudeApiKey); - Amplitude.setUserProperties({ - sisReleaseChannel: Constants.manifest.releaseChannel || 'development', - sisVersion: Constants.manifest.version - }); -} - export function App () { - const [fontLoaded, setFontLoaded] = useState(false); + const [ready, setReady] = useState(false); useEffect(() => { - Font.loadAsync({ - 'gotham-black': require('../assets/fonts/Gotham-Black.ttf'), - 'gotham-book': require('../assets/fonts/Gotham-Book.ttf') - }) - .then(() => setFontLoaded(true)) + Promise.all([ + Font.loadAsync({ + 'gotham-black': require('../assets/fonts/Gotham-Black.ttf'), + 'gotham-book': require('../assets/fonts/Gotham-Book.ttf') + }), + // Add Amplitude if available + Constants.manifest.extra.amplitudeApiKey + ? Amplitude.initialize(Constants.manifest.extra.amplitudeApiKey).then( + () => { + Amplitude.setUserProperties({ + sisReleaseChannel: + Constants.manifest.releaseChannel || 'development', + sisVersion: Constants.manifest.version + }); + } + ) + : Promise.resolve() + ]) + + .then(() => setReady(true)) .catch(console.error); }, []); - return fontLoaded ? ( + return ready ? ( diff --git a/App/Screens/About/About.tsx b/App/Screens/About/About.tsx index 7430924d..65f5b509 100644 --- a/App/Screens/About/About.tsx +++ b/App/Screens/About/About.tsx @@ -79,7 +79,10 @@ export function About (props: AboutProps) { scrollIntoViewOptions={scrollViewOptions} style={theme.withPadding} > - navigation.pop()} style={styles.backButton} /> + navigation.goBack()} + style={styles.backButton} + /> diff --git a/App/Screens/Details/Details.tsx b/App/Screens/Details/Details.tsx index d42d002a..a49b9b78 100644 --- a/App/Screens/Details/Details.tsx +++ b/App/Screens/Details/Details.tsx @@ -88,7 +88,7 @@ export function Details (props: DetailsProps) { return ( -
navigation.pop()} /> +
navigation.goBack()} /> {showMap && ( props.navigation.pop()} + onPress={() => props.navigation.goBack()} style={styles.backButton} /> diff --git a/App/util/amplitude.ts b/App/util/amplitude.ts index 00e83090..d5befb6d 100644 --- a/App/util/amplitude.ts +++ b/App/util/amplitude.ts @@ -15,6 +15,7 @@ // along with Sh**t! I Smoke. If not, see . import * as Amplitude from 'expo-analytics-amplitude'; +import Constants from 'expo-constants'; import { useEffect } from 'react'; type AmplitudeEvent = @@ -43,6 +44,10 @@ type AmplitudeEvent = | 'ERROR_SCREEN_CHANGE_LOCATION_CLICK'; export function track (event: AmplitudeEvent, properties?: Record) { + if (!Constants.manifest.extra.amplitudeApiKey) { + return; + } + properties ? Amplitude.logEventWithProperties(event, properties) : Amplitude.logEvent(event); diff --git a/app.example.json b/app.example.json index f6079230..1bf5dca7 100644 --- a/app.example.json +++ b/app.example.json @@ -17,7 +17,6 @@ "algoliaApplicationId": "YOUR_KEY", "amplitudeApiKey": "YOUR_KEY", "githubUrl": "https://github.com/amaurymartiny/shoot-i-smoke", - "locationIqKey": "YOUR_KEY", "sentryPublicDsn": "YOUR_KEY", "waqiToken": "YOUR_KEY" }, diff --git a/package.json b/package.json index e53ffdbb..39334a05 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@types/expo": "^32.0.13", "@types/haversine": "^1.1.4", "@types/i18n-js": "^3.0.1", - "@types/node": "^12.7.2", + "@types/node": "^12.7.5", "@types/react-native": "^0.60.15", "axios": "^0.19.0", "date-fns": "^2.2.1", @@ -35,7 +35,7 @@ "io-ts": "^2.0.1", "react": "16.8.3", "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz", - "react-native-gesture-handler": "~1.4.1", + "react-native-gesture-handler": "~1.3.0", "react-native-maps": "^0.24.2", "react-native-reanimated": "~1.2.0", "react-native-scroll-into-view": "^1.0.3", @@ -64,7 +64,7 @@ "eslint-plugin-standard": "^4.0.1", "jest": "^24.9.0", "jest-expo": "^35.0.0", - "ts-jest": "^24.0.2", + "ts-jest": "^24.1.0", "typescript": "^3.6.3" } } diff --git a/yarn.lock b/yarn.lock index 8cada657..41fd6f7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1316,10 +1316,10 @@ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.136.tgz#413e85089046b865d960c9ff1d400e04c31ab60f" integrity sha512-0GJhzBdvsW2RUccNHOBkabI8HZVdOXmXbXhuKlDEd5Vv12P7oAVGfomGp3Ne21o5D/qu1WmthlNKFaoZJJeErA== -"@types/node@^12.7.2": - version "12.7.2" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.2.tgz#c4e63af5e8823ce9cc3f0b34f7b998c2171f0c44" - integrity sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg== +"@types/node@^12.7.5": + version "12.7.5" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.5.tgz#e19436e7f8e9b4601005d73673b6dc4784ffcc2f" + integrity sha512-9fq4jZVhPNW8r+UYKnxF1e2HkDWOWKM5bC2/7c9wPV835I0aOrVbS/Hw/pWPk2uKrNXQqg9Z959Kz+IYDd5p3w== "@types/prop-types@*": version "15.7.1" @@ -3693,11 +3693,6 @@ growly@^1.3.0: resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE= -hammerjs@^2.0.8: - version "2.0.8" - resolved "https://registry.yarnpkg.com/hammerjs/-/hammerjs-2.0.8.tgz#04ef77862cff2bb79d30f7692095930222bf60f1" - integrity sha1-BO93hiz/K7edMPdpIJWTAiK/YPE= - handlebars@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.1.2.tgz#b6b37c1ced0306b221e094fc7aca3ec23b131b67" @@ -4985,6 +4980,11 @@ locate-path@^3.0.0: p-locate "^3.0.0" path-exists "^3.0.0" +lodash.memoize@4.x: + version "4.1.2" + resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" + integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4= + lodash.pad@^4.1.0: version "4.5.1" resolved "https://registry.yarnpkg.com/lodash.pad/-/lodash.pad-4.5.1.tgz#4330949a833a7c8da22cc20f6a26c4d59debba70" @@ -6332,7 +6332,7 @@ prompts@^2.2.1: kleur "^3.0.3" sisteransi "^1.0.3" -prop-types@>=15.6.1, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2: +prop-types@>=15.6.1, prop-types@^15.5.10, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2: version "15.7.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== @@ -6459,15 +6459,14 @@ react-native-branch@~3.0.1: resolved "https://registry.yarnpkg.com/react-native-branch/-/react-native-branch-3.0.1.tgz#5b07b61cbd290168cd3c3662e017ebe0f356d2ca" integrity sha512-vbcYxPZlpF5f39GAEUF8kuGQqCNeD3E6zEdvtOq8oCGZunHXlWlKgAS6dgBKCvsHvXgHuMtpvs39VgOp8DaKig== -react-native-gesture-handler@~1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.4.1.tgz#c38d9e57637b95e221722a79f2bafac62e3aeb21" - integrity sha512-Ffcs+SbEbkGaal0CClYL+v7A9y4OA5G5lW01qrzjxaqASp5C8BfnWSKuqYKE00s6bLwE5L4xnlHkG0yIxAtbrQ== +react-native-gesture-handler@~1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.3.0.tgz#d0386f565928ccc1849537f03f2e37fd5f6ad43f" + integrity sha512-ASRFIXBuKRvqlmwkWJhV8yP2dTpvcqVrLNpd7FKVBFHYWr6SAxjGyO9Ik8w1lAxDhMlRP2IcJ9p9eq5X2WWeLQ== dependencies: - hammerjs "^2.0.8" hoist-non-react-statics "^2.3.1" - invariant "^2.2.4" - prop-types "^15.7.2" + invariant "^2.2.2" + prop-types "^15.5.10" react-native-maps@*: version "0.25.0" @@ -7618,15 +7617,16 @@ truncate@^2.1.0: resolved "https://registry.yarnpkg.com/truncate/-/truncate-2.1.0.tgz#391183563a25cffbd4d613a1d00ae5844c9e55d3" integrity sha512-em3E3SUDONOjTBcZ36DTm3RvDded3IRU9rX32oHwwXNt3rJD5MVaFlJTQvs8tJoHRoeYP36OuQ1eL/Q7bNEWIQ== -ts-jest@^24.0.2: - version "24.0.2" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.2.tgz#8dde6cece97c31c03e80e474c749753ffd27194d" - integrity sha512-h6ZCZiA1EQgjczxq+uGLXQlNgeg02WWJBbeT8j6nyIBRQdglqbvzDoHahTEIiS6Eor6x8mK6PfZ7brQ9Q6tzHw== +ts-jest@^24.1.0: + version "24.1.0" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.1.0.tgz#2eaa813271a2987b7e6c3fefbda196301c131734" + integrity sha512-HEGfrIEAZKfu1pkaxB9au17b1d9b56YZSqz5eCVE8mX68+5reOvlM93xGOzzCREIov9mdH7JBG+s0UyNAqr0tQ== dependencies: bs-logger "0.x" buffer-from "1.x" fast-json-stable-stringify "2.x" json5 "2.x" + lodash.memoize "4.x" make-error "1.x" mkdirp "0.x" resolve "1.x"