<commit_before>/**
 * A container for section inputs
 * Position changes on scroll to stick to section top
**/

import styled from 'styled-components'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import LayoutControls from './layout'

export class SectionControls extends Component {
  static propTypes = {
    channel: PropTypes.object,
    children: PropTypes.any,
    disabledAlert: PropTypes.func,
    isHero: PropTypes.bool,
    showLayouts: PropTypes.bool
  }

  state = {
    insideComponent: false
  }

  componentDidMount = () => {
    this.setInsideComponent()

    window.addEventListener(
      'scroll',
      this.setInsideComponent
    )
  }

  componentWillUnmount = () => {
    window.removeEventListener(
      'scroll',
      this.setInsideComponent
    )
  }

  setInsideComponent = () => {
    const insideComponent = this.insideComponent()

    if (insideComponent !== this.state.insideComponent) {
      this.setState({ insideComponent })
    }
  }

  getHeaderHeight = () => {
    const { type } = this.props.channel
    // Add extra space for channels with Yoast
    return type === 'partner' ? 55 : 95
  }

  getPositionBottom = () => {
    if (this.controls) {
      const { insideComponent } = this.state
      const { isHero } = this.props

      const controlsHeight = $(this.controls).height()
      const windowHeight = window.innerHeight
      const headerHeight = this.getHeaderHeight()

      const stickyBottom = windowHeight - controlsHeight - headerHeight

      if (insideComponent && !isHero) {
        return stickyBottom + 'px'
      } else {
        return '100%'
      }
    }
  }

  isScrollingOver = ($section) => {
    if (this.controls) {
      const controlsHeight = $(this.controls).height()
      const offsetTop = $section.offset().top

      const scrollPlusHeader = window.scrollY + this.getHeaderHeight()
      const offsetMinusControls = offsetTop - controlsHeight

      return scrollPlusHeader > offsetMinusControls
    }
  }

  isScrolledPast = ($section) => {
    if (this.controls) {
      const controlsHeight = $(this.controls).height()
      const sectionHeight = $section.height()
      const offsetTop = $section.offset().top
      const scrollPosition = window.scrollY

      const scrollPlusControls = scrollPosition + controlsHeight
      const scrollPlusSection = offsetTop + sectionHeight

      return scrollPlusControls > scrollPlusSection<commit_msg>fix controls position bug<commit_after>/**
 * A container for section inputs
 * Position changes on scroll to stick to section top
**/

import styled from 'styled-components'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import LayoutControls from './layout'

export class SectionControls extends Component {
  static propTypes = {
    channel: PropTypes.object,
    children: PropTypes.any,
    disabledAlert: PropTypes.func,
    isHero: PropTypes.bool,
    showLayouts: PropTypes.bool
  }

  state = {
    insideComponent: false
  }

  componentDidMount = () => {
    this.setInsideComponent()

    window.addEventListener(
      'scroll',
      this.setInsideComponent
    )
  }

  componentWillUnmount = () => {
    window.removeEventListener(
      'scroll',
      this.setInsideComponent
    )
  }

  setInsideComponent = () => {
    const insideComponent = this.insideComponent()

    if (insideComponent !== this.state.insideComponent) {
      this.setState({ insideComponent })
    }
  }

  getHeaderHeight = () => {
    const { type } = this.props.channel
    // Add extra space for channels with Yoast
    return type === 'partner' ? 55 : 95
  }

  getPositionBottom = () => {
    if (this.controls) {
      const { insideComponent } = this.state
      const { isHero } = this.props

      const controlsHeight = $(this.controls).height()
      const windowHeight = window.innerHeight
      const headerHeight = this.getHeaderHeight()

      const stickyBottom = windowHeight - controlsHeight - headerHeight

      if (insideComponent && !isHero) {
        return stickyBottom + 'px'
      }
    }
    return '100%'
  }

  isScrollingOver = ($section) => {
    if (this.controls) {
      const controlsHeight = $(this.controls).height()
      const offsetTop = $section.offset().top

      const scrollPlusHeader = window.scrollY + this.getHeaderHeight()
      const offsetMinusControls = offsetTop - controlsHeight

      return scrollPlusHeader > offsetMinusControls
    }
  }

  isScrolledPast = ($section) => {
    if (this.controls) {
      const controlsHeight = $(this.controls).height()
      const sectionHeight = $section.height()
      const offsetTop = $section.offset().top
      const scrollPosition = window.scrollY

      const scrollPlusControls = scrollPosition + controlsHeight
      const scrollPlusSection = offsetTop + sectionHeight

      return scrollPlusControls > scrollPlusSection
{'fraction_non_alphanumeric': 0.10202851978308898, 'fraction_numerical': 0.0028118096003213497, 'mean_word_length': 2.9681274900398407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '416376', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1336, 'n_words': 341}