Hydrate body ranges for story replies

This commit is contained in:
Fedor Indutny 2022-11-09 20:59:36 -08:00 committed by GitHub
parent 9f85db3fd8
commit be6e988a95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 221 additions and 172 deletions

View file

@ -11,27 +11,18 @@ export type Props = {
renderNonNewLine?: RenderTextCallbackType;
};
export class AddNewLines extends React.Component<Props> {
public static defaultProps: Partial<Props> = {
renderNonNewLine: ({ text }) => text,
};
const defaultRenderNonNewLine: RenderTextCallbackType = ({ text }) => text;
export class AddNewLines extends React.Component<Props> {
public override render():
| JSX.Element
| string
| null
| Array<JSX.Element | string | null> {
const { text, renderNonNewLine } = this.props;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const results: Array<any> = [];
const { text, renderNonNewLine = defaultRenderNonNewLine } = this.props;
const results: Array<JSX.Element | string> = [];
const FIND_NEWLINES = /\n/g;
// We have to do this, because renderNonNewLine is not required in our Props object,
// but it is always provided via defaultProps.
if (!renderNonNewLine) {
return null;
}
let match = FIND_NEWLINES.exec(text);
let last = 0;
let count = 1;