<commit_before>/*
 * Copyright (C) 2017 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { func, arrayOf, object, bool, string } from 'prop-types';
import moment from 'moment-timezone';

import I18n from 'i18n!todo_sidebar';
import Heading from 'instructure-ui/lib/components/Heading';
import List from 'instructure-ui/lib/components/List';
import ListItem from 'instructure-ui/lib/components/List/ListItem';
import Container from 'instructure-ui/lib/components/Container';
import Spinner from 'instructure-ui/lib/components/Spinner';
import ButtonLink from 'instructure-ui/lib/components/Link';

import { loadInitialItems, completeItem } from './actions';
import ToDoItem from './ToDoItem';

export class ToDoSidebar extends Component {
  static propTypes = {
    loadInitialItems: func.isRequired,
    completeItem: func.isRequired,
    items: arrayOf(object).isRequired,
    loading: bool,
    courses: arrayOf(object).isRequired,
    timeZone: string.isRequired
  };

  static defaultProps = {
    loading: false,
    timeZone: moment.tz.guess()
  }

  constructor () {
    super()
    this.state = { showTodos: false }
  }

  componentDidMount () {
    this.props.loadInitialItems(moment.tz(this.props.timeZone).startOf('day'));
  }

  showMoreTodos = () => {
    this.setState({showTodos: true});
  }

  renderShowMoreTodos (items) {
    if (items.length > 5 && !this.state.showTodos) {
      return (
        <ButtonLink onClick={this.showMoreTodos}>{`${(items.length) - 5} ${I18n.t('More')}...`}</ButtonLink>
      );
    }
  }

  render () {
    if (this.props.loading) {
      return (
        <Container as="div" textAlign="center"><commit_msg>Fix formatting of interpolated translation in To Do widget<commit_after>/*
 * Copyright (C) 2017 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { func, arrayOf, object, bool, string } from 'prop-types';
import moment from 'moment-timezone';

import I18n from 'i18n!todo_sidebar';
import Heading from 'instructure-ui/lib/components/Heading';
import List from 'instructure-ui/lib/components/List';
import ListItem from 'instructure-ui/lib/components/List/ListItem';
import Container from 'instructure-ui/lib/components/Container';
import Spinner from 'instructure-ui/lib/components/Spinner';
import ButtonLink from 'instructure-ui/lib/components/Link';

import { loadInitialItems, completeItem } from './actions';
import ToDoItem from './ToDoItem';

export class ToDoSidebar extends Component {
  static propTypes = {
    loadInitialItems: func.isRequired,
    completeItem: func.isRequired,
    items: arrayOf(object).isRequired,
    loading: bool,
    courses: arrayOf(object).isRequired,
    timeZone: string.isRequired
  };

  static defaultProps = {
    loading: false,
    timeZone: moment.tz.guess()
  }

  constructor () {
    super()
    this.state = { showTodos: false }
  }

  componentDidMount () {
    this.props.loadInitialItems(moment.tz(this.props.timeZone).startOf('day'));
  }

  showMoreTodos = () => {
    this.setState({showTodos: true});
  }

  renderShowMoreTodos (items) {
    if (items.length > 5 && !this.state.showTodos) {
      const number = items.length - 5
      return (
        <ButtonLink onClick={this.showMoreTodos}>{I18n.t("%{number} More...", {number})}</ButtonLink>
      );
    }
  }

  render () {
    if (this.props.loading) {
      return (
        <Container as="div" textAlign="center">
{'fraction_non_alphanumeric': 0.11528874117158289, 'fraction_numerical': 0.00540091400083091, 'mean_word_length': 3.7485207100591715, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6026930', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1415, 'n_words': 443}