Commit 8d3ea9b8 authored by Martin Wighus Holtmon's avatar Martin Wighus Holtmon
Browse files

projectPart2/Problem1: Fixed issue where main component did not update when...

projectPart2/Problem1: Fixed issue where main component did not update when clicking through the user list.
parent 6ecb0afe
......@@ -17,6 +17,11 @@ class UserDetail extends React.Component {
this.state = {userDetails: PROG2053Models.userModel(this.props.match.params.userId)};
}
componentDidUpdate(prevProps) {
if (this.props.match.params.userId !== prevProps.match.params.userId) {
this.setState({userDetails: PROG2053Models.userModel(this.props.match.params.userId)});
}
}
generateUserPreview = () => {
const user = this.state.userDetails;
......
......@@ -15,6 +15,12 @@ class UserPhotos extends React.Component {
this.state = {userPhotos: PROG2053Models.photoOfUserModel(this.props.match.params.userId)};
}
componentDidUpdate(prevProps) {
if (this.props.match.params.userId !== prevProps.match.params.userId) {
this.setState({userPhotos: PROG2053Models.photoOfUserModel(this.props.match.params.userId)});
}
}
getAuthor = (user) => {
if (user) {
return <Link to={`/photo-share/users/${user._id}`}>{user.first_name} {user.last_name}</Link>;
......
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