diff --git a/projectSecondPart/src/photo-share/pages/user-detail/UserDetail.jsx b/projectSecondPart/src/photo-share/pages/user-detail/UserDetail.jsx index 90db280342528bf538c1a42251a0625ec967614c..31659dbfb286bf29bda78215420025d9af8a0a5d 100644 --- a/projectSecondPart/src/photo-share/pages/user-detail/UserDetail.jsx +++ b/projectSecondPart/src/photo-share/pages/user-detail/UserDetail.jsx @@ -12,8 +12,14 @@ import PROG2053Models from '../../../model-data/PhotoApp'; * Define UserDetail, a React componment of PROG2053 part #2 */ class UserDetail extends React.Component { + constructor(props) { + super(props); + this.state = {userDetails: PROG2053Models.userModel(this.props.match.params.userId)}; + } + + generateUserPreview = () => { - const user = PROG2053Models.userModel(this.props.match.params.userId); + const user = this.state.userDetails; return ( <> <Typography variant="h3"> @@ -29,7 +35,6 @@ class UserDetail extends React.Component { }; render() { - //to={`/photo-share/photos/${this.props.match.params.userId} return ( <> {this.generateUserPreview()} diff --git a/projectSecondPart/src/photo-share/pages/user-list/UserList.jsx b/projectSecondPart/src/photo-share/pages/user-list/UserList.jsx index 691ef24c74dd4861230f7b0e8333a630566ebe05..e73759c239bba4341543a7f844c0613e519128ba 100644 --- a/projectSecondPart/src/photo-share/pages/user-list/UserList.jsx +++ b/projectSecondPart/src/photo-share/pages/user-list/UserList.jsx @@ -13,9 +13,14 @@ import {Link} from 'react-router-dom'; * Define UserList, a React componment of PROG2053 part #2 */ class UserList extends React.Component { + constructor(props) { + super(props); + this.state = {userModel: PROG2053Models.userListModel()}; + } + displayUsers = () => { const users = []; - PROG2053Models.userListModel().forEach((e) => { + this.state.userModel.forEach((e) => { users.push(( <ListItem key={e._id} button component={Link} to={`/photo-share/users/${e._id}`}> <ListItemText primary={`${e.first_name} ${e.last_name}`}/> diff --git a/projectSecondPart/src/photo-share/pages/user-photos/UserPhotos.jsx b/projectSecondPart/src/photo-share/pages/user-photos/UserPhotos.jsx index 95f202598c50f4196344a0b42a34ff49b57dc197..265fb07d9bf7482744dd597f1ba9426cd4718760 100644 --- a/projectSecondPart/src/photo-share/pages/user-photos/UserPhotos.jsx +++ b/projectSecondPart/src/photo-share/pages/user-photos/UserPhotos.jsx @@ -10,6 +10,11 @@ import {Link} from 'react-router-dom'; * Define UserPhotos, a React componment of PROG2053 part #2 */ class UserPhotos extends React.Component { + constructor(props) { + super(props); + this.state = {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>; @@ -37,10 +42,9 @@ class UserPhotos extends React.Component { }; render() { - //PROG2053Models.photoOfUserModel(this.props.match.params.userId) return ( <div id="divImageList"> - {PROG2053Models.photoOfUserModel(this.props.match.params.userId).map((image) => ( + {this.state.userPhotos.map((image) => ( // eslint-disable-next-line react/jsx-key <div className="divImageItem" key={image._id}> <div className="divImage">