<commit_before>import React from 'react';
import ReactDOM from 'react-dom';
import Promise from 'bluebird';
import * as utils from '../../../theme/template/utils';
import { Link } from 'react-router';
import { Drawer, List, Icon } from 'antd-mobile';

export function collect(nextProps, callback) {
  const componentsList = utils.collectDocs(nextProps.data.components);

  const moduleDocs = [
    ...utils.collectDocs(nextProps.data.docs.react),
    ...componentsList,
    /* eslint-disable new-cap */
    nextProps.data.CHANGELOG(),
    /* eslint-enable new-cap */
  ];

  // const componentName = nextProps.params.component;
  const componentName = nextProps.params.component;
  const demos = nextProps.utils.get(nextProps.data, ['components', componentName, 'demo']);
  const listDemos = nextProps.utils.get(nextProps.data, ['components', 'list-view', 'demo']);
  const drawerDemos = nextProps.utils.get(nextProps.data, ['components', 'drawer', 'demo']);

  const promises = [Promise.all(componentsList), Promise.all(moduleDocs)];

  if (demos) {
    promises.push(Promise.all(
      Object.keys(demos).map((key) => {
        if (typeof demos[key] === 'function') {
          return demos[key]();
        /* eslint-disable no-else-return */
        } else {
          return demos[key].web();
        }
      })
    ));
  }

  promises.push(Promise.all(
    Object.keys(listDemos).map((key) => {
      if (typeof listDemos[key] === 'function') {
        return listDemos[key]();
      /* eslint-disable no-else-return */
      } else {
        return listDemos[key].web();
      }
    }))
  );

  promises.push(Promise.all(
    Object.keys(drawerDemos).map((key) => {
      if (typeof drawerDemos[key] === 'function') {
        return drawerDemos[key]();
      /* eslint-disable no-else-return */
      } else {
        return drawerDemos[key].web();
      }
    }))
  );

  Promise.all(promises)
    .then((list) => callback(null, {
      ...nextProps,
      components: list[0],
      moduleData: list[1],
      demos: list[2],
      listDemos: list[3],
      drawerDemos: list[4],
    }));
}

export default class Home extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      open: false,
    };
  }

  componentWillReceiveProps = () => {
    this.setState({
      open: false,
    });
  }

  onOpenChange = () => {
    this.setState({ open: !this.state.open });
  }

  render() {
    const { demos, listDemos, drawerDemos } = this.props;
    const name = this.props.params.component;

    const demoSort = demos.sort((a, b) => (
      parseInt(a.meta.order, 10) - parseInt(b.meta.order, 10)
    ));

    const lists = {};
    this.props.components.forEach(i => {
      const meta = i.meta;
      if (!lists[meta.category]) {
        lists[meta.category] = [];
      }
      lists[meta.category].push(meta);
    });

    const componentList = lists['UI Views'].concat(lists['UI Bars'])
    .concat(lists['UI Controls']).concat(lists.Other);

    let demoMeta;
    componentList.forEach((item) => {
      if (item.filename.split('/')[1] === name) {
        demoMeta = item;
      }
    });

    const whiteList = ['drawer', 'list-view'];
    const sidebar = (<div>
      <div className="demo-drawer-home">
        <Link to="/">Ant Design Mobile</Link>
      </div>
      {Object.keys(lists).map((cate, index) => (
        <List key={index} title={cate}>
          <List.Body>
            {
              lists[cate].map((item, ii) => {
                const fileName = item.filename.split('/')[1];
                let subDemos;
                if (fileName === 'drawer') {
                  subDemos = drawerDemos;
                } else {
                  subDemos = listDemos;
                }

                return (<List.Item key={ii}>
                  {
                    whiteList.indexOf(fileName) > -1 ?
                      (<List>
                        <List.Header style={{ padding: '5px 0' }}>{item.chinese}</List.Header>
                        {
                          subDemos.map((item1, index1) => (
                            <List.Item key={index1}>
                              <Link style={{ lineHeight: '90px' }} to={`/${fileName}/#${fileName}-demo-${item1.meta.order}`}>{item1.meta.title}</Link>
                            </List.Item>
                          ))
                        }
                      </List>) :
                      <Link style={{ lineHeight: '90px' }} to={`/${fileName}/`}>{item.chinese}</Link>}<commit_msg>fix demo<commit_after>import React from 'react';
import ReactDOM from 'react-dom';
import Promise from 'bluebird';
import * as utils from '../../../theme/template/utils';
import { Link } from 'react-router';
import { Drawer, List, Icon } from 'antd-mobile';

export function collect(nextProps, callback) {
  const componentsList = utils.collectDocs(nextProps.data.components);

  const moduleDocs = [
    ...utils.collectDocs(nextProps.data.docs.react),
    ...componentsList,
    /* eslint-disable new-cap */
    nextProps.data.CHANGELOG(),
    /* eslint-enable new-cap */
  ];

  // const componentName = nextProps.params.component;
  const componentName = nextProps.params.component;
  const demos = nextProps.utils.get(nextProps.data, ['components', componentName, 'demo']);
  const listDemos = nextProps.utils.get(nextProps.data, ['components', 'list-view', 'demo']);
  const drawerDemos = nextProps.utils.get(nextProps.data, ['components', 'drawer', 'demo']);

  const promises = [Promise.all(componentsList), Promise.all(moduleDocs)];

  if (demos) {
    promises.push(Promise.all(
      Object.keys(demos).map((key) => {
        if (typeof demos[key] === 'function') {
          return demos[key]();
        /* eslint-disable no-else-return */
        } else {
          return demos[key].web();
        }
      })
    ));
  }

  promises.push(Promise.all(
    Object.keys(listDemos).map((key) => {
      if (typeof listDemos[key] === 'function') {
        return listDemos[key]();
      /* eslint-disable no-else-return */
      } else {
        return listDemos[key].web();
      }
    }))
  );

  promises.push(Promise.all(
    Object.keys(drawerDemos).map((key) => {
      if (typeof drawerDemos[key] === 'function') {
        return drawerDemos[key]();
      /* eslint-disable no-else-return */
      } else {
        return drawerDemos[key].web();
      }
    }))
  );

  Promise.all(promises)
    .then((list) => callback(null, {
      ...nextProps,
      components: list[0],
      moduleData: list[1],
      demos: list[2],
      listDemos: list[3],
      drawerDemos: list[4],
    }));
}

export default class Home extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      open: false,
    };
  }

  componentWillReceiveProps = () => {
    this.setState({
      open: false,
    });
  }

  onOpenChange = () => {
    this.setState({ open: !this.state.open });
  }

  render() {
    const { demos, listDemos, drawerDemos } = this.props;
    const name = this.props.params.component;

    const demoSort = demos.sort((a, b) => (
      parseInt(a.meta.order, 10) - parseInt(b.meta.order, 10)
    ));

    const lists = {};
    this.props.components.forEach(i => {
      const meta = i.meta;
      if (!lists[meta.category]) {
        lists[meta.category] = [];
      }
      lists[meta.category].push(meta);
    });

    const componentList = lists['UI Views'].concat(lists['UI Bars'])
    .concat(lists['UI Controls']).concat(lists.Other);

    let demoMeta;
    componentList.forEach((item) => {
      if (item.filename.split('/')[1] === name) {
        demoMeta = item;
      }
    });

    const whiteList = ['drawer', 'list-view'];
    const sidebar = (<div>
      <div className="demo-drawer-home">
        <Link to="/">Ant Design Mobile</Link>
      </div>
      {Object.keys(lists).map((cate, index) => (
        <List key={index} title={cate}>
          <List.Body>
            {
              lists[cate].map((item, ii) => {
                const fileName = item.filename.split('/')[1];
                let subDemos;
                if (fileName === 'drawer') {
                  subDemos = drawerDemos;
                } else {
                  subDemos = listDemos;
                }

                return (<List.Item key={ii}>
                  {
                    whiteList.indexOf(fileName) > -1 ?
                      (<List>
                        <List.Header style={{ padding: '5px 0' }}>{item.chinese}</List.Header>
                        {
                          subDemos.map((item1, index1) => (
                            <List.Item key={index1}>
                              <Link to={`/${fileName}/#${fileName}-demo-${item1.meta.order}`}>{item1.meta.title}</Link>
                            </List.Item>
                          ))
                        }
                      </List>) :
                      <Link to={`/${fileName}/`}>{item.chinese}</Link>}
{'fraction_non_alphanumeric': 0.16675955857763905, 'fraction_numerical': 0.004681752313008583, 'mean_word_length': 1.988674217188541, 'pattern_counts': {'":': 0, '<': 39, '<?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': '4030103', 'n_tokens_mistral': 2786, 'n_tokens_neox': 2732, 'n_words': 494}