As the topic says, I have a list of Projects being pulled from an external API (Teamwork). I have my app working to display all projects (endpoint of just /projects.json).
Here’s the code that is listing those Projects out (much of this taken from Meteor Chef’s site and examples):
/****
Start
****/
import React from ‘react’;
import { Link } from ‘react-router’;
import { ListGroupItem, Button, Alert, Table } from ‘react-bootstrap’;
import { browserHistory } from ‘react-router’;
const handleNav = _id => browserHistory.push(/projects/${_id}
);
const renderProjects = (projects) => (
projects.length > 0 ?
ID | Name | Project Manager | { project.id } |
<ListGroupItem key={ project.id } onClick={ () => handleNav(project.id) }> { project.name } |
{ project.category.name } |
---|
);
export class Projects extends React.Component {
render() {
const { projects } = this.props;
return <div>
<h4 className='page-header'>Projects</h4>
{ renderProjects(projects) }
</div>
}
}
Projects.propTypes = {
projects: React.PropTypes.array,
}
/****
End
****/
Basically, when you click on one of the projects, it routes correctly to /projects/<project.id> but I am unsure how to pass that project.id to my meteor method to then query the api to get the results of that endpoint. Here’s the URL structure for querying a single Project: ‘/projects/(project.id).json’
Here’s the method:
/***
Start
/
getProject() {
return callService(
‘GET’,
‘https://ironpaper.teamwork.com/projects/(project.id).json’,
apiUrl,
{
// auth removed for security
}
).then((result) => result).catch((error) => {
throw new Meteor.Error(‘500’, ${error.message}
);
});
}
/*
End
****/
And here’s the method call:
/****
Start
****/
import { Project } from ‘…/…/pages/Project.js’;
import { Loading } from ‘…/…/components/Loading.js’;
import { Meteor } from ‘meteor/meteor’;
import { Bert } from ‘meteor/themeteorchef:bert’;
import composeWithTracker from ‘…/…/…/api/compose-with-tracker.js’;
const composer = (params, onData) => {
Meteor.call(‘getProject’, (error, response) => {
if (error) {
Bert.alert(error.reason, ‘danger’);
} else {
onData(null, {project: response.data.project});
var projectId = response.data.project.id;
}
});
};
export default composeWithTracker(composer, Loading)(Project);
/****
End
****/
When hardcoding a project ID into the method, it works…but I need to know how to pass the ID from the view into the method so that the correct URL is built to return that single project.
Any ideas?