Commit f3d5ebcd authored by Gijs Hendriksen's avatar Gijs Hendriksen
Browse files

Merge branch 'feature/new-api-urls' into 'master'

Change event API urls

See merge request !15
parents 0ee91cf1 b77c5a56
...@@ -16,10 +16,6 @@ export function calendarNotRetrieved() { ...@@ -16,10 +16,6 @@ export function calendarNotRetrieved() {
export function retrieveCalendar(token) { export function retrieveCalendar(token) {
return (dispatch) => { return (dispatch) => {
const start = new Date().toISOString().substring(0, 10);
let end = new Date();
end.setMonth(end.getMonth() + 6);
end = end.toISOString().substring(0, 10);
const data = { const data = {
method: 'GET', method: 'GET',
headers: { headers: {
...@@ -28,13 +24,11 @@ export function retrieveCalendar(token) { ...@@ -28,13 +24,11 @@ export function retrieveCalendar(token) {
Authorization: `Token ${token}`, Authorization: `Token ${token}`,
}, },
}; };
return fetch(`${url}/api/events/eventlist/?start=${start}&end=${end}`, data) return fetch(`${url}/api/events/`, data)
.then( .then(
response => response.json()) response => response.json())
.then( .then(
responseJson => dispatch(calendarRetrieved(responseJson))) responseJson => dispatch(calendarRetrieved(responseJson)))
.catch(() => { .catch(() => dispatch(calendarNotRetrieved()));
dispatch(calendarNotRetrieved());
});
}; };
} }
...@@ -25,7 +25,7 @@ export function loadEvent(id, token) { ...@@ -25,7 +25,7 @@ export function loadEvent(id, token) {
Authorization: `Token ${token}`, Authorization: `Token ${token}`,
}, },
}; };
return fetch(`${url}/api/events/data/?event_id=${id}`, data) return fetch(`${url}/api/events/${id}/`, data)
.then( .then(
response => response.json(), response => response.json(),
) )
......
...@@ -45,7 +45,7 @@ function getUserInfo(token) { ...@@ -45,7 +45,7 @@ function getUserInfo(token) {
}, },
}; };
return fetch(`${url}/api/members/info/`, data) return fetch(`${url}/api/members/me/`, data)
.then( .then(
response => response.json()) response => response.json())
.then( .then(
......
...@@ -16,16 +16,12 @@ const Calendar = (props) => { ...@@ -16,16 +16,12 @@ const Calendar = (props) => {
); );
} }
const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }); const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
const events = []; const dataSource = ds.cloneWithRows(props.eventList);
for (let i = 0; i < props.eventList.length; i += 1) {
events.push(<EventCard event={props.eventList[i]} />);
}
const dataSource = ds.cloneWithRows(events);
return ( return (
<View> <View>
<ListView <ListView
dataSource={dataSource} dataSource={dataSource}
renderRow={rowData => rowData} renderRow={rowData => <EventCard event={rowData} />}
enableEmptySections enableEmptySections
/> />
</View> </View>
...@@ -34,12 +30,12 @@ const Calendar = (props) => { ...@@ -34,12 +30,12 @@ const Calendar = (props) => {
Calendar.propTypes = { Calendar.propTypes = {
eventList: React.PropTypes.arrayOf(React.PropTypes.shape({ eventList: React.PropTypes.arrayOf(React.PropTypes.shape({
pk: React.PropTypes.number,
title: React.PropTypes.string, title: React.PropTypes.string,
description: React.PropTypes.string, description: React.PropTypes.string,
start: React.PropTypes.string, start: React.PropTypes.string,
location: React.PropTypes.string, location: React.PropTypes.string,
price: React.PropTypes.string, price: React.PropTypes.string,
id: React.PropTypes.number,
})).isRequired, })).isRequired,
calendarFetched: React.PropTypes.bool.isRequired, calendarFetched: React.PropTypes.bool.isRequired,
retrieveCalendar: React.PropTypes.func.isRequired, retrieveCalendar: React.PropTypes.func.isRequired,
......
...@@ -2,11 +2,13 @@ import React from 'react'; ...@@ -2,11 +2,13 @@ import React from 'react';
import { View, Text } from 'react-native'; import { View, Text } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import styles from './style/event';
const Event = (props) => { const Event = (props) => {
if (props.success) { if (props.success) {
return ( return (
<View> <View>
<Text><h1>{props.data.title}</h1></Text> <Text style={styles.titleText}>{props.data.title}</Text>
<Text>{props.data.description}</Text> <Text>{props.data.description}</Text>
<Text>Locatie: {props.data.location}</Text> <Text>Locatie: {props.data.location}</Text>
<Text>Prijs: {props.data.price}</Text> <Text>Prijs: {props.data.price}</Text>
......
...@@ -3,15 +3,20 @@ import { View, Text, Button } from 'react-native'; ...@@ -3,15 +3,20 @@ import { View, Text, Button } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import * as actions from '../actions/events'; import * as actions from '../actions/events';
const EventCard = props => import styles from './style/eventCard';
<View>
<Text> <b>{props.event.title}</b> </Text> const EventCard = (props) => {
<Text> {new Date(props.event.start).toISOString().substring(0, 10)}</Text> const date = new Date(props.event.start).toISOString().substring(0, 10);
<i>{props.event.description}</i> return (
<Text>-----------------------------------------</Text> <View>
<Button title="Openen" onPress={() => props.loadEvent(props.event.id, props.token)} /> <Text style={styles.boldText}>{props.event.title}</Text>
</View> <Text>{date}</Text>
; <Text style={styles.italicText}>{props.event.description}</Text>
<Text>-----------------------------------------</Text>
<Button title="Openen" onPress={() => props.loadEvent(props.event.pk, props.token)} />
</View>
);
};
EventCard.propTypes = { EventCard.propTypes = {
event: React.PropTypes.shape({ event: React.PropTypes.shape({
...@@ -20,7 +25,7 @@ EventCard.propTypes = { ...@@ -20,7 +25,7 @@ EventCard.propTypes = {
start: React.PropTypes.string, start: React.PropTypes.string,
location: React.PropTypes.string, location: React.PropTypes.string,
price: React.PropTypes.string, price: React.PropTypes.string,
id: React.PropTypes.number, pk: React.PropTypes.number,
}).isRequired, }).isRequired,
loadEvent: React.PropTypes.func.isRequired, loadEvent: React.PropTypes.func.isRequired,
token: React.PropTypes.string.isRequired, token: React.PropTypes.string.isRequired,
...@@ -31,7 +36,7 @@ const mapStateToProps = state => ({ ...@@ -31,7 +36,7 @@ const mapStateToProps = state => ({
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
loadEvent: (id, token) => dispatch(actions.loadEvent(id, token)), loadEvent: (pk, token) => dispatch(actions.loadEvent(pk, token)),
}); });
export default connect(mapStateToProps, mapDispatchToProps)(EventCard); export default connect(mapStateToProps, mapDispatchToProps)(EventCard);
import { StyleSheet } from 'react-native';
import { colors } from '../../style';
const styles = StyleSheet.create({
titleText: {
fontSize: 24,
fontWeight: 'bold',
color: colors.darkMagenta,
},
});
export default styles;
import { StyleSheet } from 'react-native';
const styles = StyleSheet.create({
italicText: {
fontStyle: 'italic',
},
boldText: {
fontWeight: 'bold',
},
});
export default styles;
Supports Markdown
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