Commit 32429070 authored by AuckeBos's avatar AuckeBos
Browse files

Using custom api function eventlist for retrieving calendar

parent 3248ba41
import { AsyncStorage } from 'react-native';
import * as types from './actionTypes';
const TOKENKEY = '@MyStore:token';
export function calendarRetrieved(eventList) {
return {
type: types.CALENDARRETREIVED,
......@@ -13,23 +16,36 @@ export function calendarNotRetrieved() {
};
}
export function retrieveCalendar(){
return (dispatch)=> {
let start = new Date().toISOString().substring(0, 10);
let end = new Date();
end.setMonth(end.getMonth() + 6);
end = end.toISOString().substring(0, 10);
return fetch('http://localhost:8000/api/events?start='+start+'&end='+end)
.then(
response => response.json())
export function retrieveCalendar() {
return (dispatch) => {
AsyncStorage.getItem(TOKENKEY)
.then(
(responseJson) => {
console.log(responseJson);
return dispatch(calendarRetrieved(responseJson));
})
.catch((error) => {
console.log(error);
dispatch(calendarNotRetrieved());
})
};
}
\ No newline at end of file
(token) => {
let start = new Date().toISOString().substring(0, 10);
let end = new Date();
end.setMonth(end.getMonth() + 6);
end = end.toISOString().substring(0, 10);
const data = {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Token ' + token,
},
};
return fetch('http://localhost:8000/api/events/eventlist/?start=' + start + '&end=' + end, data)
.then(
response => response.json())
.then(
(responseJson) => {
console.log(responseJson);
return dispatch(calendarRetrieved(responseJson));
})
.catch((error) => {
console.log(error);
dispatch(calendarNotRetrieved());
})
}
);
};
}
\ No newline at end of file
import * as types from "./actionTypes";
export function openEvent(eventId) {
return null;
console.log("opening event");
return {
};
}
......@@ -2,7 +2,7 @@ import React from 'react';
import { Text, View, ListView } from 'react-native';
import { connect } from 'react-redux';
import * as actions from '../actions/calendar';
import Event from './EventCard';
import EventCard from './EventCard';
const Calendar = (props) => {
if(!props.calendarFetched) {
......@@ -16,12 +16,15 @@ const Calendar = (props) => {
)
}
else {
console.log('calendar is retrieved');
console.log(props);
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
let events = [];
for (let i = 0; i < props.eventList.length; i++) {
events.push(Event(props.eventList[i]));
console.log(props.eventList[i]);
events.push(<EventCard event={props.eventList[i]}/>);
}
console.log(events);
const dataSource = ds.cloneWithRows(events);
return (
<View>
......
import React from 'react';
import { View, Text } from 'react-native';
import { View, Text, Button } from 'react-native';
import { connect } from 'react-redux';
import { openEvent } from '../actions/eventCard';
import * as actions from '../actions/eventCard';
const Event = (event) =>
const EventCard = (props) =>
<View>
<Text> <b>{event.title}</b> </Text>
<Text> {new Date(event.start).toISOString().substring(0, 10)}</Text>
<i>{event.description}</i>
<Text> onPress={() => actions.openEvent(props.event.id)} <b>{props.event.title}</b> </Text>
<Text> {new Date(props.event.start).toISOString().substring(0, 10)}</Text>
<i>{props.event.description}</i>
<Text>-----------------------------------------</Text>
onPress={() => openEvent(event.id)}
</View>
;
Event.propTypes = {
EventCard.propTypes = {
openEvent: React.PropTypes.func.isRequired,
event: React.PropTypes.object.isRequired,
};
const mapDispatchToProps = dispatch => ({
openEvent: () => dispatch(openEvent()),
openEvent: (event_id) => dispatch(actions.openEvent(event_id)),
});
export default connect(() => ({}), mapDispatchToProps)(Event);
export default Event;
\ No newline at end of file
export default connect(() => ({}), mapDispatchToProps)(EventCard);
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment