Commit 92412959 authored by AuckeBos's avatar AuckeBos Committed by Wietse Kuipers
Browse files

Calendar retrieval fixed

parent 25342103
...@@ -6,3 +6,6 @@ export const LOGINSUCCESS = 'LOGINSUCCESS'; ...@@ -6,3 +6,6 @@ export const LOGINSUCCESS = 'LOGINSUCCESS';
export const LOGINFAILURE = 'LOGINFAILURE'; export const LOGINFAILURE = 'LOGINFAILURE';
export const LOGOUT = 'LOGOUT'; export const LOGOUT = 'LOGOUT';
export const OPENDRAWER = 'OPENDRAWER'; export const OPENDRAWER = 'OPENDRAWER';
export const CALENDARRETREIVED = 'CALENDARRETREIVED';
export const CALENDARERROR = 'CALENDARERROR';
/** import * as types from './actionTypes';
* Created by aucke on 3/8/17.
*/ export function calendarRetrieved(eventList) {
return {
type: types.CALENDARRETREIVED,
eventList:eventList
};
}
export function calendarNotRetrieved() {
return {
type: types.CALENDARERROR,
};
}
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())
.then(
(responseJson) => {
console.log(responseJson);
return dispatch(calendarRetrieved(responseJson));
})
.catch((error) => {
console.log(error);
dispatch(calendarNotRetrieved());
})
};
}
\ No newline at end of file
import React from 'react'; import React from 'react';
import { Text, View } from 'react-native'; import { Text, View, ListView } from 'react-native';
import { connect } from 'react-redux';
import * as actions from '../actions/calendar';
import Event from './Event';
const Calendar = () => const Calendar = (props) => {
<View> if(!props.calendarFetched) {
<Text> props.retrieveCalendar();
Algemene Ledenvergadering return (
</Text> <View>
<Text> <Text>
Lunchlezing Rijksoverheid No calendar retrieved!
</Text> </Text>
<Text> </View>
Benefietborrel )
</Text> }
</View> else {
; 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]));
}
const dataSource = ds.cloneWithRows(events);
return (
<View>
<ListView
dataSource={dataSource}
renderRow={(rowData) => rowData}
/>
</View>
);
}
};
export default Calendar; const mapStateToProps = state => state.calendar;
const mapDispatchToProps = dispatch => ({
retrieveCalendar: () => dispatch(actions.retrieveCalendar()),
});
export default connect(mapStateToProps, mapDispatchToProps)(Calendar);
import React from 'react';
import { View, Text } from 'react-native';
const Event = (event) =>
<View>
<Text> <b>{event.title}</b> </Text>
<Text> {new Date(event.start).toISOString().substring(0, 10)}</Text>
<i>{event.description}</i>
<Text>-----------------------------------------</Text>
</View>
;
export default Event;
\ No newline at end of file
...@@ -12,7 +12,7 @@ const Sidebar = props => ...@@ -12,7 +12,7 @@ const Sidebar = props =>
> >
<Text style={styles.header}>MENU</Text> <Text style={styles.header}>MENU</Text>
<Text onPress={() => props.navigate('welcome')} style={styles.button} >Welcome</Text> <Text onPress={() => props.navigate('welcome')} style={styles.button} >Welcome</Text>
<Text onPress={() => props.navigate('agenda')} style={styles.button} >Agenda</Text> <Text onPress={() => props.navigate('eventList')} style={styles.button} >Calendar</Text>
</View> </View>
; ;
......
...@@ -5,7 +5,8 @@ import PropTypes from 'prop-types'; ...@@ -5,7 +5,8 @@ import PropTypes from 'prop-types';
import Login from './Login'; import Login from './Login';
import Welcome from './Welcome'; import Welcome from './Welcome';
import Sidebar from './Sidebar'; import Sidebar from './Sidebar';
import Agenda from './Agenda'; import Calendar from './Calendar';
import Agenda from './Calendar';
import * as actions from '../actions/navigation'; import * as actions from '../actions/navigation';
...@@ -23,8 +24,8 @@ const sceneToComponent = (scene) => { ...@@ -23,8 +24,8 @@ const sceneToComponent = (scene) => {
switch (scene) { switch (scene) {
case 'welcome': case 'welcome':
return <Welcome />; return <Welcome />;
case 'agenda': case 'eventList':
return <Agenda />; return <Calendar />;
default: default:
return <Welcome />; return <Welcome />;
} }
......
import * as types from '../actions/actionTypes'; import * as types from '../actions/actionTypes';
const initialState = { const initialState = {
eventList:'',
calendarFetched: false,
}; };
export default function calendar(state = initialState, action = {}) { export default function calendar(state = initialState, action = {}) {
switch (action.type) { switch (action.type) {
case types.CALENDARRETREIVED:
return{...state, eventList:action.eventList, calendarFetched:true};
case types.CALENDARERROR:
return{...state, calendarFetched:true};
default: default:
return { ...state }; return { ...state };
} }
}/** }
* Created by aucke on 3/8/17.
*/
import login from './login'; import login from './login';
import navigation from './navigation'; import navigation from './navigation';
import calendar from './calendar'
export { export {
login, login,
navigation, navigation,
calendar,
}; };
import * as types from '../actions/actionTypes'; import * as types from '../actions/actionTypes';
import * as console from "react-native";
const initialState = { const initialState = {
loginState: '', loginState: '',
......
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