<commit_before>"use strict";

import React, {Component} from 'react';
import {findDOMNode} from 'react-dom';
import Agenda from '../lib/agenda'
import {Header, Navigation, Row, Info} from './calendar-utils'
import {Week, Month} from './calendar-view'


export default class extends Component {
  constructor(props) {
    super(props)
    this.agenda = new Agenda(this.props.year, this.props.month, this.props.day)
    this.agenda.setException(this.props.except||[]);
    this.state = {
      editor: false,
      view: this.props.view,
      events: this.props.events||[],
      store: this.agenda.matrix(this.props.view),
      info: this.agenda.getInfo(),
      start: -1,
      end: -1,
      startInit: -1
    }
    if (this.props.onLoad)
      this.props.onLoad(this.props)
  }

  componentWillReceiveProps(props) {
    this.agenda.changeDate(props.year, props.month, props.day)
    this.setState({
      view: props.view,
      events: props.events||[],
      agenda: this.agenda,
      store: this.agenda.matrix(props.view),
      info: this.agenda.getInfo(),
    })
    this.props.onChange(props)
  }

  toggleEditor() {
    this.setState({
      editor: !this.state.editor,
      start: -1,
      end: -1,
      startInit: -1
    });
  }

  toggleSelection(val) {
    if (this.state.editor) {
      if (this.state.start !== -1) {
        let selection = this.getSmartSelection(val)
        this.setState({
          selection: selection,
          start: -1,
          end: -1,
          startInit: -1
        })
        this.props.onSelect(selection, this.state.editor)
      } else {
        this.setState({
          startInit: val,
          start: val,
          end: val
        })
      }
    } else {
      this.props.onSelect(val, this.state.editor)
    }
  }

  moveSelection(val) {
    if (this.state.start !== -1)
      this.setState(this.getSmartSelection(val))
  }

  onSelectEvent(val) {
    this.props.onSelect(val, this.state.editor)
  }

  getSmartSelection(b) {
    let a = this.state.startInit
    return {
      start: a.date <= b.date ? a : b,
      end: a.date >= b.date ? a : b
    }
  }

  render() {
    let view = this.state.view
      , events = this.state.events
      , agenda = this.state.agenda
      , store = this.state.store
      , props = {
        events: events,
        toggleSelection: this.toggleSelection.bind(this),
        moveSelection: this.moveSelection.bind(this),
        onSelect: this.onSelectEvent.bind(this),
        selectionStart: this.state.start,
        selectionEnd: this.state.end,
        editor: this.state.editor
      };


    return (
      <div className="agenda" style={{width: this.props.width}}>

        <Navigation store={store}<commit_msg>month: hour selection equal to 23<commit_after>"use strict";

import React, {Component} from 'react';
import _ from 'lodash';
import {findDOMNode} from 'react-dom';
import Agenda from '../lib/agenda'
import {Header, Navigation, Row, Info} from './calendar-utils'
import {Week, Month} from './calendar-view'


export default class extends Component {
  constructor(props) {
    super(props)
    this.agenda = new Agenda(this.props.year, this.props.month, this.props.day)
    this.agenda.setException(this.props.except||[]);
    this.state = {
      editor: false,
      view: this.props.view,
      events: this.props.events||[],
      store: this.agenda.matrix(this.props.view),
      info: this.agenda.getInfo(),
      start: -1,
      end: -1,
      startInit: -1
    }
    if (this.props.onLoad)
      this.props.onLoad(this.props)
  }

  componentWillReceiveProps(props) {
    this.agenda.changeDate(props.year, props.month, props.day)
    this.setState({
      view: props.view,
      events: props.events||[],
      agenda: this.agenda,
      store: this.agenda.matrix(props.view),
      info: this.agenda.getInfo(),
    })
    this.props.onChange(props)
  }

  toggleEditor() {
    this.setState({
      editor: !this.state.editor,
      start: -1,
      end: -1,
      startInit: -1
    });
  }

  toggleSelection(val) {
    if (this.state.editor) {
      if (this.state.start !== -1) {
        let selection = this.getSmartSelection(val)
        this.setState({
          selection: selection,
          start: -1,
          end: -1,
          startInit: -1
        })
        if (this.state.view === "month") {
          selection = {
            start: _.clone(selection.start),
            end: _.clone(selection.end),
          }
          selection.end.date = new Date(selection.end.date)
          selection.end.date.setHours(23)
          selection.end.hour = 23
        }
        this.props.onSelect(selection, this.state.editor)
      } else {
        this.setState({
          startInit: val,
          start: val,
          end: val
        })
      }
    } else {
      val.view = this.state.view
      this.props.onSelect(val, this.state.editor)
    }
  }

  moveSelection(val) {
    if (this.state.start !== -1)
      this.setState(this.getSmartSelection(val))
  }

  onSelectEvent(val) {
    this.props.onSelect(val, this.state.editor)
  }

  getSmartSelection(b) {
    let a = this.state.startInit
    return {
      start: a.date < b.date ? a : b,
      end: a.date < b.date ? b : a
    }
  }

  render() {
    let view = this.state.view
      , events = this.state.events
      , agenda = this.state.agenda
      , store = this.state.store
      , props = {
        events: events,
        toggleSelection: this.toggleSelection.bind(this),
        moveSelection: this.moveSelection.bind(this),
        onSelect: this.onSelectEvent.bind(this),
        selectionStart: this.state.start,
        selectionEnd: this.state.end,
        editor: this.state.editor
      };


    return (
      <div className="agenda" style={{width: this.props.width}}>

        <Navigation store={store}
{'fraction_non_alphanumeric': 0.13984214138641043, 'fraction_numerical': 0.004804392587508579, 'mean_word_length': 2.169657422512235, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 6, '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': '3288216', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1877, 'n_words': 367}