import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View, Button, TextInput, ScrollView, Picker, Alert, FlatList, TouchableOpacity, ActivityIndicator, Image, RefreshControl, SwipeView } from 'react-native'; import { createAppContainer, createStackNavigator, StackActions, NavigationActions } from 'react-navigation'; import Icon from 'react-native-ionicons'; import PushNotification from 'react-native-push-notification'; import PushController from './PushController.js'; export default class ProfileScreen extends React.Component { constructor(props) { super(props) this.state = { data: 'My Original Text', loading: false, dataSource: [], isFetching: false, text: '', }; } componentWillMount(){ fetch('http://compsci02.snc.edu/cs460/2019/khoral/mysql/get_encouragement_user.php', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ name: this.state.data }) }).then((response) => response.json()) .then((responseJson) => { this.setState({data: responseJson}) }).catch((error) => { console.error(error); });} addQuote(){ if (this.state.text == '') { Alert.alert( 'Please type in a quote.', [ { text: 'OK', onPress: () => this.refs.QuoteInput.focus() }, ], {cancelable: false}, ); } else{ const { navigation } = this.props; const user = navigation.getParam('user', 'test'); fetch('http://compsci02.snc.edu/cs460/2019/khoral/mysql/insert_custom_quote.php', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ username: user, quote: this.state.text }) }).then((response) => response.json()) .then((responseJson) => { this.fetchData(); }).catch((error) => { console.error(error); }); } } ListEmpty = () => { return ( //View to show when list is empty No quotes. ); }; onRefresh() { this.setState({ isFetching: true }, function() { this.fetchData() }); } componentDidMount() {this.fetchData();} //GETS THE QUOTES FROM THE DATABASE fetchData = () => {this.setState({loading: true}); const { navigation } = this.props; const user = navigation.getParam('user', 'test'); fetch('http://compsci02.snc.edu/cs460/2019/khoral/mysql/get_quotes_for_users_list.php', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ username: user }) //This is a test to see if branch worked }) .then(response => response.json()) .then(responseJson => { console.log(responseJson); responseJson = responseJson.map(item => { item.isSelect = false; item.selectedClass = styles.list; return item; }); this.setState({ loading: false, dataSource: responseJson, isFetching: false, }); }).catch(error => {this.setState({loading: false}); }); }; //renderItem={item => this.renderItem(item)} FlatListItemSeparator = () => ; selectItem = data => { console.log("I'm here!"); console.log(data.item); console.log(data.item.quotes); PushNotification.cancelLocalNotifications({ id : data.item.quotes}); const { navigation } = this.props; const user = navigation.getParam('user', 'test'); fetch('http://compsci02.snc.edu/cs460/2019/khoral/mysql/delete_custom_quote.php', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ key: data.item.quotes, username: user, }) }).then((response) => response.json()) .then((responseJson) => { this.fetchData(); }).catch((error) => { console.error(error); }); }; //goToStore = () =>this.props.navigation.navigate("Expenses", {selected: this.state.selected,}); renderItem = data => //HANDLES THE DATA BEFORE IT GOES INTO THE FLATELIST {data.item.quotes} this.selectItem(data)} name="trash" color="cornflowerblue" /> render() { const itemNumber = this.state.dataSource.filter(item => item.isSelect).length; if (this.state.loading) {return ( ); } return ( {this.state.data} this.setState({text})} multiline value={this.state.text} ref='QuoteInput' />