-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
220 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,94 @@ | ||
import React from "react"; | ||
interface PostInter{ | ||
content:{ | ||
imgOwner:string, | ||
img:string, | ||
owner:string, | ||
text:string, | ||
comments:string[], | ||
} | ||
import axios from "axios"; | ||
import { Link } from 'react-router-dom'; | ||
interface PostInter { | ||
content: { | ||
imgOwner: string; | ||
img: string; | ||
owner: string; | ||
text: string; | ||
idOwner: number; | ||
}; | ||
} | ||
|
||
interface info { | ||
num: number; | ||
} | ||
class Posts extends React.Component{ | ||
|
||
class Posts extends React.Component<info> { | ||
state = { | ||
posts: [], | ||
num: 5, | ||
}; | ||
|
||
componentDidMount() { | ||
let url: string = 'https://localhost:8000/post/home/'; | ||
axios | ||
.get(url) | ||
.then((response) => { | ||
const userData = response.data; | ||
console.log(userData.message); | ||
if (userData.message === 'No posts found for the owner.') { | ||
alert(userData.message); | ||
} else { | ||
this.setState({ | ||
posts: userData.map((post: { | ||
id: any; | ||
owner_username: any; | ||
owner_id: any; | ||
img: string; | ||
profile: string; | ||
text: any; | ||
}) => ({ | ||
id: post.id, | ||
owner: post.owner_username, | ||
idOwner: post.owner_id, | ||
img: 'https://localhost:8000/media/' + post.img, | ||
imgOwner: 'https://localhost:8000/media/' + post.profile, | ||
text: post.text, | ||
})), | ||
}); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); | ||
}); | ||
} | ||
|
||
render() { | ||
const posts = this.state.posts.map((post: any) => ( | ||
<Post key={post.id} content={post} /> | ||
)); | ||
|
||
const jsx = posts.slice(0, this.props.num); | ||
|
||
return ( | ||
<div className="left-grid" id='left_grid'> | ||
<Post content={{imgOwner:require('./img1.jpg'),img:require('./img1.jpg'),owner:'seyed',text:'this is a post',comments:['good','bad']}}/> | ||
<Post content={{imgOwner:require('./img1.jpg'),img:require('./img1.jpg'),owner:'seyed', text:'this is a post' ,comments:['good','bad']}}/> | ||
<Post content={{imgOwner:require('./img1.jpg'),img:require('./img1.jpg'),owner:'seyed',text:'this is a post',comments:['good','bad']}}/> | ||
<div className="left-grid" id="left_grid"> | ||
{jsx} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
class Post extends React.Component<PostInter>{ | ||
class Post extends React.Component<PostInter> { | ||
render() { | ||
console.log(this.props); | ||
return ( | ||
<div className="box"> | ||
<img className={'profile_img profile_post'} src={this.props.content.imgOwner} width='3%'/> | ||
<img className={'img_post'} src={this.props.content.img} width='40%'/> | ||
<header className={'name_post'}>{this.props.content.owner}</header> | ||
<p className={'name_post'}>{this.props.content.text}</p> | ||
<ul> | ||
{this.props.content.comments.map((item, index) => ( | ||
<li key={index}>{item}</li> | ||
))} | ||
</ul> | ||
<input type={'text'} placeholder={'post comment'}/> | ||
<div className="parent"> | ||
<img className="img_post" src={this.props.content.img} /> | ||
</div> | ||
|
||
<div className={'home_post_content'}> | ||
<h2 className="name_post" >{this.props.content.owner}</h2> | ||
<Link to={`/profile/${this.props.content.idOwner}`}> | ||
<img className="profile_img profile_post" src={this.props.content.imgOwner} /> | ||
</Link> | ||
</div> | ||
<p>Caption: <span className="content_post ">{this.props.content.text}</span></p> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Posts | ||
export default Posts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.