From 9a34493d6102d226d70b733efbc2c8baef319395 Mon Sep 17 00:00:00 2001 From: aka4rKO Date: Wed, 8 May 2019 01:50:39 +0530 Subject: [PATCH] nasif did this work --- Nasif/goeve_final/src/Route.js | 3 +- .../src/components/InterestsCards.js | 22 +++++++++----- Nasif/goeve_final/src/components/Interets.js | 30 +++++++++++++++---- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/Nasif/goeve_final/src/Route.js b/Nasif/goeve_final/src/Route.js index 4e80d89..fbffe0f 100644 --- a/Nasif/goeve_final/src/Route.js +++ b/Nasif/goeve_final/src/Route.js @@ -17,6 +17,7 @@ import { LoginButton } from 'react-native-fbsdk'; import Home from './components/Home'; import Interets from './components/Interets' +import InterestsCards from './components/InterestsCards' import Login from './components/Login'; const { width: widthDim } = Dimensions.get('window'); @@ -108,7 +109,7 @@ const HomeStack = createStackNavigator({ const InterestsStack = createStackNavigator({ Interets: { - screen: Interets, + screen: InterestsCards, navigationOptions: ({ navigation }) => ({ headerStyle: { backgroundColor: '#FB6600' }, headerTitleStyle: { diff --git a/Nasif/goeve_final/src/components/InterestsCards.js b/Nasif/goeve_final/src/components/InterestsCards.js index ca48c3b..14eabc0 100644 --- a/Nasif/goeve_final/src/components/InterestsCards.js +++ b/Nasif/goeve_final/src/components/InterestsCards.js @@ -27,18 +27,24 @@ export default class App extends Component { this.handleChange = this.handleChange.bind(this); } + componentDidMount() { + fetch(`http://35.186.155.252:4000/categories/`) + .then(res => res.json()) + .then(json => this.setState({ data: json.categories })); + } + handleChange = (key,checked) => { console.log("Key "+key+" Checked "+checked) const newArray = [...this.state.data]; newArray[key].status = checked; this.setState({data:newArray}) console.log("Length "+this.state.data.length) - this.state.data.map((item,key)=>{console.log(item.name+" "+item.status)}) + this.state.data.map((item,key)=>{console.log(item.category+" "+item.status)}) } - componentWillMount (){ + /* componentWillMount (){ this.setState({data:this.props.data}) - } + } */ renderItem = ({ item, index }) => { if (item.empty === true) { return ( @@ -48,10 +54,10 @@ export default class App extends Component { cornerRadius={0} style={styles.itemInvisible} > - + - {item.name} + {item.category} ); } @@ -62,7 +68,7 @@ export default class App extends Component { cornerRadius={8} style={styles.card} > - + - {item.name} + {item.category} ); @@ -148,7 +154,7 @@ const styles = StyleSheet.create({ height: 110 }, text: { - color: "#000", + color: "#fff", textAlign: 'center', textAlignVertical: "center", marginTop: 17, diff --git a/Nasif/goeve_final/src/components/Interets.js b/Nasif/goeve_final/src/components/Interets.js index 6276736..40713f8 100644 --- a/Nasif/goeve_final/src/components/Interets.js +++ b/Nasif/goeve_final/src/components/Interets.js @@ -9,15 +9,35 @@ export default class Interests extends Component { super(); this.state = { data: [] }; } - componentDidMount() { + + /* componentWillMount() { + this.fetchData(); + } + + fetchData = async () => { + const res = await fetch(`http://35.186.155.252:4000/categories/`); + const json = await res.json(); + this.setState({ data: json.categories }); + } */ + + /* componentDidMount() { fetch(`http://35.186.155.252:4000/categories/`) .then(res => res.json()) - .then(json => this.setState({ data: json })); - } + .then(json => this.setState({ data: json.categories })); + } */ render() { + console.log(this.state.data); - + /* let events = []; + const eventType = this.state.datacomponentDidMount() { + fetch(`http://35.186.155.252:4000/categories/`) + .then(res => res.json()) + .then(json => this.setState({ data: json.categories })); + }.categories; + eventType.forEach(element => { + events.push(element); + }); */ const eventType = [ { key: 1, @@ -55,7 +75,7 @@ export default class Interests extends Component { ] return ( - + ); } }