diff --git a/App.js b/App.js index 9c30c178..fa177ba7 100644 --- a/App.js +++ b/App.js @@ -4,13 +4,14 @@ import AddEntry from './components/AddEntry' import { createStore } from 'redux' import { Provider } from 'react-redux' import reducer from './reducers' +import History from './components/History' export default class App extends React.Component { render() { return ( - + ) diff --git a/components/History.js b/components/History.js new file mode 100644 index 00000000..8c35b586 --- /dev/null +++ b/components/History.js @@ -0,0 +1,40 @@ +import React, { Component } from 'react' +import { View, Text } from 'react-native' +import { connect } from 'react-redux' +import { receiveEntries, addEntry } from '../actions' +import { timeToString, getDailyReminderValue } from '../utils/helpers' +import { fetchCalendarResults } from '../utils/api' + +class History extends Component { + componentDidMount () { + const { dispatch } = this.props + + fetchCalendarResults() + .then((entries) => dispatch(receiveEntries(entries))) + .then(({ entries }) => { + if (!entries[timeToString()]) { + dispatch(addEntry({ + [timeToString()]: getDailyReminderValue() + })) + } + }) + .then(() => this.setState(() => ({ready: true}))) + } + render() { + return ( + + {JSON.stringify(this.props)} + + ) + } +} + +function mapStateToProps (entries) { + return { + entries + } +} + +export default connect( + mapStateToProps, +)(History) \ No newline at end of file diff --git a/utils/api.js b/utils/api.js index 4a3a6f03..7405e522 100644 --- a/utils/api.js +++ b/utils/api.js @@ -1,5 +1,10 @@ import { AsyncStorage } from 'react-native' -import { CALENDAR_STORAGE_KEY } from './_calendar' +import { formatCalendarResults, CALENDAR_STORAGE_KEY } from './_calendar' + +export function fetchCalendarResults () { + return AsyncStorage.getItem(CALENDAR_STORAGE_KEY) + .then(formatCalendarResults) +} export function submitEntry ({ entry, key }) { return AsyncStorage.mergeItem(CALENDAR_STORAGE_KEY, JSON.stringify({