Commit c7ec2c96 authored by Gijs Hendriksen's avatar Gijs Hendriksen Committed by Wietse Kuipers
Browse files

Adjusted to different API functionality for retrieving first five events

parent 3b470946
......@@ -45,36 +45,6 @@ export function logoutSuccess() {
};
}
export function welcome(eventList) {
return {
type: types.WELCOME,
eventList,
};
}
export function retrieveShortlist(token) {
return (dispatch) => {
const data = {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Token ${token}`,
},
};
return fetch(`${url}/api/events/shortlist/`, data)
.then(
response => response.json(),
)
.then(
responseJson => dispatch(welcome(responseJson)),
)
.catch(
() => dispatch(welcome([])),
);
};
}
function getUserInfo(token) {
const data = {
......
import { url } from '../url';
import * as types from './actionTypes';
export function welcome(eventList) {
return {
type: types.WELCOME,
eventList,
};
}
export function retrieveShortlist(token, amount) {
return (dispatch) => {
const data = {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Token ${token}`,
},
};
return fetch(`${url}/api/events/?limit=${amount}&ordering=start`, data)
.then(
response => response.json(),
)
.then(
responseJson => dispatch(welcome(responseJson.results)),
)
.catch(
() => dispatch(welcome([])),
);
};
}
......@@ -5,22 +5,42 @@ import Moment from 'moment';
import 'moment/locale/nl';
import EventDetailCard from './EventDetailCard';
import { retrieveShortlist } from '../actions/login';
import { retrieveShortlist } from '../actions/welcome';
import { navigate } from '../actions/navigation';
import styles from './style/welcome';
const eventListToSections = (eventLists) => {
const eventListToSections = (eventList) => {
Moment.locale('nl');
return eventLists.map(eventList => ({
key: Moment(eventList[0].start).calendar(null, {
sameDay: '[Vandaag]',
nextDay: '[Morgen]',
nextWeek: 'dddd D MMMM',
lastDay: '[Gisteren]',
lastWeek: 'dddd D MMMM',
sameElse: 'dddd D MMMM',
}),
data: eventList,
const calendarFormat = {
sameDay: '[Vandaag]',
nextDay: '[Morgen]',
nextWeek: 'dddd D MMMM',
lastDay: '[Gisteren]',
lastWeek: 'dddd D MMMM',
sameElse: 'dddd D MMMM',
};
const numberOfDays = 2;
const eventLists = [];
let eventIndex = 0;
for (let i = 0; i < numberOfDays && eventIndex < eventList.length; i += 1) {
const first = eventList[eventIndex];
eventIndex += 1;
const list = [];
let next = first;
while (Moment(first.start).isSame(next.start) && eventIndex < eventList.length) {
list.push(next);
next = eventList[eventIndex];
eventIndex += 1;
}
eventLists.push(list);
}
return eventLists.map(list => ({
key: Moment(list[0].start).calendar(null, calendarFormat),
data: list,
}));
};
......@@ -57,7 +77,7 @@ class Welcome extends Component {
handleRefresh = () => {
this.setState({ refreshing: true });
this.props.retrieveShortlist(this.props.token)
this.props.retrieveShortlist(this.props.token, 5)
.then(() => this.setState({ refreshing: false }));
};
......@@ -92,7 +112,7 @@ class Welcome extends Component {
}
Welcome.propTypes = {
eventList: React.PropTypes.arrayOf(React.PropTypes.arrayOf(React.PropTypes.shape({
eventList: React.PropTypes.arrayOf(React.PropTypes.shape({
title: React.PropTypes.string,
description: React.PropTypes.string,
start: React.PropTypes.string,
......@@ -102,7 +122,7 @@ Welcome.propTypes = {
pk: React.PropTypes.number,
registered: React.PropTypes.bool,
pizza: React.PropTypes.bool,
}))).isRequired,
})).isRequired,
token: React.PropTypes.string.isRequired,
retrieveShortlist: React.PropTypes.func.isRequired,
};
......@@ -113,7 +133,7 @@ const mapStateToProps = state => ({
});
const mapDispatchToProps = dispatch => ({
retrieveShortlist: token => dispatch(retrieveShortlist(token)),
retrieveShortlist: (token, amount) => dispatch(retrieveShortlist(token, amount)),
});
export default connect(mapStateToProps, mapDispatchToProps)(Welcome);
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