move to external async-storage module

This commit is contained in:
Bart Akeley 2019-09-26 16:48:07 -05:00
parent 7f06de277b
commit 97f9b0159c
7 changed files with 128 additions and 120 deletions

View file

@ -1,7 +1,7 @@
//@flow
import { type Auth0User, loginAuth0, createAuth0User, resetAuth0Password } from './apis/Auth0';
import moment from 'moment';
import { AsyncStorage } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
export const AUTH_PROVIDER_FACEBOOK: 'facebook' = 'facebook';
export const AUTH_PROVIDER_GOOGLE: 'google' = 'google';

View file

@ -1,7 +1,8 @@
// @flow
import { emitter } from "../streams/LocationStream";
import { getCoordsFromZip } from "./GoogleMapsApi";
import { AsyncStorage, PermissionsAndroid, Platform } from "react-native";
import { PermissionsAndroid, Platform } from "react-native";
import AsyncStorage from '@react-native-community/async-storage';
import Geolocation from "react-native-geolocation-service";
const {

View file

@ -1,13 +1,14 @@
// @flow
import React from "react";
import { View, Text, AsyncStorage } from "react-native";
import React from 'react';
import { View, Text } from 'react-native';
// import atcCookieImage from '../imgs/atc-cookie-logo.png';
import { Link } from "react-router-native";
import RouterButton from "react-router-native-button";
import { compose, withHandlers, withState } from "recompose";
import { withRouterContext } from "../enhancers/routeEnhancers";
import { Link } from 'react-router-native';
import RouterButton from 'react-router-native-button';
import { compose, withHandlers, withState } from 'recompose';
import { withRouterContext } from '../enhancers/routeEnhancers';
import AsyncStorage from '@react-native-community/async-storage';
import theme from "../ui-theme";
import theme from '../ui-theme';
type Props = {
skipIfAlreadyChosen: () => void,
@ -15,9 +16,9 @@ type Props = {
loading: boolean,
router: {
history: {
replace: (route: string) => void
}
}
replace: (route: string) => void,
},
},
};
const LandingPage = ({ skipIfAlreadyChosen, loading }: Props) => {
@ -29,19 +30,18 @@ const LandingPage = ({ skipIfAlreadyChosen, loading }: Props) => {
return (
<View
style={{
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
flex: 1,
height: "100%"
}}
>
height: '100%',
}}>
{/* <Image
source={atcCookieImage}
style={{ height: 320, marginBottom: 10 }}
resizeMode="contain"
/> */}
<Text style={{ fontSize: 24, marginBottom: 30, textAlign: "center", width: 330 }}>
<Text style={{ fontSize: 24, marginBottom: 30, textAlign: 'center', width: 330 }}>
We need to use your location to bring you the best experience possible.
</Text>
<View style={{ width: 275, marginBottom: 30 }}>
@ -58,15 +58,15 @@ const LandingPage = ({ skipIfAlreadyChosen, loading }: Props) => {
export default compose(
withRouterContext,
withState("loading", "setLoading", true),
withState('loading', 'setLoading', true),
withHandlers({
skipIfAlreadyChosen: (props: Props) => async () => {
const zipcode = await AsyncStorage.getItem("zipcode");
const zipcode = await AsyncStorage.getItem('zipcode');
if (zipcode) {
props.router.history.replace("/list/food");
props.router.history.replace('/list/food');
} else {
props.setLoading(false);
}
}
},
})
)(LandingPage);

View file

@ -1,12 +1,13 @@
// @flow
import React from "react";
import { View, Text, Switch, TextInput, AsyncStorage } from "react-native";
import IconButton from "../components/IconButton";
import { palette } from "../ui-theme";
import { compose, withState, withHandlers, lifecycle } from "recompose";
import { withRouterContext } from "../enhancers/routeEnhancers";
import { getLocation } from "../apis/PositionApi";
import Snackbar from "react-native-snackbar";
import React from 'react';
import { View, Text, Switch, TextInput } from 'react-native';
import IconButton from '../components/IconButton';
import { palette } from '../ui-theme';
import { compose, withState, withHandlers, lifecycle } from 'recompose';
import { withRouterContext } from '../enhancers/routeEnhancers';
import { getLocation } from '../apis/PositionApi';
import Snackbar from 'react-native-snackbar';
import AsyncStorage from '@react-native-community/async-storage';
type Props = {
zipcode: ?string,
@ -19,10 +20,10 @@ type Props = {
toggleGPS: (a: boolean) => Promise<void>,
router: {
history: {
replace: (route: string) => void
}
replace: (route: string) => void,
},
isLoggedIn: boolean
},
isLoggedIn: boolean,
};
export const ProfilePage = (props: Props) => {
@ -34,26 +35,25 @@ export const ProfilePage = (props: Props) => {
error,
toggleGPS,
router: { history },
isLoggedIn
isLoggedIn,
} = props;
const usingGPS = zipcode === "usegps";
const usingGPS = zipcode === 'usegps';
return (
<View style={{ flex: 1, flexDirection: "column", padding: 15 }}>
<Text style={{ fontSize: 32, marginBottom: 20, color: "#555555" }}>Profile</Text>
<View style={{ flexDirection: "row", justifyContent: "space-between" }}>
<View style={{ flex: 1, flexDirection: 'column', padding: 15 }}>
<Text style={{ fontSize: 32, marginBottom: 20, color: '#555555' }}>Profile</Text>
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
<Text style={{ fontSize: 18 }}>Use My Location</Text>
<Switch value={usingGPS} onValueChange={toggleGPS} />
</View>
{!usingGPS && (
<View style={{ flexDirection: "row" }}>
<View style={{ flexDirection: 'row' }}>
<View
style={{
flex: 1,
flexDirection: "column",
justifyContent: "flex-end",
height: 60
}}
>
flexDirection: 'column',
justifyContent: 'flex-end',
height: 60,
}}>
<TextInput
editable={!loading}
value={zipcode}
@ -62,19 +62,19 @@ export const ProfilePage = (props: Props) => {
onEndEditing={saveZip}
keyboardType="numeric"
style={{
fontSize: 18
fontSize: 18,
}}
/>
</View>
</View>
)}
{!!error && <Text style={{ fontSize: 16, color: "red" }}>{error}</Text>}
{!!error && <Text style={{ fontSize: 16, color: 'red' }}>{error}</Text>}
<View style={{ marginTop: 20 }}>
{isLoggedIn && (
<IconButton
glyph="exit-to-app"
text="Logout"
onPress={() => history.push("/logout")}
onPress={() => history.push('/logout')}
color={palette.accentColor}
textStyle={{ color: palette.accentColor }}
/>
@ -83,7 +83,7 @@ export const ProfilePage = (props: Props) => {
<IconButton
glyph="exit-to-app"
text="Login"
onPress={() => history.push("/login")}
onPress={() => history.push('/login')}
color={palette.accentColor}
textStyle={{ color: palette.accentColor }}
/>
@ -95,32 +95,32 @@ export const ProfilePage = (props: Props) => {
export default compose(
withRouterContext,
withState("loading", "setLoading", false),
withState("zipcode", "setZip", null),
withState("error", "setError", ""),
withState('loading', 'setLoading', false),
withState('zipcode', 'setZip', null),
withState('error', 'setError', ''),
withHandlers({
saveZip: (props: Props) => async () => {
props.setError("");
props.setError('');
if (!props.zipcode || props.zipcode.length !== 5) {
props.setError("Zipcode must be five digits");
props.setError('Zipcode must be five digits');
return;
}
props.setLoading(true);
await AsyncStorage.setItem("zipcode", props.zipcode);
await AsyncStorage.setItem('zipcode', props.zipcode);
props.setLoading(false);
getLocation();
Snackbar.show({ title: "Zipcode updated." });
}
Snackbar.show({ title: 'Zipcode updated.' });
},
}),
withHandlers({
toggleGPS: (props: Props) => async (useGPS: boolean) => {
try {
props.setLoading(true);
props.setZip(useGPS ? "usegps" : "");
await AsyncStorage.setItem("zipcode", "usegps");
props.setZip(useGPS ? 'usegps' : '');
await AsyncStorage.setItem('zipcode', 'usegps');
} catch (error) {
console.error(error); //eslint-disable-line no-console
props.setZip(props.zipcode || "");
props.setZip(props.zipcode || '');
} finally {
props.setLoading(false);
}
@ -128,17 +128,17 @@ export default compose(
getZipcode: ({ setLoading, setZip }) => async () => {
setLoading(true);
try {
setZip(await AsyncStorage.getItem("zipcode"));
setZip(await AsyncStorage.getItem('zipcode'));
} catch (error) {
console.error(error); //eslint-disable-line no-console
} finally {
setLoading(false);
}
}
},
}),
lifecycle({
componentDidMount() {
this.props.getZipcode();
}
},
})
)(ProfilePage);

View file

@ -1,10 +1,11 @@
// @flow
import React from 'react';
import { View, Text, TextInput, Button, AsyncStorage } from 'react-native';
import { View, Text, TextInput, Button } from 'react-native';
import { compose, withState, withHandlers } from 'recompose';
import { withRouterContext } from '../enhancers/routeEnhancers';
import theme from '../ui-theme';
import AsyncStorage from '@react-native-community/async-storage';
type Props = {
zipcode: string,

View file

@ -14,6 +14,7 @@
"android:install-apks": "yarn android:bundletool install-apks --apks=/tmp/app.apks"
},
"dependencies": {
"@react-native-community/async-storage": "^1.6.2",
"geodist": "^0.2.1",
"immutable": "^4.0.0-rc.12",
"moment": "^2.24.0",
@ -40,17 +41,17 @@
"@babel/core": "^7.5.0",
"@babel/runtime": "^7.5.0",
"@react-native-community/eslint-config": "^0.0.3",
"babel-jest": "^24.1.0",
"jest": "^24.1.0",
"metro-react-native-babel-preset": "0.54.1",
"react-test-renderer": "16.8.6",
"babel-eslint": "^8.1.1",
"babel-jest": "^24.1.0",
"babel-preset-react-native": "1.9.1",
"eslint": "^5",
"eslint-plugin-react": "^7",
"eslint-plugin-react-native": "^2.2.1",
"flow-bin": "^0.92.0",
"jshint": "^2.9.4"
"jest": "^24.1.0",
"jshint": "^2.9.4",
"metro-react-native-babel-preset": "0.54.1",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native"

View file

@ -1038,6 +1038,11 @@
"@types/istanbul-reports" "^1.1.1"
"@types/yargs" "^13.0.0"
"@react-native-community/async-storage@^1.6.2":
version "1.6.2"
resolved "https://registry.yarnpkg.com/@react-native-community/async-storage/-/async-storage-1.6.2.tgz#a19ca7149c4dfe8216f2330e6b1ebfe2d075ef92"
integrity sha512-EJGsbrHubK1mGxPjWB74AaHAd5m9I+Gg2RRPZzMK6org7QOU9WOBnIMFqoeVto3hKOaEPlk8NV74H6G34/2pZQ==
"@react-native-community/cli-platform-android@^2.6.0", "@react-native-community/cli-platform-android@^2.9.0":
version "2.9.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-android/-/cli-platform-android-2.9.0.tgz#28831e61ce565a2c7d1905852fce1eecfd33cb5e"