From 085eda25bffd12c5d84e89054e98665cd22af985 Mon Sep 17 00:00:00 2001 From: Ken-ichi Ueda Date: Tue, 14 Jun 2022 14:29:40 -0700 Subject: [PATCH] Clean up eslint and flow errors Added some types, but most of this is a bit of a cop-out. Flow with hooks and dynamically keyed objects doesn't work all that well. --- .flowconfig | 3 ++ ios/Podfile.lock | 52 +++++++++++-------- .../LoginSignUp/AuthenticationService.js | 2 +- src/components/ObsEdit/CVSuggestions.js | 2 +- src/components/ObsEdit/ObsEditSearch.js | 2 +- src/components/Projects/ProjectSearch.js | 2 +- src/components/Search/Search.js | 2 +- src/components/Settings/Settings.js | 19 ++++--- src/components/Settings/SettingsAccount.js | 6 ++- .../Settings/SettingsApplications.js | 9 +++- .../Settings/SettingsContentDisplay.js | 15 +++++- .../Settings/SettingsNotifications.js | 11 ++-- src/components/Settings/SettingsProfile.js | 7 ++- .../Settings/SettingsRelationships.js | 16 ++++-- src/components/Settings/hooks/useUserMe.js | 4 +- src/components/Settings/types.js | 6 +++ .../SharedComponents/PermissionGate.js | 2 +- src/styles/permissionGate.js | 3 ++ src/styles/settings/settings.js | 4 +- tests/integration/MyObservations.test.js | 3 +- .../unit/components/LoginSignUp/Login.test.js | 19 ++++--- 21 files changed, 123 insertions(+), 66 deletions(-) create mode 100644 src/components/Settings/types.js diff --git a/.flowconfig b/.flowconfig index d18b9cf03..3b82a9c4a 100644 --- a/.flowconfig +++ b/.flowconfig @@ -11,6 +11,9 @@ node_modules/react-native/Libraries/polyfills/.* ; Flow doesn't support platforms .*/Libraries/Utilities/LoadingView.js +; This is an intentionally malflormed package +.*/node_modules/resolve/test/resolver/malformed.* + [untyped] .*/node_modules/@react-native-community/cli/.*/.* diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 14ba82a95..6be50e8b1 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -221,11 +221,13 @@ PODS: - React - react-native-geolocation-service (5.3.0-beta.4): - React + - react-native-image-picker (4.8.4): + - React-Core - react-native-image-resizer (1.4.5): - React-Core - react-native-maps (0.30.1): - React-Core - - react-native-netinfo (8.2.0): + - react-native-netinfo (8.3.0): - React-Core - react-native-safe-area-context (4.2.4): - RCT-Folly @@ -300,17 +302,17 @@ PODS: - React-jsi (= 0.67.4) - React-logger (= 0.67.4) - React-perflogger (= 0.67.4) - - RealmJS (10.20.0-beta.1): + - RealmJS (10.20.0-beta.5): - React - - RNAudioRecorderPlayer (3.3.4): + - RNAudioRecorderPlayer (3.4.0): - React-Core - RNCCheckbox (0.5.12): - React-Core - - RNCPicker (2.4.0): + - RNCPicker (2.4.1): - React-Core - - RNDateTimePicker (6.1.0): + - RNDateTimePicker (6.1.3): - React-Core - - RNDeviceInfo (8.5.1): + - RNDeviceInfo (8.7.1): - React-Core - RNFS (2.19.0): - React-Core @@ -352,7 +354,7 @@ PODS: - React-RCTImage - RNVectorIcons (9.1.0): - React-Core - - VisionCamera (2.13.0): + - VisionCamera (2.13.3): - React - React-callinvoker - React-Core @@ -383,6 +385,7 @@ DEPENDENCIES: - react-native-config (from `../node_modules/react-native-config`) - react-native-geocoder (from `../node_modules/react-native-geocoder`) - react-native-geolocation-service (from `../node_modules/react-native-geolocation-service`) + - react-native-image-picker (from `../node_modules/react-native-image-picker`) - react-native-image-resizer (from `../node_modules/react-native-image-resizer`) - react-native-maps (from `../node_modules/react-native-maps`) - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)" @@ -465,6 +468,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native-geocoder" react-native-geolocation-service: :path: "../node_modules/react-native-geolocation-service" + react-native-image-picker: + :path: "../node_modules/react-native-image-picker" react-native-image-resizer: :path: "../node_modules/react-native-image-resizer" react-native-maps: @@ -536,9 +541,9 @@ SPEC CHECKSUMS: FBLazyVector: f7b0632c6437e312acf6349288d9aa4cb6d59030 FBReactNativeSpec: 0f4e1f4cfeace095694436e7c7fcc5bf4b03a0ff fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 - glog: 5337263514dd6f09803962437687240c5dc39aa4 - Permission-LocationWhenInUse: 006c85c8de0c05b5d8be8e8029e4f6b813270293 - RCT-Folly: a21c126816d8025b547704b777a2ba552f3d9fa9 + glog: 85ecdd10ee8d8ec362ef519a6a45ff9aa27b2e85 + Permission-LocationWhenInUse: 50736c907dff5a77d80a3503d3b333831148288b + RCT-Folly: 803a9cfd78114b2ec0f140cfa6fa2a6bafb2d685 RCTRequired: 0aa6c1c27e1d65920df35ceea5341a5fe76bdb79 RCTTypeSafety: d76a59d00632891e11ed7522dba3fd1a995e573a React: ab8c09da2e7704f4b3ebad4baa6cfdfcc852dcb5 @@ -550,14 +555,15 @@ SPEC CHECKSUMS: React-jsiexecutor: cbdf37cebdc4f5d8b3d0bf5ccaa6147fd9de9f3d React-jsinspector: f4775ea9118cbe1f72b834f0f842baa7a99508d8 React-logger: a1f028f6d8639a3f364ef80419e5e862e1115250 - react-native-cameraroll: 2957f2bce63ae896a848fbe0d5352c1bd4d20866 + react-native-cameraroll: 60ac50a5209777cbccfe8d7a62d0743a9da87060 react-native-config: 6502b1879f97ed5ac570a029961fc35ea606cd14 react-native-geocoder: 757427682892bb256f3b3745858cc90eba148a8e react-native-geolocation-service: c0efb872258ed9240f1003a70fca9e9757e5c785 - react-native-image-resizer: d9fb629a867335bdc13230ac2a58702bb8c8828f + react-native-image-picker: 9f9eb160a4f4fc0702f9d0a60fa453b413258ef8 + react-native-image-resizer: 506412a2bdd70dde64a61e13505ce10f61a04369 react-native-maps: d752b0dd0e1951d815b1336332835aab6b4a836f - react-native-netinfo: e922cb2e3eaf9ccdf16b8d4744a89657377aa4a1 - react-native-safe-area-context: f98b0b16d1546d208fc293b4661e3f81a895afd9 + react-native-netinfo: ebbcd8fbe1a0ce7035e43cd18c5a545dcb93dd08 + react-native-safe-area-context: a95ad1a0e18341f58c5d6f53b0e2d43efade1a67 react-native-sensitive-info: d44e909d065f9c0e15734245e5dd6a24b82e3dcd React-perflogger: 0afaf2f01a47fd0fc368a93bfbb5bd3b26db6e7f React-RCTActionSheet: 59f35c4029e0b532fc42114241a06e170b7431a2 @@ -571,20 +577,20 @@ SPEC CHECKSUMS: React-RCTVibration: 3b52a7dced19cdb025b4f88ab26ceb2d85f30ba2 React-runtimeexecutor: a9d3c82ddf7ffdad9fbe6a81c6d6f8c06385464d ReactCommon: 07d0c460b9ba9af3eaf1b8f5abe7daaad28c9c4e - RealmJS: 74cf2dec0a20e7ca75655b5190eb60c062d106ec - RNAudioRecorderPlayer: 4efbe1839fd21c5caf8de132a8b3b51b422aa997 - RNCCheckbox: ed1b4ca295475b41e7251ebae046360a703b6eb5 - RNCPicker: 6d5d64e7b90c240c779ee0938ec433c11e2dd758 - RNDateTimePicker: 064f3a609fbebc6896f7e5a2f48dcee5d9a6fd51 - RNDeviceInfo: 8d4177859b062334835962799460528869a487fb + RealmJS: 772520fb85c19b65c2ea0c8f9aa6e790a905a377 + RNAudioRecorderPlayer: 4482e03d9336c8d8ba41825af227f74f41ba0a01 + RNCCheckbox: 934e11d33abb6b0db105cfa5a22a42bd89dfb4b9 + RNCPicker: abc646b53a3d28ccfa3232c927a0ca52e0cf024d + RNDateTimePicker: 47ab186e06826a4af7051b8a8199fac9477f339e + RNDeviceInfo: af47a7d1a09d64c8cbb8b0c883db9bca422a9813 RNFS: fc610f78fdf8bfc89a9e5cc2f898519f4dba1002 RNGestureHandler: 4f4986408310a43f1606c391f38f76e0d6e790d5 - RNLocalize: cbcb55d0e19c78086ea4eea20e03fe8000bbbced - RNPermissions: 34d678157c800b25b22a488e4d8babb57456e796 + RNLocalize: 414c99a0f6625a58dfee7f5780678d98c4ffabc2 + RNPermissions: 7ad8d93b004e6bc85c89e27a102afcde90e07efa RNReanimated: 96ab42cfb0e5517293499e0f3f810420eb459f75 RNScreens: 40a2cb40a02a609938137a1e0acfbf8fc9eebf19 RNVectorIcons: 7923e585eaeb139b9f4531d25a125a1500162a0b - VisionCamera: f6ebc7a6be166f3cd5744972b9ae394ca15a5145 + VisionCamera: c0198055514e3ed0d224be5939acd133c8d914ea Yoga: d6b6a80659aa3e91aaba01d0012e7edcbedcbecd PODFILE CHECKSUM: da0f05a708fcf3cbef37e07cf5b19489c9630466 diff --git a/src/components/LoginSignUp/AuthenticationService.js b/src/components/LoginSignUp/AuthenticationService.js index e6489538d..6cf862c86 100644 --- a/src/components/LoginSignUp/AuthenticationService.js +++ b/src/components/LoginSignUp/AuthenticationService.js @@ -10,7 +10,7 @@ import {getBuildNumber, getDeviceType, getSystemName, getSystemVersion, getVersi // Base API domain can be overridden (in case we want to use staging URL) - either by placing it in .env file, or // in an environment variable. -const API_HOST = Config.OAUTH_API_URL || process.env.OAUTH_API_URL || "https://www.inaturalist.org"; +const API_HOST: string = Config.OAUTH_API_URL || process.env.OAUTH_API_URL || "https://www.inaturalist.org"; // User agent being used, when calling the iNat APIs const USER_AGENT = `iNaturalistRN/${getVersion()} ${getDeviceType()} (Build ${getBuildNumber()}) ${getSystemName()}/${getSystemVersion()}`; diff --git a/src/components/ObsEdit/CVSuggestions.js b/src/components/ObsEdit/CVSuggestions.js index 7b503c557..32d1b33a4 100644 --- a/src/components/ObsEdit/CVSuggestions.js +++ b/src/components/ObsEdit/CVSuggestions.js @@ -26,7 +26,7 @@ const CVSuggestions = ( ): Node => { const [showSeenNearby, setShowSeenNearby] = useState( true ); const [selectedPhotoIndex, setSelectedPhotoIndex] = useState( 0 ); const [q, setQ] = React.useState( "" ); - const list = useRemoteObsEditSearchResults( q, "taxa" ); + const list = useRemoteObsEditSearchResults( q, "taxa", "all" ); const isLoggedIn = useLoggedIn( ); const currentObs = observations[currentObsIndex]; diff --git a/src/components/ObsEdit/ObsEditSearch.js b/src/components/ObsEdit/ObsEditSearch.js index d458bfe3c..4636f55d2 100644 --- a/src/components/ObsEdit/ObsEditSearch.js +++ b/src/components/ObsEdit/ObsEditSearch.js @@ -18,7 +18,7 @@ const ObsEditSearch = ( { }: Props ): React.Node => { const [q, setQ] = React.useState( "" ); // choose users or taxa - const list = useRemoteObsEditSearchResults( q, source ); + const list = useRemoteObsEditSearchResults( q, source, "all" ); // TODO: when UI is finalized, make sure these list results are not duplicate UI // with Search or Projects; share components if possible diff --git a/src/components/Projects/ProjectSearch.js b/src/components/Projects/ProjectSearch.js index 7aecc27e4..e452a19aa 100644 --- a/src/components/Projects/ProjectSearch.js +++ b/src/components/Projects/ProjectSearch.js @@ -12,7 +12,7 @@ type Props = { } const ProjectSearch = ( { q, clearSearch }: Props ): React.Node => { - const projectSearchResults = useRemoteSearchResults( q, "projects" ); + const projectSearchResults = useRemoteSearchResults( q, "projects", "all" ); if ( q === "" ) { return null; diff --git a/src/components/Search/Search.js b/src/components/Search/Search.js index 6fd66e25d..2dc5f18ac 100644 --- a/src/components/Search/Search.js +++ b/src/components/Search/Search.js @@ -14,7 +14,7 @@ const Search = ( ): React.Node => { const [q, setQ] = React.useState( "" ); const [queryType, setQueryType] = React.useState( "taxa" ); // choose users or taxa - const list = useRemoteSearchResults( q, queryType ); + const list = useRemoteSearchResults( q, queryType, "all" ); const renderItem = ( { item } ) => { // TODO: make sure TaxonDetails navigates back to Search diff --git a/src/components/Settings/Settings.js b/src/components/Settings/Settings.js index 23b09d49b..4125f8dcb 100644 --- a/src/components/Settings/Settings.js +++ b/src/components/Settings/Settings.js @@ -1,5 +1,3 @@ -// @flow strict-local - import React, { useCallback, useEffect, useState } from "react"; import { useFocusEffect } from "@react-navigation/native"; import { @@ -36,7 +34,9 @@ const TAB_TYPE_CONTENT_DISPLAY = "content_display"; const TAB_TYPE_APPLICATIONS = "applications"; // List of all user settings that will be saved (when calling the API to update the settings). -const SETTINGS_PROPERTIES_LIST = [ +// $FlowIgnore +const emailNotificationsValues: Array = Object.values( EMAIL_NOTIFICATIONS ); +const SETTINGS_PROPERTIES_LIST: Array = [ "login", "email", "name", @@ -61,7 +61,7 @@ const SETTINGS_PROPERTIES_LIST = [ "make_observation_licenses_same", "make_photo_licenses_same", "make_sound_licenses_same", - ...Object.values( EMAIL_NOTIFICATIONS ) + ...emailNotificationsValues ]; type Props = { @@ -149,8 +149,8 @@ const SettingsTabs = ( { activeTab, onTabPress } ): React.Node => { const Settings = ( { children }: Props ): Node => { const [activeTab, setActiveTab] = useState( TAB_TYPE_PROFILE ); - const [settings, setSettings] = useState(); - const [accessToken, setAccessToken] = useState(); + const [settings, setSettings] = useState( {} ); + const [accessToken, setAccessToken] = useState( null ); const [isLoading, setIsLoading] = useState( true ); const [isSaving, setIsSaving] = useState( false ); const user = useUserMe( accessToken ); @@ -164,7 +164,7 @@ const Settings = ( { children }: Props ): Node => { }, [user] ); useEffect( () => { - if ( accessToken ) { + if ( accessToken !== null ) { fetchProfile(); } }, [accessToken, fetchProfile] ); @@ -172,9 +172,9 @@ const Settings = ( { children }: Props ): Node => { const saveSettings = async () => { setIsSaving( true ); const payload = { - id: settings.id + id: settings?.id }; - SETTINGS_PROPERTIES_LIST.forEach( ( v ) => { + SETTINGS_PROPERTIES_LIST.forEach( ( v: string ) => { payload[`user[${v}]`] = settings[v]; } ); @@ -240,7 +240,6 @@ const Settings = ( { children }: Props ): Node => { Settings