<commit_before>/* @flow */

import flowRight from 'lodash/flowRight';
import createContainer from '../../../modules/store/createContainer';
import createPaginatedContainer from '../../../modules/store/createPaginatedContainer';
import createTransformPropsContainer from '../../../modules/store/createTransformPropsContainer';
import createUserContainer from '../../../modules/store/createUserContainer';
import ChatMessages from '../views/Chat/ChatMessages';
import {
	TYPE_TEXT,
	TYPE_THREAD,
	TAG_POST_HIDDEN,
	TAG_USER_ADMIN,
} from '../../../lib/Constants';
import type {
	Text,
	Thread,
	TextRel,
	ThreadRel,
	User,
} from '../../../lib/schemaTypes';

type TextData = Array<{ text: Text; textrel: TextRel; type?: 'loading' }>

export const transformTexts = (texts: TextData, thread: ?Thread, threadrel: ?ThreadRel): any => {
	const data = [];

	for (let l = texts.length - 1, i = l; i >= 0; i--) {
		const { text, textrel, type } = texts[i];
		if (type === 'loading') {
			data.push(texts[i]);
		} else if (text && text.type === TYPE_TEXT) {
			const previousText = texts[i - 1].text;
			data.push({
				text,
				textrel,
				previousText,
				isLast: i === l,
			});
		}
	}

	if (thread && thread.type === TYPE_THREAD) {<commit_msg>fix(ui): fix accessing previous text (#395)<commit_after>/* @flow */

import flowRight from 'lodash/flowRight';
import createContainer from '../../../modules/store/createContainer';
import createPaginatedContainer from '../../../modules/store/createPaginatedContainer';
import createTransformPropsContainer from '../../../modules/store/createTransformPropsContainer';
import createUserContainer from '../../../modules/store/createUserContainer';
import ChatMessages from '../views/Chat/ChatMessages';
import {
	TYPE_TEXT,
	TYPE_THREAD,
	TAG_POST_HIDDEN,
	TAG_USER_ADMIN,
} from '../../../lib/Constants';
import type {
	Text,
	Thread,
	TextRel,
	ThreadRel,
	User,
} from '../../../lib/schemaTypes';

type TextData = Array<{ text: Text; textrel: TextRel; type?: 'loading' }>

export const transformTexts = (texts: TextData, thread: ?Thread, threadrel: ?ThreadRel): any => {
	const data = [];

	for (let l = texts.length - 1, i = l; i >= 0; i--) {
		const { text, textrel, type } = texts[i];
		if (type === 'loading') {
			data.push(texts[i]);
		} else if (text && text.type === TYPE_TEXT) {
			const previousItem = texts[i - 1];
			const previousText = previousItem ? previousItem.text : null;
			data.push({
				text,
				textrel,
				previousText,
				isLast: i === l,
			});
		}
	}

	if (thread && thread.type === TYPE_THREAD) {
{'fraction_non_alphanumeric': 0.17757009345794392, 'fraction_numerical': 0.0035046728971962616, 'mean_word_length': 3.5793226381461674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '5320989', 'n_tokens_mistral': 873, 'n_tokens_neox': 821, 'n_words': 214}