<commit_before>import React, { Component } from 'react';
import { Linking, Alert, TouchableOpacity, Text, View, Image, TextInput, ListView, TouchableHighlight } from 'react-native';
import helpers from '../helpers/helpers.js';
import styles from '../styles.ios.js';
import ShareFacebook from './ShareFacebook.ios.js';
import { connect } from "react-redux";

class Recipe extends Component {
  constructor(props) {
    super(props);
    const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      steps: ds.cloneWithRows(props.recipe.analyzedInstructions[0].steps),
      ingredients: []
    }
  }

  componentWillMount() {
    this.renderIngredients();
    this.renderOptions();
  }

  goBack() {
    this.props.navigator.pop();
  }

  renderIngredients() {
    let ingredients = [];
    for (let ingredient of this.props.recipe.extendedIngredients) {
      ingredients.push(ingredient.originalString);
    }
    this.setState({
      ingredients: ingredients
    })
  }

  renderOptions() {
    const recipe = this.props.recipe;
    recipe.vegan = recipe.vegan ? '∙ Vegan' : false;
    recipe.glutenFree = recipe.glutenFree ? '∙ Gluten Free' : false;
    recipe.dairyFree = recipe.dairyFree ? '∙ Dairy Free' : false;
    if (!recipe.vegan && !recipe.glutenFree && !recipe.dairyFree) {
      recipe.dairyFree = 'No Dietary Restrictions';
    }
    recipe.cheap = recipe.cheap ? '$' : '$$$';
    recipe.sustainable = recipe.sustainable ? '∙ Recipe Sustainable' : false;
    recipe.servings = recipe.servings ? recipe.servings : 'Not available';
    recipe.healthscore = recipe.healthscore ? recipe.healthscore : 'Not available';
    // recipe.sourceUrl
  }


  shareToInstagram() {
    //deep link into the instagram app if installed
    Linking.canOpenURL('instagram://camera').then(supported => {
      if (!supported) {
        Alert.alert('You must install the Instagram app in order to use this feature.',
                    '',
                    [{text: 'Install Instagram', onPress: () => Linking.openURL('https://itunes.apple.com/us/app/instagram/id389801252?mt=8')},
                     {text: 'Not Now'}]
        );
      } else {
        return Linking.openURL('instagram://camera');
      }
    }).catch(err => console.error('An error occurred', err));
  }

  shareToTwitter() {
    //deep link into the twitter app if installed
    Linking.canOpenURL('twitter://camera').then(supported => {
      if (!supported) {
        Alert.alert('You must install the Twitter app in order to use this feature.',
                    '',
                    [{text: 'Install Twitter', onPress: () => Linking.openURL('https://itunes.apple.com/us/app/twitter/id333903271?mt=8')},
                     {text: 'Not Now'}]
        );
      } else {
        return Linking.openURL(`twitter://post?message=I%20just%20made%20${this.props.food.split(' ').join('%20')}%20with%20a%20little%20help%20from%20the%20app%20Snacktime!`);
      }
    }).catch(err => console.error('An error occurred', err));
  }

  render() {
    const ingredients = this.state.ingredients.map((ingredient, i) => {
      return (
        <Text style = {styles.ingredientListText2} key={i}>∙ {ingredient} </Text>
      )
    });
    const recipe = this.props.recipe;
    if (this.props.state.isAuthenticated) {
      return(
        <View style={styles.recipe}>
          <View style={styles.resultsTitle}> 
            <TouchableHighlight style={styles.backButton} onPress={this.goBack.bind(this)}>
              <Image style={styles.backButtonImage} source={{uri: 'https://cdn0.iconfinder.com/data/icons/vector-basic-tab-bar-icons/48/back_button-128.png'}} />
            </TouchableHighlight>
            <Text style={styles.resultsTitleText}>Instructions for {this.props.food}:</Text>
          </View>
          <View style={styles.ingredientContainer}>
            <View style={styles.ingredientList}>
              <Text> {recipe.vegan} {recipe.glutenFree} {recipe.dairyFree}</Text>
              <Text> {recipe.cheap} {recipe.sustainable} Servings: {recipe.servings} Healthscore: {recipe.healthscore}</Text>
              <Text style={styles.recipeTitle2}>Ingredients:</Text>
              <Text style={styles.ingredientListText2}>{ingredients}</Text>
            </View>
            <View style={styles.recipeImageAndIcons}>
              <Image source={{uri: this.props.image}} style={styles.recipeImage} />
              <View style={styles.iconsContainer}>
                <ShareFacebook url={this.props.recipe.sourceUrl} />
                <TouchableOpacity onPress={this.shareToInstagram.bind(this)}>
                  <Image source={require('../instagram_icon.png')} style={styles.shareIcons} />
                </TouchableOpacity>
                <TouchableOpacity onPress={this.shareToTwitter.bind(this)}>
                  <Image source={require('../twitter_icon.png')} style={styles.shareIcons} />
                </TouchableOpacity>
              </View>
            </View>
          </View>
          <View>
            <Text style={styles.recipeTitle2}>Directions:</Text>
            {/*<Image source={{uri: this.props.image}} style={styles.recipeImage} />
            <ShareFacebook url={this.props.recipe.sourceUrl} />
            <TouchableOpacity onPress={this.shareToInstagram.bind(this)}>
              <Text>Share on Instagram!</Text>
            </TouchableOpacity>
            <TouchableOpacity onPress={this.shareToTwitter.bind(this)}>
              <Text>Share on Twitter!</Text>
            </TouchableOpacity>*/}
          </View>
          <ListView
            style={styles.recipe}
            dataSource={this.state.steps}
            renderRow={(step, i) => {
              let image = step.ingredients[0] ? step.ingredients[0].image : 'https://s3-us-west-1.amazonaws.com/filmedin/food+(1).png';
              return (
              <View
                key={i} 
                style={styles.recipeStep}
                underlayColor="grey"
                >
                  <Image source={{uri: image}} style={styles.recipeImage} />
                  <Text style={styles.recipeStepText}>step {step.number}: {step.step}</Text>
              </View>
              )}}
          />
        </View>
      )
    } else {<commit_msg>(git) Git merged instagram/twitter share buttons<commit_after>import React, { Component } from 'react';
import { Linking, Alert, TouchableOpacity, Text, View, Image, TextInput, ListView, TouchableHighlight } from 'react-native';
import helpers from '../helpers/helpers.js';
import styles from '../styles.ios.js';
import ShareFacebook from './ShareFacebook.ios.js';
import { connect } from "react-redux";

class Recipe extends Component {
  constructor(props) {
    super(props);
    const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      steps: ds.cloneWithRows(props.recipe.analyzedInstructions[0].steps),
      ingredients: []
    }
  }

  componentWillMount() {
    this.renderIngredients();
    this.renderOptions();
  }

  goBack() {
    this.props.navigator.pop();
  }

  renderIngredients() {
    let ingredients = [];
    for (let ingredient of this.props.recipe.extendedIngredients) {
      ingredients.push(ingredient.originalString);
    }
    this.setState({
      ingredients: ingredients
    })
  }

  renderOptions() {
    const recipe = this.props.recipe;
    recipe.vegan = recipe.vegan ? '∙ Vegan' : false;
    recipe.glutenFree = recipe.glutenFree ? '∙ Gluten Free' : false;
    recipe.dairyFree = recipe.dairyFree ? '∙ Dairy Free' : false;
    if (!recipe.vegan && !recipe.glutenFree && !recipe.dairyFree) {
      recipe.dairyFree = 'No Dietary Restrictions';
    }
    recipe.cheap = recipe.cheap ? '$' : '$$$';
    recipe.sustainable = recipe.sustainable ? '∙ Recipe Sustainable' : false;
    recipe.servings = recipe.servings ? recipe.servings : 'Not available';
    recipe.healthscore = recipe.healthscore ? recipe.healthscore : 'Not available';
    // recipe.sourceUrl
  }


  shareToInstagram() {
    //deep link into the instagram app if installed
    Linking.canOpenURL('instagram://camera').then(supported => {
      if (!supported) {
        Alert.alert('You must install the Instagram app in order to use this feature.',
                    '',
                    [{text: 'Install Instagram', onPress: () => Linking.openURL('https://itunes.apple.com/us/app/instagram/id389801252?mt=8')},
                     {text: 'Not Now'}]
        );
      } else {
        return Linking.openURL('instagram://camera');
      }
    }).catch(err => console.error('An error occurred', err));
  }

  shareToTwitter() {
    //deep link into the twitter app if installed
    Linking.canOpenURL('twitter://camera').then(supported => {
      if (!supported) {
        Alert.alert('You must install the Twitter app in order to use this feature.',
                    '',
                    [{text: 'Install Twitter', onPress: () => Linking.openURL('https://itunes.apple.com/us/app/twitter/id333903271?mt=8')},
                     {text: 'Not Now'}]
        );
      } else {
        return Linking.openURL(`twitter://post?message=I%20just%20made%20${this.props.food.split(' ').join('%20')}%20with%20a%20little%20help%20from%20the%20app%20Snacktime!`);
      }
    }).catch(err => console.error('An error occurred', err));
  }

  render() {
    const ingredients = this.state.ingredients.map((ingredient, i) => {
      return (
        <Text style = {styles.ingredientListText2} key={i}>∙ {ingredient} </Text>
      )
    });
    const recipe = this.props.recipe;
    if (this.props.state.isAuthenticated) {
      return(
        <View style={styles.recipe}>
          <View style={styles.resultsTitle}> 
            <TouchableHighlight style={styles.backButton} onPress={this.goBack.bind(this)}>
              <Image style={styles.backButtonImage} source={{uri: 'https://cdn0.iconfinder.com/data/icons/vector-basic-tab-bar-icons/48/back_button-128.png'}} />
            </TouchableHighlight>
            <Text style={styles.resultsTitleText}>Instructions for {this.props.food}:</Text>
          </View>
          <View style={styles.ingredientContainer}>
            <View style={styles.ingredientList}>
              <Text> {recipe.vegan} {recipe.glutenFree} {recipe.dairyFree}</Text>
              <Text> {recipe.cheap} {recipe.sustainable} Servings: {recipe.servings} Healthscore: {recipe.healthscore}</Text>
              <Text style={styles.recipeTitle2}>Ingredients:</Text>
              <Text style={styles.ingredientListText2}>{ingredients}</Text>
            </View>
            <View style={styles.recipeImageAndIcons}>
              <Image source={{uri: this.props.image}} style={styles.recipeImage} />
              <View style={styles.iconsContainer}>
                <ShareFacebook url={this.props.recipe.sourceUrl} />
                <TouchableOpacity onPress={this.shareToInstagram.bind(this)}>
                  <Image source={require('../instagram_icon.png')} style={styles.shareIcons} />
                </TouchableOpacity>
                <TouchableOpacity onPress={this.shareToTwitter.bind(this)}>
                  <Image source={require('../twitter_icon.png')} style={styles.shareIcons} />
                </TouchableOpacity>
              </View>
            </View>
          </View>
          <View>
            <Text style={styles.recipeTitle2}>Directions:</Text>
          </View>
          <ListView
            style={styles.recipe}
            dataSource={this.state.steps}
            renderRow={(step, i) => {
              let image = step.ingredients[0] ? step.ingredients[0].image : 'https://s3-us-west-1.amazonaws.com/filmedin/food+(1).png';
              return (
              <View
                key={i} 
                style={styles.recipeStep}
                underlayColor="grey"
                >
                  <Image source={{uri: image}} style={styles.recipeImage} />
                  <Text style={styles.recipeStepText}>step {step.number}: {step.step}</Text>
              </View>
              )}}
          />
        </View>
      )
    } else {
{'fraction_non_alphanumeric': 0.14895018526142445, 'fraction_numerical': 0.01053931659118979, 'mean_word_length': 2.4070126227208974, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 121, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6853131', 'n_tokens_mistral': 3724, 'n_tokens_neox': 3602, 'n_words': 637}