OpenDroneMap-WebODM/app/static/app/js/components/ProjectList.jsx

76 wiersze
2.1 KiB
React
Czysty Zwykły widok Historia

import React from 'react';
import $ from 'jquery';
import ProjectListItem from './ProjectListItem';
class ProjectList extends React.Component {
constructor(){
super();
this.state = {
loading: true,
error: "",
projects: null
}
2016-11-15 16:51:19 +00:00
this.handleDelete = this.handleDelete.bind(this);
}
componentDidMount(){
this.refresh();
}
refresh(){
// Load projects from API
this.serverRequest =
$.getJSON(this.props.source, json => {
if (json.results){
this.setState({
projects: json.results,
loading: false
});
}else{
this.setState({
error: `Invalid JSON response: ${JSON.stringify(json)}`,
loading: false
});
}
})
.fail((jqXHR, textStatus, errorThrown) => {
this.setState({
error: `Could not load projects list: ${textStatus}`,
loading: false
});
});
}
componentWillUnmount(){
this.serverRequest.abort();
}
2016-11-15 16:51:19 +00:00
handleDelete(projectId){
let projects = this.state.projects.filter(p => p.id !== projectId);
this.setState({projects: projects});
}
render() {
if (this.state.loading){
return (<div>Loading projects... <i className="fa fa-refresh fa-spin fa-fw"></i></div>);
}
else if (this.state.projects){
2016-10-11 20:37:00 +00:00
return (<ul className="list-group">
{this.state.projects.map(p => (
2016-11-15 16:51:19 +00:00
<ProjectListItem key={p.id} data={p} onDelete={this.handleDelete} />
))}
2016-10-11 20:37:00 +00:00
</ul>);
}else if (this.state.error){
return (<div>An error occurred: {this.state.error}</div>);
}else{
return (<div></div>); // should never happen
}
}
}
export default ProjectList;