diff --git a/package-lock.json b/package-lock.json index ed8f918..83a73c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@ui-kitten/eva-icons": "5.1.2", "@ui-kitten/moment": "5.1.2", "expo": "45.0.2", - "expo-application": "4.1.0", + "expo-application": "~4.1.0", "expo-asset": "8.5.0", "expo-constants": "13.1.1", "expo-crypto": "10.2.0", @@ -28,6 +28,7 @@ "expo-image-manipulator": "10.3.1", "expo-image-picker": "13.1.1", "expo-linking": "3.1.0", + "expo-network": "~4.2.0", "expo-sharing": "10.2.0", "expo-splash-screen": "0.15.1", "expo-sqlite": "10.2.0", @@ -41,7 +42,7 @@ "moment": "2.29.3", "react": "17.0.2", "react-dom": "17.0.2", - "react-native": "0.68.1", + "react-native": "0.68.2", "react-native-gesture-handler": "2.2.1", "react-native-reanimated": "2.8.0", "react-native-safe-area-context": "4.2.4", @@ -327,9 +328,9 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.16.7.tgz", - "integrity": "sha512-Qg3Nk7ZxpgMrsox6HreY1ZNKdBq7K72tDSliA6dCl5f007jR4ne8iD5UzuNnCJH2xBf2BEEVGr+/OL6Gdp7RxA==", + "version": "7.17.12", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.17.12.tgz", + "integrity": "sha512-JDkf04mqtN3y4iAbO1hv9U2ARpPyPL1zqyWs/2WG1pgSq9llHFjStX5jdxb84himgJm+8Ng+x0oiWF/nw/XQKA==", "engines": { "node": ">=6.9.0" } @@ -858,11 +859,11 @@ } }, "node_modules/@babel/plugin-syntax-flow": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.16.7.tgz", - "integrity": "sha512-UDo3YGQO0jH6ytzVwgSLv9i/CzMcUjbKenL67dTrAZPPv6GFAtDhe6jqnvmoKzC/7htNTohhos+onPtDMqJwaQ==", + "version": "7.17.12", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.17.12.tgz", + "integrity": "sha512-B8QIgBvkIG6G2jgsOHQUist7Sm0EBLDCx8sen072IwqNuzMegZNXrYnSv77cYzA8mLDZAfQYqsLIhimiP1s2HQ==", "dependencies": { - "@babel/helper-plugin-utils": "^7.16.7" + "@babel/helper-plugin-utils": "^7.17.12" }, "engines": { "node": ">=6.9.0" @@ -1168,12 +1169,12 @@ } }, "node_modules/@babel/plugin-transform-flow-strip-types": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.16.7.tgz", - "integrity": "sha512-mzmCq3cNsDpZZu9FADYYyfZJIOrSONmHcop2XEKPdBNMa4PDC4eEvcOvzZaCNcjKu72v0XQlA5y1g58aLRXdYg==", + "version": "7.17.12", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.17.12.tgz", + "integrity": "sha512-g8cSNt+cHCpG/uunPQELdq/TeV3eg1OLJYwxypwHtAWo9+nErH3lQx9CSO2uI9lF74A0mR0t4KoMjs1snSgnTw==", "dependencies": { - "@babel/helper-plugin-utils": "^7.16.7", - "@babel/plugin-syntax-flow": "^7.16.7" + "@babel/helper-plugin-utils": "^7.17.12", + "@babel/plugin-syntax-flow": "^7.17.12" }, "engines": { "node": ">=6.9.0" @@ -1702,13 +1703,13 @@ } }, "node_modules/@babel/preset-flow": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/preset-flow/-/preset-flow-7.16.7.tgz", - "integrity": "sha512-6ceP7IyZdUYQ3wUVqyRSQXztd1YmFHWI4Xv11MIqAlE4WqxBSd/FZ61V9k+TS5Gd4mkHOtQtPp9ymRpxH4y1Ug==", + "version": "7.17.12", + "resolved": "https://registry.npmjs.org/@babel/preset-flow/-/preset-flow-7.17.12.tgz", + "integrity": "sha512-7QDz7k4uiaBdu7N89VKjUn807pJRXmdirQu0KyR9LXnQrr5Jt41eIMKTS7ljej+H29erwmMrwq9Io9mJHLI3Lw==", "dependencies": { - "@babel/helper-plugin-utils": "^7.16.7", + "@babel/helper-plugin-utils": "^7.17.12", "@babel/helper-validator-option": "^7.16.7", - "@babel/plugin-transform-flow-strip-types": "^7.16.7" + "@babel/plugin-transform-flow-strip-types": "^7.17.12" }, "engines": { "node": ">=6.9.0" @@ -15480,6 +15481,14 @@ "invariant": "^2.2.4" } }, + "node_modules/expo-network": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/expo-network/-/expo-network-4.2.0.tgz", + "integrity": "sha512-1NcxK6kRIjUqNIHTT8wsstJluMSr3sLuJL8RvBLTR6wdo4rZS5oDKs8TiX0ExM5sRrL64alkDe8iTJZ0FyKZjA==", + "peerDependencies": { + "expo": "*" + } + }, "node_modules/expo-pwa": { "version": "0.0.119", "resolved": "https://registry.npmjs.org/expo-pwa/-/expo-pwa-0.0.119.tgz", @@ -32496,9 +32505,9 @@ "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "node_modules/react-native": { - "version": "0.68.1", - "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.68.1.tgz", - "integrity": "sha512-5gfvslo5NO2Ece2k/q41eVOK3ca4u1QAOf+qM+auvOiUA4/QR5Yr0WfSGbRpUr2GaFgv7qP11F4+elCravg7uQ==", + "version": "0.68.2", + "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.68.2.tgz", + "integrity": "sha512-qNMz+mdIirCEmlrhapAtAG+SWVx6MAiSfCbFNhfHqiqu1xw1OKXdzIrjaBEPihRC2pcORCoCHduHGQe/Pz9Yuw==", "dependencies": { "@jest/create-cache-key-function": "^27.0.1", "@react-native-community/cli": "^7.0.3", @@ -32522,7 +32531,7 @@ "pretty-format": "^26.5.2", "promise": "^8.0.3", "react-devtools-core": "^4.23.0", - "react-native-codegen": "^0.0.13", + "react-native-codegen": "^0.0.17", "react-native-gradle-plugin": "^0.0.6", "react-refresh": "^0.4.0", "react-shallow-renderer": "16.14.1", @@ -32544,9 +32553,9 @@ } }, "node_modules/react-native-codegen": { - "version": "0.0.13", - "resolved": "https://registry.npmjs.org/react-native-codegen/-/react-native-codegen-0.0.13.tgz", - "integrity": "sha512-rCh1P+s0Q4N6vNgS97ckafbhJRztz22+0l0VZoyQC06F07J98kI5cUByH0ATypPRIdpkMbAZc59DoPdDFc01bg==", + "version": "0.0.17", + "resolved": "https://registry.npmjs.org/react-native-codegen/-/react-native-codegen-0.0.17.tgz", + "integrity": "sha512-7GIEUmAemH9uWwB6iYXNNsPoPgH06pxzGRmdBzK98TgFBdYJZ7CBuZFPMe4jmHQTPOkQazKZ/w5O6/71JBixmw==", "dependencies": { "@babel/parser": "^7.14.0", "flow-parser": "^0.121.0", @@ -39632,9 +39641,9 @@ } }, "@babel/helper-plugin-utils": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.16.7.tgz", - "integrity": "sha512-Qg3Nk7ZxpgMrsox6HreY1ZNKdBq7K72tDSliA6dCl5f007jR4ne8iD5UzuNnCJH2xBf2BEEVGr+/OL6Gdp7RxA==" + "version": "7.17.12", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.17.12.tgz", + "integrity": "sha512-JDkf04mqtN3y4iAbO1hv9U2ARpPyPL1zqyWs/2WG1pgSq9llHFjStX5jdxb84himgJm+8Ng+x0oiWF/nw/XQKA==" }, "@babel/helper-remap-async-to-generator": { "version": "7.16.8", @@ -39977,11 +39986,11 @@ } }, "@babel/plugin-syntax-flow": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.16.7.tgz", - "integrity": "sha512-UDo3YGQO0jH6ytzVwgSLv9i/CzMcUjbKenL67dTrAZPPv6GFAtDhe6jqnvmoKzC/7htNTohhos+onPtDMqJwaQ==", + "version": "7.17.12", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.17.12.tgz", + "integrity": "sha512-B8QIgBvkIG6G2jgsOHQUist7Sm0EBLDCx8sen072IwqNuzMegZNXrYnSv77cYzA8mLDZAfQYqsLIhimiP1s2HQ==", "requires": { - "@babel/helper-plugin-utils": "^7.16.7" + "@babel/helper-plugin-utils": "^7.17.12" } }, "@babel/plugin-syntax-import-meta": { @@ -40173,12 +40182,12 @@ } }, "@babel/plugin-transform-flow-strip-types": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.16.7.tgz", - "integrity": "sha512-mzmCq3cNsDpZZu9FADYYyfZJIOrSONmHcop2XEKPdBNMa4PDC4eEvcOvzZaCNcjKu72v0XQlA5y1g58aLRXdYg==", + "version": "7.17.12", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.17.12.tgz", + "integrity": "sha512-g8cSNt+cHCpG/uunPQELdq/TeV3eg1OLJYwxypwHtAWo9+nErH3lQx9CSO2uI9lF74A0mR0t4KoMjs1snSgnTw==", "requires": { - "@babel/helper-plugin-utils": "^7.16.7", - "@babel/plugin-syntax-flow": "^7.16.7" + "@babel/helper-plugin-utils": "^7.17.12", + "@babel/plugin-syntax-flow": "^7.17.12" } }, "@babel/plugin-transform-for-of": { @@ -40521,13 +40530,13 @@ } }, "@babel/preset-flow": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/preset-flow/-/preset-flow-7.16.7.tgz", - "integrity": "sha512-6ceP7IyZdUYQ3wUVqyRSQXztd1YmFHWI4Xv11MIqAlE4WqxBSd/FZ61V9k+TS5Gd4mkHOtQtPp9ymRpxH4y1Ug==", + "version": "7.17.12", + "resolved": "https://registry.npmjs.org/@babel/preset-flow/-/preset-flow-7.17.12.tgz", + "integrity": "sha512-7QDz7k4uiaBdu7N89VKjUn807pJRXmdirQu0KyR9LXnQrr5Jt41eIMKTS7ljej+H29erwmMrwq9Io9mJHLI3Lw==", "requires": { - "@babel/helper-plugin-utils": "^7.16.7", + "@babel/helper-plugin-utils": "^7.17.12", "@babel/helper-validator-option": "^7.16.7", - "@babel/plugin-transform-flow-strip-types": "^7.16.7" + "@babel/plugin-transform-flow-strip-types": "^7.17.12" } }, "@babel/preset-modules": { @@ -51589,6 +51598,12 @@ "invariant": "^2.2.4" } }, + "expo-network": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/expo-network/-/expo-network-4.2.0.tgz", + "integrity": "sha512-1NcxK6kRIjUqNIHTT8wsstJluMSr3sLuJL8RvBLTR6wdo4rZS5oDKs8TiX0ExM5sRrL64alkDe8iTJZ0FyKZjA==", + "requires": {} + }, "expo-pwa": { "version": "0.0.119", "resolved": "https://registry.npmjs.org/expo-pwa/-/expo-pwa-0.0.119.tgz", @@ -64879,9 +64894,9 @@ "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "react-native": { - "version": "0.68.1", - "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.68.1.tgz", - "integrity": "sha512-5gfvslo5NO2Ece2k/q41eVOK3ca4u1QAOf+qM+auvOiUA4/QR5Yr0WfSGbRpUr2GaFgv7qP11F4+elCravg7uQ==", + "version": "0.68.2", + "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.68.2.tgz", + "integrity": "sha512-qNMz+mdIirCEmlrhapAtAG+SWVx6MAiSfCbFNhfHqiqu1xw1OKXdzIrjaBEPihRC2pcORCoCHduHGQe/Pz9Yuw==", "requires": { "@jest/create-cache-key-function": "^27.0.1", "@react-native-community/cli": "^7.0.3", @@ -64905,7 +64920,7 @@ "pretty-format": "^26.5.2", "promise": "^8.0.3", "react-devtools-core": "^4.23.0", - "react-native-codegen": "^0.0.13", + "react-native-codegen": "^0.0.17", "react-native-gradle-plugin": "^0.0.6", "react-refresh": "^0.4.0", "react-shallow-renderer": "16.14.1", @@ -64936,9 +64951,9 @@ } }, "react-native-codegen": { - "version": "0.0.13", - "resolved": "https://registry.npmjs.org/react-native-codegen/-/react-native-codegen-0.0.13.tgz", - "integrity": "sha512-rCh1P+s0Q4N6vNgS97ckafbhJRztz22+0l0VZoyQC06F07J98kI5cUByH0ATypPRIdpkMbAZc59DoPdDFc01bg==", + "version": "0.0.17", + "resolved": "https://registry.npmjs.org/react-native-codegen/-/react-native-codegen-0.0.17.tgz", + "integrity": "sha512-7GIEUmAemH9uWwB6iYXNNsPoPgH06pxzGRmdBzK98TgFBdYJZ7CBuZFPMe4jmHQTPOkQazKZ/w5O6/71JBixmw==", "requires": { "@babel/parser": "^7.14.0", "flow-parser": "^0.121.0", diff --git a/package.json b/package.json index 6487d29..8514780 100644 --- a/package.json +++ b/package.json @@ -48,14 +48,15 @@ "moment": "2.29.3", "react": "17.0.2", "react-dom": "17.0.2", - "react-native": "0.68.1", + "react-native": "0.68.2", "react-native-gesture-handler": "2.2.1", "react-native-reanimated": "2.8.0", "react-native-safe-area-context": "4.2.4", "react-native-screens": "3.11.1", "react-native-svg": "12.3.0", "react-native-web": "0.17.7", - "sentry-expo": "4.1.1" + "sentry-expo": "4.1.1", + "expo-network": "4.2.0" }, "devDependencies": { "@babel/core": "7.17.10", diff --git a/src/services/GrowBuddyPlantsService.ts b/src/services/GrowBuddyPlantsService.ts index 8f1ff73..5af1659 100644 --- a/src/services/GrowBuddyPlantsService.ts +++ b/src/services/GrowBuddyPlantsService.ts @@ -5,28 +5,39 @@ import {PreferredLocation} from "../model/PreferredLocation"; import {isDefined} from "../common/Utils"; import * as FileSystem from "expo-file-system"; import Fuse from 'fuse.js' +import * as Network from 'expo-network'; import FuseResult = Fuse.FuseResult; const REMOTE_GROW_BUDDY_PLANTS_URI = "https://raw.githubusercontent.com/Grow-Buddy/grow-buddy-plants/main/database.json"; -const LOCAL_GROW_BUDDY_PLANTS_URI = `${FileSystem.documentDirectory}/plants-reference-database.json` +const LOCAL_GROW_BUDDY_PLANTS_URI = `${FileSystem.documentDirectory}/plants-reference-database.json`; class GrowBuddyPlantsService { - referenceDatabase!: PlantInfo[]; + private referenceDatabase: PlantInfo[] = []; constructor() { - this.initializeDatabase(); + this.updateAndLoadDatabase(); } - async initializeDatabase() { - await FileSystem.downloadAsync(REMOTE_GROW_BUDDY_PLANTS_URI, LOCAL_GROW_BUDDY_PLANTS_URI); - const rawReferenceDatabase = await FileSystem.readAsStringAsync(LOCAL_GROW_BUDDY_PLANTS_URI); - this.referenceDatabase = JSON.parse(rawReferenceDatabase); + async updateAndLoadDatabase() { + const networkState = await Network.getNetworkStateAsync(); + if (networkState.isInternetReachable) { + await FileSystem.downloadAsync(REMOTE_GROW_BUDDY_PLANTS_URI, LOCAL_GROW_BUDDY_PLANTS_URI, {cache: false}); + } + + const databaseFileInfo = await FileSystem.getInfoAsync(LOCAL_GROW_BUDDY_PLANTS_URI); + if (databaseFileInfo.exists) { + const rawReferenceDatabase = await FileSystem.readAsStringAsync(LOCAL_GROW_BUDDY_PLANTS_URI); + this.referenceDatabase = JSON.parse(rawReferenceDatabase); + } + } - FileSystem.deleteAsync(LOCAL_GROW_BUDDY_PLANTS_URI); + getDatabaseSize() { + return this.referenceDatabase.length; } - async searchForProducts(query: string): Promise { + async search(query: string): + Promise { const fuse = new Fuse(this.referenceDatabase!, {keys: ['name', 'botanicalName']}) const result = fuse.search(query) diff --git a/src/stacks/default/tabs/developer/screens/DeveloperOverviewScreen.tsx b/src/stacks/default/tabs/developer/screens/DeveloperOverviewScreen.tsx index 2c025fe..e2c5b43 100644 --- a/src/stacks/default/tabs/developer/screens/DeveloperOverviewScreen.tsx +++ b/src/stacks/default/tabs/developer/screens/DeveloperOverviewScreen.tsx @@ -13,6 +13,8 @@ import * as Updates from 'expo-updates'; import DrawerAction from "../../../../../common/components/DrawerAction"; import ImageRepository from "../../../../../repositories/ImageRepository"; import LoadingContainer from "../../../../../common/components/LoadingContainer"; +import * as Application from 'expo-application'; +import GrowBuddyPlantsService from "../../../../../services/GrowBuddyPlantsService"; export default () => { @@ -20,6 +22,7 @@ export default () => { const route = useRoute>(); const [waiting, setWaiting] = useState(false); + const [referenceDatabaseSize, setReferenceDatabaseSize] = useState(GrowBuddyPlantsService.getDatabaseSize()); async function fetchAndApplyOTAUpdate() { try { @@ -68,6 +71,16 @@ export default () => { } } + async function updateReferenceDatabase() { + try { + setWaiting(true); + await GrowBuddyPlantsService.updateAndLoadDatabase(); + setReferenceDatabaseSize(GrowBuddyPlantsService.getDatabaseSize()) + } finally { + setWaiting(false); + } + } + function renderVersionItem({item}: ListRenderItemInfo) { return ( @@ -81,12 +94,12 @@ export default () => { }, { key: 'Native App Version', - value: Constants.nativeAppVersion + value: Application.nativeApplicationVersion } ] - const Footer = (props: any) => ( + const VersionsFooter = (props: any) => ( + + ) + return ( { accessoryLeft={DrawerAction}/> - + + + + + +