Skip to content

Commit

Permalink
home page in ready
Browse files Browse the repository at this point in the history
  • Loading branch information
seyed0123 committed Aug 22, 2023
1 parent 50a9e52 commit b65b339
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 71 deletions.
10 changes: 5 additions & 5 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import axios from 'axios';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import Home from "./home/home";
import profile from "./profile/profile";
import Profile from "./profile/profile";
import Setting from "./setting/setting";
import SignIn from "./Sing/Signin";
import Create from "./Sing/create";
Expand Down Expand Up @@ -39,11 +39,11 @@ class App extends React.Component {
<Route render={(props) => <SignIn {...props} />}/>
</Router>:
<Router>
<Route path="/" exact component={Home} />
<Route path="/profile/:id" component={profile} />
<Route path="/setting" component={Setting}/>
<Route path="/" exact render={(props) => <Home {...props} id={this.state.id}/> }/>
<Route path="/profile/:id" render={(props) => <Profile {...props} />}/>
<Route path="/setting" render={(props) => <Setting {...props} id={this.state.id} />}/>
<Route path="/login" render={(props) => <SignIn {...props} />}/>
<Route path="/create" component={Create}/>
<Route path="/create" render={(props) => <Create {...props} />}/>
</Router>

);
Expand Down
20 changes: 18 additions & 2 deletions client/src/home/header.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react';
import img from './img1.jpg'
import { Link } from 'react-router-dom';
interface headerProps{
content:{
path:string;
username:string;
id:number;
};
}
class Header extends React.Component<headerProps>{
Expand All @@ -12,8 +15,21 @@ class Header extends React.Component<headerProps>{
<header>
<div id='header'>
<input className={'input'} type={'text'} placeholder={'username'}/>
<button type={'submit'} className={'buttons'}>search</button>
<img src={this.props.content.path} className={'img-rounded profile_img'} width='7%' alt={'profile'}/>
<button type={'submit'} className={'buttons'}>search</button>
<Link to={`/profile/${this.props.content.id}`}>
<img src={this.props.content.path} className={'img-rounded profile_img'} width='7%' alt={'profile'}/>
</Link>

<h6><Link to={'/setting'}>
<svg xmlns="https://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" className="feather feather-settings">
<circle cx="12" cy="12" r="3"></circle>
<path
d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path>
</svg>
</Link> login as: {this.props.content.username}</h6>

</div>
</header>
);
Expand Down
59 changes: 41 additions & 18 deletions client/src/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,57 @@ import Header from "./header";
import Recom from "./recom";
import Posts from "./post";

interface Props extends RouteComponentProps {}
interface Props extends RouteComponentProps {
id:number
}
class Home extends React.Component<Props>
{
state:{data:{hello:string}}={
data:{hello:'seyed'}
state={
username :'',
profile:'',
loading:true,
num:5,
id:0,
text:'Recommendation'
}

constructor(props:Props) {
super(props);
this.load = this.load.bind(this)
}

componentDidMount() {
let url :string= 'https://localhost:8000/person/setting/'+this.props.id+'/'
axios.get(url)
.then(response => {
const userData = response.data;
this.setState({
id:userData.id,
username: userData.username,
profile: 'https://localhost:8000/media/'+userData.profile_img,
loading :false
});
})
.catch(error => {
console.error('Error:', error);
});
}
load(){
this.setState((prevState:{num:number}) => ({
num: prevState.num + 5
}))
}

handleProfileButtonClick = () => {
this.props.history.push('/profile');
};
// componentDidMount() {
// axios.get('https://localhost:8000/api/hello')
// .then((response: { data: any; }) => {
// this.setState({
// data: response.data
// });
// });
// }
render(){
return(
<div>
<Header content={{path:require('./img1.jpg')}} />
<Header content={{path:this.state.profile ,username:this.state.username , id:this.state.id}} />
<div className='container_body'>
<Recom/>
<Posts/>
<Recom id={this.state.id} text={this.state.text}/>
<Posts num={this.state.num}/>
</div>
<div style={{justifyContent:'center' , display:'flex'}}>
<button type={'submit'}>Load more</button>
<button className={'profile_follow'} onClick={this.load}>Load more</button>
</div>
</div>
)
Expand Down
102 changes: 77 additions & 25 deletions client/src/home/post.tsx
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;
18 changes: 14 additions & 4 deletions client/src/home/recom.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import React from "react";
import axios from "axios";
interface person{
content:{
img:string
username:string
id_user:number
id:number
}
}
class Recom extends React.Component{

interface info {
id:number;
text:string
}
class Recom extends React.Component<info>{
constructor(props:any) {
super(props);

}
render() {
return (
<div className='right-grid' id='right_grid'>
<h2>Recommendations</h2>
<Person content={{img:require('./img1.jpg'),username:'seyed'}}/>
<Person content={{img:require('./img1.jpg'),username:'seyed'}}/>
<h2>{this.props.text}</h2>
</div>
);
}
Expand Down
38 changes: 32 additions & 6 deletions client/src/index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@import url('https://fonts.googleapis.com/css?family=Dosis');
@import url('https://fonts.googleapis.com/css?family=Monoton');
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@300&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inconsolata:wght@700&display=swap');

body{
background-color: #264653;
Expand All @@ -9,6 +11,7 @@ body{
color: #F4A261;
color: #E76F51;
color: black;
font-family: 'Inconsolata', monospace;

}

Expand Down Expand Up @@ -36,6 +39,21 @@ body{
.profile_img:hover{
transform: scale(1.1);
}
.img-rounded{
position: absolute;
right : 20px;
width: 10%;
}
.parent {
display: flex;
justify-content: center;
align-items: center;
}

.img_post {
width: 80%;
}

.buttons{
align-items: center;
appearance: none;
Expand Down Expand Up @@ -107,19 +125,27 @@ body{
position: relative;
}
.profile_post{
position: absolute;
top: 1%;
right: 1%;
width: 5%;

width: 10%;
z-index: 1;
}
.name_post{
font-size: xx-large;
font-weight: bold;
font-family: Broadway, serif;
text-shadow: 0 0 5px white;

z-index: 1;
}
.home_post_content{
display: flex;
justify-content: left;
gap: 5%;
}
.content_post{

font-family: 'Raleway', sans-serif;
z-index: 1;

}
.img_fullscreen {
width: 100%;
height: 100vh;
Expand Down
Loading

0 comments on commit b65b339

Please sign in to comment.