<commit_before>// @flow
import React, {PropTypes} from 'react'
import {
  StyleSheet,
  View,
  ListView,
  Text,
  Navigator,
  TouchableOpacity,
} from 'react-native'

import type {StoryType} from './types'
import LoadingView from '../components/loading'
import * as c from '../components/colors'

let Entities = require('html-entities').AllHtmlEntities
const entities = new Entities()

import NewsItemView from './news-item'

export default class NewsContainer extends React.Component {
  static propTypes = {
    navigator: PropTypes.instanceOf(Navigator).isRequired,
    url: PropTypes.string.isRequired,
  }

  state = {
    dataSource: null,
    loaded: false,
    error: false,
  }

  componentWillMount() {
    this.fetchData()
  }

  rowHasChanged(r1: StoryType, r2: StoryType) {
    return r1.title != r2.title
  }

  async fetchData() {
    let ds = new ListView.DataSource({
      rowHasChanged: this.rowHasChanged,
    })

    try {
      let response = await fetch(this.props.url)
      let responseJson = await response.json()
      this.setState({dataSource: ds.cloneWithRows(responseJson.responseData.feed.entries)})
    } catch (error) {
      this.setState({error: true})
      console.error(error)
    }
    this.setState({loaded: true})
  }

  renderRow(story: StoryType) {
    let title = entities.decode(story.title)
    let snippet = entities.decode(story.contentSnippet)
    return (
      <TouchableOpacity onPress={() => this.onPressNews(title, story)}>
        <View style={styles.pageContainer}>
          <View style={styles.rightContainer}>
            <Text style={styles.newsTitle}>{title}</Text>
            <Text style={styles.newsSummary}>{snippet}</Text>
          </View>
        </View>
      </TouchableOpacity>
    )
  }

  onPressNews(title, story: StoryType) {
    this.props.navigator.push({
      id: 'NewsItemView',
      title: title,
      component: <NewsItemView
        story={story}
        title={title}
        navigator={this.props.navigator}
      />,
    })
  }

  render() {
    if (this.state.dataSource === null) {
      return <LoadingView />
    }

    return (
      <ListView
        style={styles.newsItemContainer}
        dataSource={this.state.dataSource}
        renderRow={this.renderRow.bind(this)}
      />
    )
  }
}

const styles = StyleSheet.create({
  pageContainer: {
    marginLeft: 10,
    marginRight: 10,
    borderBottomWidth: 1,
    borderBottomColor: '#ebebeb',
  },
  rightContainer: {
    flex: 1,
  },
  newsItemContainer: {
    paddingBottom: 50,
    backgroundColor: '#ffffff',
  },
  newsPic: {
    width: 90,
    height: 60,
    margin: 10,
    marginLeft: 0,
  },
  newsTitle: {
    color: c.black,
    paddingLeft: 10,
    paddingRight: 10,
    paddingTop: 10,
    paddingBottom: 3,
    fontSize: 16,
    textAlign: 'left',
  },
  newsSummary: {
    color: c.iosText,
    paddingLeft: 10,
    paddingRight: 10,
    paddingBottom: 6,
    fontSize: 13,
    textAlign: 'left',
  },
})
<commit_msg>remove a level of view nesting in NewsContainer<commit_after>// @flow
import React, {PropTypes} from 'react'
import {
  StyleSheet,
  View,
  ListView,
  Text,
  Navigator,
  TouchableOpacity,
} from 'react-native'

import type {StoryType} from './types'
import LoadingView from '../components/loading'
import * as c from '../components/colors'

let Entities = require('html-entities').AllHtmlEntities
const entities = new Entities()

import NewsItemView from './news-item'

export default class NewsContainer extends React.Component {
  static propTypes = {
    navigator: PropTypes.instanceOf(Navigator).isRequired,
    url: PropTypes.string.isRequired,
  }

  state = {
    dataSource: null,
    loaded: false,
    error: false,
  }

  componentWillMount() {
    this.fetchData()
  }

  rowHasChanged(r1: StoryType, r2: StoryType) {
    return r1.title != r2.title
  }

  async fetchData() {
    let ds = new ListView.DataSource({
      rowHasChanged: this.rowHasChanged,
    })

    try {
      let response = await fetch(this.props.url)
      let responseJson = await response.json()
      this.setState({dataSource: ds.cloneWithRows(responseJson.responseData.feed.entries)})
    } catch (error) {
      this.setState({error: true})
      console.error(error)
    }
    this.setState({loaded: true})
  }

  renderRow(story: StoryType) {
    let title = entities.decode(story.title)
    let snippet = entities.decode(story.contentSnippet)
    return (
      <TouchableOpacity onPress={() => this.onPressNews(title, story)}>
        <View style={styles.rowContainer}>
          <Text style={styles.itemTitle}>{title}</Text>
          <Text style={styles.itemPreview}>{snippet}</Text>
        </View>
      </TouchableOpacity>
    )
  }

  onPressNews(title, story: StoryType) {
    this.props.navigator.push({
      id: 'NewsItemView',
      title: title,
      component: <NewsItemView
        story={story}
        title={title}
        navigator={this.props.navigator}
      />,
    })
  }

  render() {
    if (this.state.dataSource === null) {
      return <LoadingView />
    }

    return (
      <ListView
        style={styles.listContainer}
        dataSource={this.state.dataSource}
        renderRow={this.renderRow.bind(this)}
      />
    )
  }
}

const styles = StyleSheet.create({
  listContainer: {
    paddingBottom: 50,
    backgroundColor: '#ffffff',
  },
  rowContainer: {
    marginLeft: 10,
    marginRight: 10,
    borderBottomWidth: 1,
    borderBottomColor: '#ebebeb',
  },
  itemTitle: {
    color: c.black,
    paddingLeft: 10,
    paddingRight: 10,
    paddingTop: 10,
    paddingBottom: 3,
    fontSize: 16,
    textAlign: 'left',
  },
  itemPreview: {
    color: c.iosText,
    paddingLeft: 10,
    paddingRight: 10,
    paddingBottom: 6,
    fontSize: 13,
    textAlign: 'left',
  },
})

{'fraction_non_alphanumeric': 0.1292376527275856, 'fraction_numerical': 0.01066942006539322, 'mean_word_length': 2.781392322706571, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3194436', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1839, 'n_words': 392}