<commit_before>
"use strict";

import React from 'react';
import { render } from 'react-dom';
import WeUI from 'react-weui';
import Ajax from '../lib/Ajax';
const {Cells, CellsTitle, CellBody, Cell, Button, CellFooter} = WeUI;

export default class InviteList extends React.Component {

    state = {
        invite_list : this.props.user_info.invite_list,
        allow_invite_count: this.props.user_info.allow_invite_count,
        button_enable: this.props.user_info.allow_invite_count - this.props.user_info.invite_list.length > 0
    };

    generateInviteCode(){
        this.setState({
            button_enable: false
        });
        Ajax.get('/api/user/generate_code').end((err, res) => {
            window.timer.loaded = +new Date();
            var duration = window.timer.loaded - window.timer.startAt;
            var func = () => {
                var invite_list = this.state.invite_list;
                var allow_invite_count = this.state.allow_invite_count;
                if(res.body.error_code == 0){
                    invite_list.push({
                        'code': res.body.data.code,
                        'truename': '',
                        'invite_id': parseInt(1000+Math.random() * 1000)
                    })
                }
                this.setState({
                    invite_list: invite_list,
                    allow_invite_count: allow_invite_count,
                    button_enable: true
                });
            };
            if (duration >= 1000) {func();}
            else {setTimeout(func, 1000 - duration);}
        })
    }

    render() {
        let lists = this.state.invite_list.length ? this.state.invite_list.map(function(code){
            if(!code.truename) code.truename = '未使用';
            function handleClick(e){
                console.log(e);
                //@TODO 跳转到详情页
            }
            return (
                <Cell className="list_item" onClick={handleClick.bind(this)} key={code.invite_id}>
                    <CellBody>
                        <h2 className="title">{code.code}</h2>
                    </CellBody>
                    <CellFooter>
                        <p className="desc">{code.truename}</p>
                    </CellFooter>
                </Cell>
            )
        }) : '';
        let generateButton = this.state.button_enable ? (
            <Button type="primary" onClick={this.generateInviteCode.bind(this)}>
                生成邀请码
            </Button>
        ):(
            <Button type="default" disabled={true} >
                生成邀请码
            </Button>
        );
        return (<section>
            <Cell className="list_item">
                <CellBody>
                    <h2 className="title">邀请码列表</h2>
                </CellBody>
                <CellFooter>
                    <p className="desc">您已生成{this.state.invite_list.length}/{this.state.allow_invite_count}个邀请码</p>
                </CellFooter>
            </Cell>
            {lists}
            <Cell className="list_item">
                {generateButton}
            </Cell>
            <Cell className="list_item">
                <p className="desc">目前仅允许一度邀请12个好友。<br/>详情参考<a href={`${window._BASE_}/index/term`} >了解 ThreeDegrees</a></p>
            </Cell>
        </section>);
    }

}
<commit_msg>develop<commit_after>
"use strict";

import React from 'react';
import { render } from 'react-dom';
import WeUI from 'react-weui';
import Ajax from '../lib/Ajax';
const {Cells, CellsTitle, CellBody, Cell, Button, CellFooter} = WeUI;

export default class InviteList extends React.Component {

    state = {
        invite_list : this.props.user_info.invite_list,
        allow_invite_count: this.props.user_info.allow_invite_count,
        button_enable: this.props.user_info.allow_invite_count - this.props.user_info.invite_list.length > 0
    };

    generateInviteCode(){
        this.setState({
            button_enable: false
        });
        Ajax.get('/api/user/generate_code').end((err, res) => {
            var invite_list = this.state.invite_list;
            var allow_invite_count = this.state.allow_invite_count;
            if(res.body.error_code == 0){
                invite_list.push({
                    'code': res.body.data.code,
                    'truename': '',
                    'invite_id': parseInt(1000+Math.random() * 1000)
                })
            }
            this.setState({
                invite_list: invite_list,
                allow_invite_count: allow_invite_count,
                button_enable: true
            });
        })
    }

    render() {
        let lists = this.state.invite_list.length ? this.state.invite_list.map(function(code){
            if(!code.truename) code.truename = '未使用';
            function handleClick(e){
                console.log(e);
                //@TODO 跳转到详情页
            }
            return (
                <Cell className="list_item" onClick={handleClick.bind(this)} key={code.invite_id}>
                    <CellBody>
                        <h2 className="title">{code.code}</h2>
                    </CellBody>
                    <CellFooter>
                        <p className="desc">{code.truename}</p>
                    </CellFooter>
                </Cell>
            )
        }) : '';
        let generateButton = this.state.button_enable ? (
            <Button type="primary" onClick={this.generateInviteCode.bind(this)}>
                生成邀请码
            </Button>
        ):(
            <Button type="default" disabled={true} >
                生成邀请码
            </Button>
        );
        return (<section>
            <Cell className="list_item">
                <CellBody>
                    <h2 className="title">邀请码列表</h2>
                </CellBody>
                <CellFooter>
                    <p className="desc">您已生成{this.state.invite_list.length}/{this.state.allow_invite_count}个邀请码</p>
                </CellFooter>
            </Cell>
            {lists}
            <Cell className="list_item">
                {generateButton}
            </Cell>
            <Cell className="list_item">
                <p className="desc">目前仅允许一度邀请12个好友。<br/>详情参考<a href={`${window._BASE_}/index/term`} >了解 ThreeDegrees</a></p>
            </Cell>
        </section>);
    }

}

{'fraction_non_alphanumeric': 0.12484197218710492, 'fraction_numerical': 0.006321112515802781, 'mean_word_length': 1.5055423594615993, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 79, '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': '501155', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1845, 'n_words': 291}