Skip to content

Commit

Permalink
Start investigating the Storage and Identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardHaoranLee committed Nov 8, 2020
1 parent a2788c3 commit 1a44982
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 23 deletions.
23 changes: 0 additions & 23 deletions Flourish/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,3 @@ export default function App() {
);
}

// import { StatusBar } from 'expo-status-bar';
// import React from 'react';
// import { StyleSheet, Text, View } from 'react-native';
// import TabNavigation from './TabNavigation'
//
// export default function App() {
// return (
// <View style={styles.container}>
// <Text>Open up App.js to start working on your app!</Text>
// <StatusBar style="auto" />
// <TabNavigation />
// </View>
// );
// }
//
// const styles = StyleSheet.create({
// container: {
// flex: 1,
// backgroundColor: '#fff',
// alignItems: 'center',
// justifyContent: 'center',
// },
// });
57 changes: 57 additions & 0 deletions Flourish/Gateways/StorageAccess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { AsyncStorage } from 'react-native';

const STORAGE_KEY_PLANTS = '@plants'
const STORAGE_KEY_REMINDERS = '@reminders'

export default class StorageAccess extends React.Component {
state = {
plants: [],
reminders: []
}

savePlants = async () => {
try {
await AsyncStorage.setItem(STORAGE_KEY_PLANTS, this.state.plants)
alert('Data successfully saved')
} catch (e) {
alert('Failed to save the data to the storage')
}
}

saveReminders = async () => {
try {
await AsyncStorage.setItem(STORAGE_KEY_REMINDERS, this.state.reminders)
alert('Data successfully saved')
} catch (e) {
alert('Failed to save the data to the storage')
}
}

readPlants = async () => {
try {
const plants = await AsyncStorage.getItem(STORAGE_KEY_PLANTS)

if (plants !== null) {
this.setState({
plants: plants
})
}
} catch (e) {
alert('Failed to fetch the data from storage')
}
}

readReminders = async () => {
try {
const reminders = await AsyncStorage.getItem(STORAGE_KEY_REMINDERS)

if (reminders !== null) {
this.setState({
reminders: reminders
})
}
} catch (e) {
alert('Failed to fetch the data from storage')
}
}
}
1 change: 1 addition & 0 deletions Flourish/Tabs/FlourishingTabScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class FlourishingTabScreen extends React.Component{
componentDidMount() {
this.setState({
plants: this.props.plants

})
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 1a44982

Please sign in to comment.