2016-10-25 14:47:49 +00:00
|
|
|
import React from 'react';
|
|
|
|
import '../css/TaskList.scss';
|
2016-10-27 16:26:15 +00:00
|
|
|
import TaskListItem from './TaskListItem';
|
2016-10-25 14:47:49 +00:00
|
|
|
|
|
|
|
class TaskList extends React.Component {
|
|
|
|
constructor(){
|
|
|
|
super();
|
2016-10-26 21:35:31 +00:00
|
|
|
|
|
|
|
this.state = {
|
2016-10-27 16:26:15 +00:00
|
|
|
tasks: [],
|
|
|
|
error: "",
|
|
|
|
loading: true
|
2016-10-26 21:35:31 +00:00
|
|
|
};
|
2016-10-27 16:26:15 +00:00
|
|
|
|
|
|
|
this.refresh = this.refresh.bind(this);
|
2016-10-25 14:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount(){
|
2016-10-26 21:35:31 +00:00
|
|
|
this.loadTaskList();
|
2016-10-25 14:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh(){
|
2016-10-26 21:35:31 +00:00
|
|
|
this.loadTaskList();
|
|
|
|
}
|
|
|
|
|
|
|
|
loadTaskList(){
|
|
|
|
this.taskListRequest =
|
|
|
|
$.getJSON(this.props.source, json => {
|
2016-10-27 16:26:15 +00:00
|
|
|
this.setState({
|
|
|
|
tasks: json
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.fail((jqXHR, textStatus, errorThrown) => {
|
|
|
|
this.setState({
|
|
|
|
error: `Could not load projects list: ${textStatus}`,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.always(() => {
|
|
|
|
this.setState({
|
|
|
|
loading: false
|
|
|
|
})
|
|
|
|
});
|
2016-10-26 21:35:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount(){
|
|
|
|
this.taskListRequest.abort();
|
2016-10-25 14:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="task-list">
|
2016-10-27 16:26:15 +00:00
|
|
|
{this.state.loading ?
|
|
|
|
<span>Loading... <i className="fa fa-refresh fa-spin fa-fw"></i></span>
|
|
|
|
: ""}
|
|
|
|
{this.state.error ?
|
|
|
|
<span>Could not get tasks: {this.state.error}. <a href="javascript:void(0);" onClick={this.refresh}>Try again</a></span>
|
|
|
|
: ""}
|
|
|
|
|
|
|
|
{this.state.tasks.map(task => (
|
|
|
|
<TaskListItem data={task} key={task.id} />
|
|
|
|
))}
|
2016-10-25 14:47:49 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TaskList;
|