<commit_before>React = require 'react'
Reflux = require 'reflux'
DocumentTitle = require 'react-document-title'

utils = require '../utils.coffee'
articleActions = require '../actions/article-actions.coffee'
articleStore = require '../stores/article-store.coffee'
ArticleItem = require './article.cjsx'
ArticleEditor = require './article-editor.cjsx'

module.exports = React.createClass
	displayName: 'ArticleList'
	mixins: [
		Reflux.listenTo(articleStore, 'onUpdate')
	]
	fetch: (params) ->
		articleActions.fetch(params)
	onUpdate: (articles) ->
		@setState articles: articles
	getInitialState: ->
		@fetch @props.params unless articleStore.lastFetched
		{ articles: articleStore.articles }
	componentWillReceiveProps: (nextProps) ->
		@fetch nextProps.params
	render: ->
		articles = @state.articles
		lang = articleStore.lang
		isSingle = articles.length == 1
		title = (if isSingle then utils.localize(lang, articles[0].title) + ' - ' else '') + @props.title
		unless isSingle
			datalist = ({ doc: article, lang: lang } for article in articles)
			list = (<article key={ data.doc._id }><ArticleItem data={ data }/></article> for data in datalist)
		else
			data = doc: articles[0], lang: lang
			if @props.params.view
				list = <ArticleEditor data={ data } params={ @props.params }/>
			else
				list = <ArticleItem data={ data }/>
		<DocumentTitle title={ title }>
			<div>
				{ list }
			</div>
		</DocumentTitle><commit_msg>Fixed title after using format fields.<commit_after>React = require 'react'
Reflux = require 'reflux'
DocumentTitle = require 'react-document-title'

utils = require '../utils.coffee'
articleActions = require '../actions/article-actions.coffee'
articleStore = require '../stores/article-store.coffee'
ArticleItem = require './article.cjsx'
ArticleEditor = require './article-editor.cjsx'

module.exports = React.createClass
	displayName: 'ArticleList'
	mixins: [
		Reflux.listenTo(articleStore, 'onUpdate')
	]
	fetch: (params) ->
		articleActions.fetch(params)
	onUpdate: (articles) ->
		@setState articles: articles
	getInitialState: ->
		@fetch @props.params unless articleStore.lastFetched
		{ articles: articleStore.articles }
	componentWillReceiveProps: (nextProps) ->
		@fetch nextProps.params
	render: ->
		articles = @state.articles
		lang = articleStore.lang
		isSingle = articles.length == 1
		title = @props.title
		if isSingle
			title = utils.getFieldValueFromFormats(utils.localize(lang, articles[0].title)) + ' - ' + title
		unless isSingle
			datalist = ({ doc: article, lang: lang } for article in articles)
			list = (<article key={ data.doc._id }><ArticleItem data={ data }/></article> for data in datalist)
		else
			data = doc: articles[0], lang: lang
			if @props.params.view
				list = <ArticleEditor data={ data } params={ @props.params }/>
			else
				list = <ArticleItem data={ data }/>
		<DocumentTitle title={ title }>
			<div>
				{ list }
			</div>
		</DocumentTitle>
{'fraction_non_alphanumeric': 0.1374019774974429, 'fraction_numerical': 0.002045687009887487, 'mean_word_length': 4.067357512953368, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 31, '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': '5882423', 'n_tokens_mistral': 1020, 'n_tokens_neox': 908, 'n_words': 234}