<commit_before>import React, { Component, PropTypes } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { TabViewAnimated, TabBar, SceneMap } from 'react-native-tab-view';
import { List, ListItem } from 'react-native-elements';
import * as shortid from 'shortid';

import SECTIONS from '../../../constants/SECTIONS';

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

class SectionPage extends Component {
  static componentName = 'SectionPage';

  static propTypes = {
    sectionIndex: PropTypes.number.isRequired,
    subSectionIndex: PropTypes.number.isRequired,
  };

  state = {
    index: 0,
    sectionInfo: [],
    routes: [
      { key: '1', title: '文章' },
      { key: '2', title: '洞见' },
    ],
  };

  componentWillMount() {
    const sectionIndex = this.props.subSectionIndex;
    const sectionInfo = SECTIONS[this.props.sectionIndex].subSections[sectionIndex];

    this.setState({
      sectionInfo,
    });
  }

  handleChangeTab = index => this.setState({ index });

  renderHeader = props => <TabBar {...props} />;

  renderScene = SceneMap({
    1: () => {
      const articlesView = this.state.sectionInfo.articlesView;

      if (!articlesView) {
        return <Text />;
      }

      const articleViewComponent = articlesView[0].articles.map(article => (
        <ListItem
          key={shortid.generate()}
          title={article.title}
        />
      ));

      return (
        <View>
          <View style={{ backgroundColor: '#2d89ef' }}>
            <Text style={{ margin: 10, color: '#fff', textAlign: 'center' }}>了解优秀软件工程实践所需的信息</Text>
          </View>
          <List>
            {articleViewComponent}
          </List>
        </View>
      );
    },

    2: () => (
      <View>
        <Text>扩展自己的知识视野</Text>
        {
          this.state.sectionInfo.growthView ?
            this.state.sectionInfo.growthView[0].sections.map(section => (
              <ListItem
                key={shortid.generate()}
                title={section.title}
              />
            )) : ''
        }
        <Text>TODO</Text>
        {
          this.state.sectionInfo.todoView ?
            this.state.sectionInfo.todoView.map(todo => (
              <ListItem
                key={shortid.generate()}
                title={todo.title}
              />
            )) : ''
        }
      </View>
    ),
  });

  render() {
    return (
      <TabViewAnimated
        style={styles.container}
        navigationState={this.state}
        renderScene={this.renderScene}
        renderHeader={this.renderHeader}
        onRequestChangeTab={this.handleChangeTab}
      />
    );
  }
}

export default SectionPage;<commit_msg>[Home] SectionPage: add insight view<commit_after>import React, { Component, PropTypes } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { TabViewAnimated, TabBar, SceneMap } from 'react-native-tab-view';
import { List, ListItem } from 'react-native-elements';
import * as shortid from 'shortid';

import SECTIONS from '../../../constants/SECTIONS';

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

class SectionPage extends Component {
  static componentName = 'SectionPage';

  static propTypes = {
    sectionIndex: PropTypes.number.isRequired,
    subSectionIndex: PropTypes.number.isRequired,
  };

  state = {
    index: 0,
    sectionInfo: [],
    routes: [
      { key: '1', title: '文章' },
      { key: '2', title: '洞见' },
    ],
  };

  componentWillMount() {
    const sectionIndex = this.props.subSectionIndex;
    const sectionInfo = SECTIONS[this.props.sectionIndex].subSections[sectionIndex];

    this.setState({
      sectionInfo,
    });
  }

  handleChangeTab = index => this.setState({ index });

  renderHeader = props => <TabBar {...props} />;

  renderScene = SceneMap({
    1: () => {
      const articlesView = this.state.sectionInfo.articlesView;

      if (!articlesView) {
        return <Text />;
      }

      const articleViewComponent = articlesView[0].articles.map(article => (
        <ListItem
          key={shortid.generate()}
          title={article.title}
        />
      ));

      return (
        <View>
          <View style={{ backgroundColor: '#2d89ef' }}>
            <Text style={{ margin: 10, color: '#fff', textAlign: 'center' }}>了解优秀软件工程实践所需的信息</Text>
          </View>
          <List>
            {articleViewComponent}
          </List>
        </View>
      );
    },

    2: () => {
      const growthView = this.state.sectionInfo.growthView;
      const todoView = this.state.sectionInfo.todoView;

      const growthViewComponent = growthView ? growthView[0].sections.map(section => (
        <ListItem
          key={shortid.generate()}
          title={section.title}
        />
      )) : <View />;

      const todoViewComponent = todoView ? todoView.map(todo => (
        <ListItem
          key={shortid.generate()}
          title={todo.title}
        />
        )) : <View />;

      return (
        <View>
          <View style={{ backgroundColor: '#2d89ef' }}>
            <Text style={{ margin: 10, color: '#fff', textAlign: 'center' }}>扩展自己的知识视野</Text>
          </View>
          <List>
            { growthViewComponent }
          </List>
          {
            todoView ? <Text style={{ marginTop: 15, textAlign: 'center' }}>TODO</Text> : null
          }
          <List>
            { todoViewComponent }
          </List>
        </View>
      );
    },
  });

  render() {
    return (
      <TabViewAnimated
        style={styles.container}
        navigationState={this.state}
        renderScene={this.renderScene}
        renderHeader={this.renderHeader}
        onRequestChangeTab={this.handleChangeTab}
      />
    );
  }
}

export default SectionPage;
{'fraction_non_alphanumeric': 0.14396551724137932, 'fraction_numerical': 0.005689655172413793, 'mean_word_length': 2.0922174840085286, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 65, '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': '5655370', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1763, 'n_words': 329}