<commit_before>import React from 'react'
import { connect } from 'react-redux'
import { subscribe } from 'subscribe-ui-event'
import Button from './Button'
import styles from '../styles/components/facebook-share.css'

class FacebookShare extends React.Component {

    constructor (props) {
        super(props)
        this.state = { sticky: false }
        this.subscribers
        this.shareOnFacebook = this.shareOnFacebook.bind(this)
        this.scrollHandler = this.scrollHandler.bind(this)
    }

    static propTypes = {
        responseHandler: React.PropTypes.func,
        fractions: React.PropTypes.array
    }

    componentDidMount () {
        this.subscribers = [
            subscribe('scroll', this.scrollHandler, {enableScrollInfo:true})
        ]
    }

    componentWillUnmount () {
        let subscribers = this.subscribers || []
        for (let subscriber of subscribers) {
            subscriber.unsubscribe()
        }
    }

    scrollHandler (event, payload) {
        if (payload.scroll.top > 100 && !this.state.sticky) {
            this.setState({sticky: true})
        }

        if (payload.scroll.top < 101 && this.state.sticky) {
            this.setState({sticky: false})
        }
    }

    // Because we have lots of TS-LDK files, it's easier just to use this function, than to convert files.
    shortTitle (fraction) {
        let short_title = fraction.short_title
        if (short_title === 'TSLKDF')
            short_title = 'TS-LKDF'
        if (short_title === 'LLRAKŠSF')
            short_title = 'LLRA-KŠSF'
        return short_title
    }

    shareOnFacebook () {
        const location = window.location.href.split('/')
        const base_url = location[0] + '//' + location[2]

        // Don't include MG in facebook share results
        const fractions = this.realFractions

        const fraction_one = fractions[0]
        const fraction_two = fractions[1]
        const fraction_three = fractions[2]

        const picture = base_url + '/static/img/fb-share/' +
                        this.shortTitle(fraction_one) + '/' +
                        this.shortTitle(fraction_two) + '-' +
                        this.shortTitle(fraction_three) + '.png'

        const caption = 'Sužinok daugiau >>>'
        const description = `${fraction_one.title} ${fraction_one.similarity}%; ` +
                            `${fraction_two.title} ${fraction_two.similarity}%; ` +
                            `${fraction_three.title} ${fraction_three.similarity}%. \n` +
                            'Su kokiomis politinėmis partijomis ir politikais sutampi tu?'

        // Track click in Google Analytics
        window.ga('send', 'event', {
            eventCategory: 'Facebook Share',
            eventAction: 'click',
            eventLabel: 'Click from Results'
        });

        FB.ui({
            method: 'feed',
            link: base_url + '/test',
            picture: picture,
            name: 'Politinių pažiūrų testas - manoSeimas.lt',
            caption: caption,
            description: description
        }, this.props.responseHandler)
    }

    get realFractions () {
        return this.props.fractions.filter(fraction => fraction.short_title !== 'MG')
    }

    render () {
        let fractions = this.realFractions
        let sticky_style = {}
        if (this.state.sticky) {<commit_msg>Update URL in Facebook share<commit_after>import React from 'react'
import { connect } from 'react-redux'
import { subscribe } from 'subscribe-ui-event'
import Button from './Button'
import styles from '../styles/components/facebook-share.css'

class FacebookShare extends React.Component {

    constructor (props) {
        super(props)
        this.state = { sticky: false }
        this.subscribers
        this.shareOnFacebook = this.shareOnFacebook.bind(this)
        this.scrollHandler = this.scrollHandler.bind(this)
    }

    static propTypes = {
        responseHandler: React.PropTypes.func,
        fractions: React.PropTypes.array
    }

    componentDidMount () {
        this.subscribers = [
            subscribe('scroll', this.scrollHandler, {enableScrollInfo:true})
        ]
    }

    componentWillUnmount () {
        let subscribers = this.subscribers || []
        for (let subscriber of subscribers) {
            subscriber.unsubscribe()
        }
    }

    scrollHandler (event, payload) {
        if (payload.scroll.top > 100 && !this.state.sticky) {
            this.setState({sticky: true})
        }

        if (payload.scroll.top < 101 && this.state.sticky) {
            this.setState({sticky: false})
        }
    }

    // Because we have lots of TS-LDK files, it's easier just to use this function, than to convert files.
    shortTitle (fraction) {
        let short_title = fraction.short_title
        if (short_title === 'TSLKDF')
            short_title = 'TS-LKDF'
        if (short_title === 'LLRAKŠSF')
            short_title = 'LLRA-KŠSF'
        return short_title
    }

    shareOnFacebook () {
        const location = window.location.href.split('/')
        const base_url = location[0] + '//' + location[2]

        // Don't include MG in facebook share results
        const fractions = this.realFractions

        const fraction_one = fractions[0]
        const fraction_two = fractions[1]
        const fraction_three = fractions[2]

        const picture = base_url + '/static/img/fb-share/' +
                        this.shortTitle(fraction_one) + '/' +
                        this.shortTitle(fraction_two) + '-' +
                        this.shortTitle(fraction_three) + '.png'

        const caption = 'Sužinok daugiau >>>'
        const description = `${fraction_one.title} ${fraction_one.similarity}%; ` +
                            `${fraction_two.title} ${fraction_two.similarity}%; ` +
                            `${fraction_three.title} ${fraction_three.similarity}%. \n` +
                            'Su kokiomis politinėmis partijomis ir politikais sutampi tu?'

        // Track click in Google Analytics
        window.ga('send', 'event', {
            eventCategory: 'Facebook Share',
            eventAction: 'click',
            eventLabel: 'Click from Results'
        });

        FB.ui({
            method: 'feed',
            link: base_url + '/testas',
            picture: picture,
            name: 'Politinių pažiūrų testas - manoSeimas.lt',
            caption: caption,
            description: description
        }, this.props.responseHandler)
    }

    get realFractions () {
        return this.props.fractions.filter(fraction => fraction.short_title !== 'MG')
    }

    render () {
        let fractions = this.realFractions
        let sticky_style = {}
        if (this.state.sticky) {
{'fraction_non_alphanumeric': 0.11250925240562547, 'fraction_numerical': 0.003256846780162842, 'mean_word_length': 1.98014997794442, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '937529', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1851, 'n_words': 424}