<commit_before>/*
Copyright 2016 First People's Cultural Council

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { Component, PropTypes } from 'react'
import Immutable from 'immutable'

// REDUX
import { connect } from 'react-redux'
// REDUX: actions/dispatch/func
import { pushWindowPath } from 'providers/redux/reducers/windowPath'
import { queryPage } from 'providers/redux/reducers/fvPage'
import { fetchUserStartpage } from 'providers/redux/reducers/fvUser'

import selectn from 'selectn'
import classNames from 'classnames'

import ProviderHelpers from 'common/ProviderHelpers'

import PromiseWrapper from 'views/components/Document/PromiseWrapper'

import RaisedButton from 'material-ui/lib/raised-button'

import IntroCardView from 'views/components/Browsing/intro-card-view'
import TextHeader from 'views/components/Document/Typography/text-header'

import { isMobile } from 'react-device-detect'
import IntlService from 'views/services/intl'
import NavigationHelpers from '../../../common/NavigationHelpers'

/**
 * Explore Archive page shows all the families in the archive
 */

const { func, object, string } = PropTypes
export class PageHome extends Component {
  static propTypes = {
    // REDUX: reducers/state
    computeLogin: object.isRequired,
    computePage: object.isRequired,
    computeUserStartpage: object.isRequired,
    properties: object.isRequired,
    windowPath: string.isRequired,
    // REDUX: actions/dispatch/func
    fetchUserStartpage: func.isRequired,
    pushWindowPath: func.isRequired,
    queryPage: func.isRequired,
  }

  /*static contextTypes = {
        muiTheme: React.object.isRequired
    };*/

  intl = IntlService.instance

  constructor(props, context) {
    super(props, context)
    window.intl = this.intl

    this.state = {
      pagePath: '/' + this.props.properties.domain + '/sections/Site/Resources/',
      dialectsPath: '/' + this.props.properties.domain + '/sections/',
    }
    ;['_onNavigateRequest', '_getBlockByArea'].forEach((method) => (this[method] = this[method].bind(this)))
  }

  componentDidMount() {
    this.props.queryPage(this.state.pagePath, " AND fvpage:url LIKE '/home/'" + '&sortOrder=ASC' + '&sortBy=dc:title')

    // Get user start page
    ProviderHelpers.fetchIfMissing('currentUser', this.props.fetchUserStartpage, this.props.computeUserStartpage)
  }

  componentDidUpdate() {
    /*
    Redirect user to their start page if they:
    - are members of a single dialect
    - have one defined,
    - are not an admin
    */

    // If user is accessing /home directly, do not redirect.
    if (this.props.windowPath.indexOf('/home') !== -1) {
      return
    }
    const _computeUserStartpage = ProviderHelpers.getEntry(this.props.computeUserStartpage, 'currentUser')
    const startPage = selectn('response.value', _computeUserStartpage)
    const isAdmin = ProviderHelpers.isAdmin(this.props.computeLogin)
    if (startPage && isAdmin === false && window.location.href !== startPage) {
      window.location = startPage
    }
  }

  _onNavigateRequest(path) {
    this.props.pushWindowPath(path)
  }

  _getBlockByArea(page, area) {
    return (selectn('fvpage:blocks', page) || []).filter((block) => {
      return block.area == area
    })
  }

  render() {
    let bgAlign = 'center'
<commit_msg>Fix ∞ loop: fetchUserStartpage > defaultHome: false<commit_after>/*
Copyright 2016 First People's Cultural Council

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { Component, PropTypes } from 'react'
import Immutable from 'immutable'

// REDUX
import { connect } from 'react-redux'
// REDUX: actions/dispatch/func
import { pushWindowPath } from 'providers/redux/reducers/windowPath'
import { queryPage } from 'providers/redux/reducers/fvPage'
import { fetchUserStartpage } from 'providers/redux/reducers/fvUser'

import selectn from 'selectn'
import classNames from 'classnames'

import ProviderHelpers from 'common/ProviderHelpers'

import PromiseWrapper from 'views/components/Document/PromiseWrapper'

import RaisedButton from 'material-ui/lib/raised-button'

import IntroCardView from 'views/components/Browsing/intro-card-view'
import TextHeader from 'views/components/Document/Typography/text-header'

import { isMobile } from 'react-device-detect'
import IntlService from 'views/services/intl'
import NavigationHelpers from '../../../common/NavigationHelpers'

/**
 * Explore Archive page shows all the families in the archive
 */

const { func, object, string } = PropTypes
export class PageHome extends Component {
  static propTypes = {
    // REDUX: reducers/state
    computeLogin: object.isRequired,
    computePage: object.isRequired,
    computeUserStartpage: object.isRequired,
    properties: object.isRequired,
    windowPath: string.isRequired,
    // REDUX: actions/dispatch/func
    fetchUserStartpage: func.isRequired,
    pushWindowPath: func.isRequired,
    queryPage: func.isRequired,
  }

  /*static contextTypes = {
        muiTheme: React.object.isRequired
    };*/

  intl = IntlService.instance

  constructor(props, context) {
    super(props, context)
    window.intl = this.intl

    this.state = {
      pagePath: '/' + this.props.properties.domain + '/sections/Site/Resources/',
      dialectsPath: '/' + this.props.properties.domain + '/sections/',
    }
    ;['_onNavigateRequest', '_getBlockByArea'].forEach((method) => (this[method] = this[method].bind(this)))
  }

  async componentDidMount() {
    await this.props.queryPage(
      this.state.pagePath,
      " AND fvpage:url LIKE '/home/'" + '&sortOrder=ASC' + '&sortBy=dc:title'
    )
    // Get user start page
    await this.props.fetchUserStartpage('currentUser', {
      defaultHome: false,
    })
  }

  componentDidUpdate() {
    /*
    Redirect user to their start page if they:
    - are members of a single dialect
    - have one defined
    */

    // If user is accessing /home directly, do not redirect.
    if (this.props.windowPath.indexOf('/home') !== -1) {
      return
    }
    const _computeUserStartpage = ProviderHelpers.getEntry(this.props.computeUserStartpage, 'currentUser')
    const startPage = selectn('response.value', _computeUserStartpage)
    if (startPage) {
      window.location = startPage
    }
  }

  _onNavigateRequest(path) {
    this.props.pushWindowPath(path)
  }

  _getBlockByArea(page, area) {
    return (selectn('fvpage:blocks', page) || []).filter((block) => {
      return block.area == area
    })
  }

  render() {
    let bgAlign = 'center'

{'fraction_non_alphanumeric': 0.10951934663274869, 'fraction_numerical': 0.0024099611728477708, 'mean_word_length': 3.8038585209003215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '253627', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2165, 'n_words': 604}