Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
.App {
text-align: center;
}

.row {
display: flex;
flex-wrap: wrap;
justify-content: center;
flex-direction: column;
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
}

.h2 {
display: flex;
flex-direction: row;
justify-content: space-around;
}
li {
display: flex;
flex-direction: row;
}
ul {
display: flex;
justify-content: center;
flex-direction: column;
}
.img {
width: 2rem;
height: 3rem;
margin: 0 6rem;
}
p {
margin: 0 3rem;
}
.App-header {
background-color: #282c34;
min-height: 100vh;
Expand Down
86 changes: 69 additions & 17 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,80 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import contacts from './data/contacts.json';
import List from './Components/List';
import Add from './Components/Add';
import ByName from './Components/ByName';
import ByPop from './Components/ByPop';


class App extends Component {
state = {
contacts: contacts.slice(0,5)
};

getRandomInt = (min, max) => {
return Math.floor(Math.random() * (max - min)) + min;
};

random = () => {
console.log("Click")
const contactRandom = this.getRandomInt(0,contacts.length);

this.setState({
contacts: [...this.state.contacts, contacts[contactRandom]],

});
};
SortName = () => {
this.setState({
contacts: this.state.contacts.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0)),
})
};

SortPop = () => {
this.setState({
contacts: this.state.contacts.sort((a,b) => (a.popularity < b.popularity) ? 1 : ((b.popularity < a.popularity) ? -1 : 0)),
})
};

deleteContact = (index) => {
this.state.contacts.splice(index, 1);
this.setState({
contacts: [...this.state.contacts],
})
}



render() {
const {contacts} = this.state;
return (
<>
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<h1>Iron Contacts</h1>
<Add button={this.random} />
<ByName button={this.SortName} />
<ByPop button={this.SortPop} />
<div className="h2">
<h2>Pic</h2>
<h2>Name</h2>
<h2>Pop</h2>
</div>
<ul>
{contacts.map((contact,index) => {
return ( <List
key={index}
index={index}
list={contact}
del={this.deleteContact}
/>
)
})};
</ul>
</div>
</>
);
}
}
};
};

export default App;
11 changes: 11 additions & 0 deletions src/Components/Add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { Component } from 'react';

class Add extends Component {

render(){
return(
<button onClick={this.props.button}>Add Random Contact</button>
)}

}
export default Add;
11 changes: 11 additions & 0 deletions src/Components/ByName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { Component } from 'react';

class ByName extends Component {

render(){
return(
<button onClick={this.props.button}>Sort By Name</button>
)}
}

export default ByName;
11 changes: 11 additions & 0 deletions src/Components/ByPop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { Component } from 'react';

class ByPop extends Component {

render(){
return(
<button onClick={this.props.button}>Sort By Popularity</button>
)}
}

export default ByPop;
24 changes: 24 additions & 0 deletions src/Components/List.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { Component } from 'react';

class List extends Component {

handleClick = () => {
this.props.del(this.props.index);
console.log(this.props.index)
}

render () {
return (
<div className="row">
<li>
<img src={this.props.list.pictureUrl} alt="Famous" className="img" ></img>
<p >{this.props.list.name}</p>
<p >{this.props.list.popularity}</p>
<button onClick={this.handleClick}>Delete</button>
</li>
</div>
);
}
}

export default List;
3 changes: 2 additions & 1 deletion src/data/contacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -994,4 +994,5 @@
"pictureUrl": "https://image.tmdb.org/t/p/w500/aqZ9RjL5j44HMlBMvTaawhHiGOH.jpg",
"popularity": 6.914606
}
]
]