<commit_before>/* global $ */
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';

import { selectStock, unselectStock, toggleFavourite, quandlResponse, insertFavouriteAt } from '../../../actions/sidebar';
import favTabImage from '../../../assets/png/favourites_tab.png';
import Favourite from '../../../components/Favourite.js';

/*
 *  dataTransfer.getData is only available in dragstart, drop and dragEnd
 * This allows us to get around that by setting only 2 properties:
 * -> The 'text/plain' key points to the stock code
 * -> ${stockcode} is the key and points to empty string
 * By accesing the set keys and ignoring 'text/plain'
 * we get the key code of the stock being dragged
 * */
function getCodeFromDT(types) {
    for (let i = 0; i < types.length; i++) {
        if (types[i] !== 'text/plain') {    // horrible hack to access
            return (types[i]).toUpperCase();
        }
    }
    return undefined;
}

class Favourites extends Component {
    constructor(props) {
        super(props);

        this.onClick = this.onClick.bind(this);
        this.toggleFavourite = this.toggleFavourite.bind(this);
        this.onDragOverFavourite = this.onDragOverFavourite.bind(this);
        this.onDropOverFavourite = this.onDropOverFavourite.bind(this);
        this.onQuandlResponse = this.onQuandlResponse.bind(this);
    }

    componentDidMount() {
        this.addDropTarget('favDropTarget');
        const scrollPadding = 'scroll-padding';
        const el = this.refs.scrollarea;
        $(this.refs.scrollarea).mCustomScrollbar({
            scrollInertia: 0,
            mouseWheel: {
                scrollAmount: 80
            },
            callbacks: {
                onOverflowY: () => {
                    $(el).addClass(scrollPadding);
                },
                onOverflowYNone: () => {
                    $(el).removeClass(scrollPadding);
                }
            }
        });
    }

    onClick(stockCode, stockName) {
        this.props.dispatch(selectStock(stockCode, stockName));
    }

    onDragOverFavourite(e, targetCode) {
        const codes = this.props.favourites.codes;
        const code = getCodeFromDT(e.dataTransfer.types);
        // const index = codes.indexOf(targetCode);

        const indexOfCode = codes.indexOf(code);
        if (indexOfCode <= -1 || targetCode !== code) {
            e.target.classList.add('dragOver');
        }
        e.stopPropagation();
    }

    // when dropped over fav
    onDropOverFavourite(e, targetCode) {
        const codes = this.props.favourites.codes;
        const code = e.dataTransfer.getData('text/plain');<commit_msg>style: remove redundant comment (#822)<commit_after>/* global $ */
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';

import { selectStock, unselectStock, toggleFavourite, quandlResponse, insertFavouriteAt } from '../../../actions/sidebar';
import favTabImage from '../../../assets/png/favourites_tab.png';
import Favourite from '../../../components/Favourite.js';

/*
 *  dataTransfer.getData is only available in dragstart, drop and dragEnd
 * This allows us to get around that by setting only 2 properties:
 * -> The 'text/plain' key points to the stock code
 * -> ${stockcode} is the key and points to empty string
 * By accesing the set keys and ignoring 'text/plain'
 * we get the key code of the stock being dragged
 * */
function getCodeFromDT(types) {
    for (let i = 0; i < types.length; i++) {
        if (types[i] !== 'text/plain') {    // horrible hack to access
            return (types[i]).toUpperCase();
        }
    }
    return undefined;
}

class Favourites extends Component {
    constructor(props) {
        super(props);

        this.onClick = this.onClick.bind(this);
        this.toggleFavourite = this.toggleFavourite.bind(this);
        this.onDragOverFavourite = this.onDragOverFavourite.bind(this);
        this.onDropOverFavourite = this.onDropOverFavourite.bind(this);
        this.onQuandlResponse = this.onQuandlResponse.bind(this);
    }

    componentDidMount() {
        this.addDropTarget('favDropTarget');
        const scrollPadding = 'scroll-padding';
        const el = this.refs.scrollarea;
        $(this.refs.scrollarea).mCustomScrollbar({
            scrollInertia: 0,
            mouseWheel: {
                scrollAmount: 80
            },
            callbacks: {
                onOverflowY: () => {
                    $(el).addClass(scrollPadding);
                },
                onOverflowYNone: () => {
                    $(el).removeClass(scrollPadding);
                }
            }
        });
    }

    onClick(stockCode, stockName) {
        this.props.dispatch(selectStock(stockCode, stockName));
    }

    onDragOverFavourite(e, targetCode) {
        const codes = this.props.favourites.codes;
        const code = getCodeFromDT(e.dataTransfer.types);

        const indexOfCode = codes.indexOf(code);
        if (indexOfCode <= -1 || targetCode !== code) {
            e.target.classList.add('dragOver');
        }
        e.stopPropagation();
    }

    // when dropped over fav
    onDropOverFavourite(e, targetCode) {
        const codes = this.props.favourites.codes;
        const code = e.dataTransfer.getData('text/plain');
{'fraction_non_alphanumeric': 0.12380236708622958, 'fraction_numerical': 0.0028179597971068945, 'mean_word_length': 2.3379310344827586, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '4497906', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1514, 'n_words': 352}