From 40cac5ff6c3bbc7235c668bfb7648561d0b60e31 Mon Sep 17 00:00:00 2001 From: Roberta Conrad Date: Tue, 3 Jul 2018 16:10:05 +0200 Subject: [PATCH] done Jana & Roberta --- .../starter-code/src/index.js | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/labs/lab-react-ironcontacts/starter-code/src/index.js b/labs/lab-react-ironcontacts/starter-code/src/index.js index 8770e8e..f3d6e8b 100644 --- a/labs/lab-react-ironcontacts/starter-code/src/index.js +++ b/labs/lab-react-ironcontacts/starter-code/src/index.js @@ -2,16 +2,90 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; +import contacts from "./contacts.json"; + class App extends React.Component { constructor(props) { super(props); + this.state = { + contacts : contacts, + subContacts : contacts.slice(0,5) + } + } + + handleClick(){ + let newSubContacts = this.state.subContacts.slice(); + newSubContacts.push(contacts[Math.floor(Math.random()*(contacts.length-1))]); + this.setState({ + subContacts : newSubContacts + }) + } + + sortName(){ + let sortedContacts = this.state.subContacts.slice() + sortedContacts.sort(function(a,b) {return (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0);} ); + console.log(sortedContacts) + this.setState({ + subContacts : sortedContacts + }) + } + + sortPopularity(){ + let sortedPopContacts = this.state.subContacts.slice() + sortedPopContacts.sort(function(b,a) {return (a.popularity > b.popularity) ? 1 : ((b.popularity> a.popularity) ? -1 : 0);} ); + console.log(sortedPopContacts) + this.setState({ + subContacts : sortedPopContacts + }) + } + + deleteContact(i){ + let reducedContacts = this.state.subContacts.slice() + // console.log() + reducedContacts.splice(i,1) //change 0 to the key value of the button // or table element + this.setState({ + subContacts : reducedContacts + }) } render() { return (

IronContacts

+ + + + + + + + + + + + + + + + + + + {/* für jeden actor fügen wir picture name popularity ein */} + {this.state.subContacts.map((actor,i)=> + + + + + + + + )} + + +
PictureNamePopularityAction
{actor.name}{actor.popularity.toFixed(2)}
+ +
); }