Grab user data from web server

This commit is contained in:
2018-02-03 17:20:58 -07:00
parent 3b5509000d
commit a1c80c70cb
4 changed files with 43 additions and 25 deletions

View File

@@ -10,18 +10,23 @@ class App extends Component {
super();
this.state = {
user: null,
toolData: null,
};
}
componentDidMount() {
fetch('http://localhost:8080/api/client')
fetch('http://localhost:8080/api/tooldata')
.then(response => response.json())
.then(data => this.setState({ toolData: data }));
fetch('http://localhost:8080/api/user')
.then(response => response.json())
.then(data => this.setState({ user: data }));
}
render() {
const toolData = this.state.toolData;
const user = this.state.user;
return (
<div>
@@ -41,18 +46,18 @@ class App extends Component {
<div style={{height: '70px', display: 'inline-block'}} />
{toolData ?
{toolData && user ?
<div>
<Route exact path='/' render={props =>
<Categories {...props} data={toolData} />
<Categories {...props} data={toolData} user={user} />
} />
<Route exact path='/:category' render={props =>
<Category {...props} data={toolData} />
<Category {...props} data={toolData} user={user} />
} />
<Route exact path='/:category/:id' render={props =>
<Tool {...props} data={toolData} />
<Tool {...props} data={toolData} user={user} />
} />
</div>
:

View File

@@ -5,11 +5,11 @@ import { Link } from 'react-router-dom';
class Category extends Component {
render() {
const data = this.props.data;
const user = data.user;
const user = this.props.user;
const match = this.props.match;
const category = data.categories.find((x) =>
x.slug == match.params.category
x.slug === match.params.category
);
return (

View File

@@ -5,15 +5,15 @@ import { Link } from 'react-router-dom';
class Tool extends Component {
render() {
const data = this.props.data;
const user = data.user;
const user = this.props.user;
const match = this.props.match;
const category = data.categories.find((x) =>
x.slug == match.params.category
x.slug === match.params.category
);
const tool = category.tools.find((x) =>
x.id == match.params.id
x.id.toString() === match.params.id
);
const approved = user.authorizedTools.includes(tool.id);