<commit_before>// @flow
import React from 'react';
import { connect } from 'react-redux';
import moment from 'moment-timezone';
import { getDashboardData, fetchPosts } from '../../actions/dashboard';
import DatePicker from './DatePicker';
import RenderData from './RenderData';

type Props = {
  handleDashboardData: (start: string, end: string) => void,
  dashboardData: any
};

export type Shows = 'lastweek' | 'today' | 'month' | 'thisweek';

type State = {
  dashboard: Array<mixed>,
  startDate: any,
  focusedInput: any,
  endDate: any,
  defaultShow: Shows
};

class Dashboard extends React.Component<Props, State> {
  static defaultProps = {
    dashboardData: {}
  };
  state = {
    dashboard: [],
    defaultShow: 'today',
    startDate: moment.utc(new Date()),
    endDate: moment.utc(new Date()),
    focusedInput: null
  };

  componentDidMount() {
    const { startDate, endDate } = this.state;
    this.props.handleDashboardData(
      startDate.format('YYYY-MM-DD'),
      endDate.format('YYYY-MM-DD'),
      moment.tz.guess()
    );
  }

  componentDidUpdate({ dashboardData }: Props) {
    if (
      this.props.dashboardData.isFetching === false &&
      dashboardData.isFetching === true
    ) {
      this.setState({
        dashboard: this.props.dashboardData.prepared
      });
    }
  }

  setDates = (startDate, endDate) => {
    this.setState({
      startDate: moment.utc(startDate),
      endDate: moment.utc(endDate)
    });
  };

  setDefaultShow = (str: Shows) => {
    this.setState({
      defaultShow: str
    });
  };

  setFocusedInput = (input: any) => {
    this.setState({ focusedInput: input });
  };

  render() {
    return (
      <div className="dashboard">
        <DatePicker
          setDates={this.setDates}
          startDate={this.state.startDate}
          endDate={this.state.endDate}
          setDefaultShow={this.setDefaultShow}
          defaultShow={this.state.defaultShow}
          focusedInput={this.state.focusedInput}
          setFocusedInput={this.setFocusedInput}
          loadData={this.props.handleDashboardData}
        />
        <RenderData
          isFetching={this.props.dashboardData.isFetching}
          data={this.state.dashboard}
        />
      </div>
    );
  }
}

const mapStateToProps = state => ({
  dashboardData: state.dashboard
});

const mapDispatchToProps = dispatch => ({
  handleDashboardData(start, end, timezone) {
    dispatch(fetchPosts());
    dispatch(getDashboardData(start, end, timezone));
  }
});

export default connect(
  mapStateToProps,<commit_msg>remove utc conversion since mongodb does it anyway<commit_after>// @flow
import React from 'react';
import { connect } from 'react-redux';
import moment from 'moment-timezone';
import { getDashboardData, fetchPosts } from '../../actions/dashboard';
import DatePicker from './DatePicker';
import RenderData from './RenderData';

type Props = {
  handleDashboardData: (start: string, end: string) => void,
  dashboardData: any
};

export type Shows = 'lastweek' | 'today' | 'month' | 'thisweek';

type State = {
  dashboard: Array<mixed>,
  startDate: any,
  focusedInput: any,
  endDate: any,
  defaultShow: Shows
};

class Dashboard extends React.Component<Props, State> {
  static defaultProps = {
    dashboardData: {}
  };
  state = {
    dashboard: [],
    defaultShow: 'today',
    startDate: moment(new Date()),
    endDate: moment(new Date()),
    focusedInput: null
  };

  componentDidMount() {
    const { startDate, endDate } = this.state;
    this.props.handleDashboardData(
      startDate.format('YYYY-MM-DD'),
      endDate.format('YYYY-MM-DD')
    );
  }

  componentDidUpdate({ dashboardData }: Props) {
    if (
      this.props.dashboardData.isFetching === false &&
      dashboardData.isFetching === true
    ) {
      this.setState({
        dashboard: this.props.dashboardData.prepared
      });
    }
  }

  setDates = (startDate, endDate) => {
    this.setState({
      startDate: moment(startDate),
      endDate: moment(endDate)
    });
  };

  setDefaultShow = (str: Shows) => {
    this.setState({
      defaultShow: str
    });
  };

  setFocusedInput = (input: any) => {
    this.setState({ focusedInput: input });
  };

  render() {
    return (
      <div className="dashboard">
        <DatePicker
          setDates={this.setDates}
          startDate={this.state.startDate}
          endDate={this.state.endDate}
          setDefaultShow={this.setDefaultShow}
          defaultShow={this.state.defaultShow}
          focusedInput={this.state.focusedInput}
          setFocusedInput={this.setFocusedInput}
          loadData={this.props.handleDashboardData}
        />
        <RenderData
          isFetching={this.props.dashboardData.isFetching}
          data={this.state.dashboard}
        />
      </div>
    );
  }
}

const mapStateToProps = state => ({
  dashboardData: state.dashboard
});

const mapDispatchToProps = dispatch => ({
  handleDashboardData(start, end) {
    dispatch(fetchPosts());
    dispatch(getDashboardData(start, end));
  }
});

export default connect(
  mapStateToProps,
{'fraction_non_alphanumeric': 0.13732809430255402, 'fraction_numerical': 0.0, 'mean_word_length': 2.9312741312741313, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '350487', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1612, 'n_words': 307}