<commit_before>/**
 * @providesModule BillboardTitle
 * @flow
 */

import React from 'react'
import styled, { css } from 'styled-components'
import { connect } from 'react-redux'

import ActiveStorageProvider from 'react-activestorage-provider'
import { EditableText } from '@blueprintjs/core'

import { updateCase } from 'redux/actions'

import LibraryLogo from './LibraryLogo'
import AuthorsList from './AuthorsList'
import { PositionedFileUploadWidget } from 'utility/FileUploadWidget'

import type { State, CaseDataState, Byline, Library } from 'redux/state'

function mapStateToProps ({ edit, caseData }: State) {
  const {
    slug,
    kicker,
    title,
    photoCredit,
    authors,
    translators,
    acknowledgements,
    coverUrl,
    library,
    links,
  } = caseData

  return {
    slug,
    kicker,
    title,
    photoCredit,
    coverUrl,
    authors,
    translators,
    acknowledgements,
    library,
    links,
    editing: edit.inProgress,
  }
}

type Props = {
  slug: string,
  editing: boolean,
  kicker: string,
  title: string,
  photoCredit: string,
  coverUrl: string,
  updateCase: typeof updateCase,
  minimal?: boolean,
  library: Library,
  links: $PropertyType<CaseDataState, 'links'>,
  onBeginEditing?: () => void,
  onFinishEditing?: () => void,
} & Byline

export const UnconnectedBillboardTitle = ({
  slug,
  editing,
  kicker,
  title,
  photoCredit,
  authors,
  translators,
  acknowledgements,
  coverUrl,
  updateCase,
  minimal,
  library,
  links,
  onBeginEditing,
  onFinishEditing,
}: Props) => {
  return (
    <CoverImageContainer src={coverUrl}>
      {!minimal &&
        editing && (
        <ActiveStorageProvider
          endpoint={{
            path: `/cases/${slug}`,
            model: 'Case',
            attribute: 'cover_image',
            method: 'PUT',
          }}
          render={renderProps => (
            <PositionedFileUploadWidget
              message={{ id: 'cases.edit.changeCoverImage' }}
              {...renderProps}
            />
          )}
          onSubmit={({ coverUrl }: CaseDataState) =>
            updateCase({ coverUrl }, false)
          }
        />
      )}

      <h1>
        <span className="c-kicker">
          <EditableText
            className="pt-multiline"
            value={kicker}
            disabled={!editing || minimal}
            placeholder="Snappy kicker"
            onChange={value => updateCase({ kicker: value })}
            onEdit={onBeginEditing}
            onCancel={onFinishEditing}
            onConfirm={onFinishEditing}
          />
        </span>
        <EditableText
          multiline
          value={title}
          disabled={!editing || minimal}
          placeholder="What is the central question of the case?"
          onChange={value => updateCase({ title: value })}
          onEdit={onBeginEditing}
          onCancel={onFinishEditing}
          onConfirm={onFinishEditing}
        />
      </h1>

      {!minimal && (
        <AuthorsList
          canEdit={editing}
          byline={{
            authors,
            translators,
            acknowledgements,
          }}
          onChange={(value: Byline) => updateCase(value)}
          onStartEditing={onBeginEditing}
          onFinishEditing={onFinishEditing}
        />
      )}

      <cite className="o-bottom-right c-photo-credit">
        {!minimal && (
          <EditableText
            value={photoCredit}
            disabled={!editing}
            placeholder={editing ? 'Photo credit' : ''}
            onChange={value => updateCase({ photoCredit: value })}
            onEdit={onBeginEditing}
            onCancel={onFinishEditing}
            onConfirm={onFinishEditing}
          />
        )}
      </cite>

      {!minimal && (
        <LibraryLogo
          library={library}<commit_msg>fix: don't blow the stack when EditableText contents are too long<commit_after>/**
 * @providesModule BillboardTitle
 * @flow
 */

import React from 'react'
import styled, { css } from 'styled-components'
import { connect } from 'react-redux'

import ActiveStorageProvider from 'react-activestorage-provider'
import { EditableText } from '@blueprintjs/core'

import { updateCase } from 'redux/actions'

import LibraryLogo from './LibraryLogo'
import AuthorsList from './AuthorsList'
import { PositionedFileUploadWidget } from 'utility/FileUploadWidget'

import type { State, CaseDataState, Byline, Library } from 'redux/state'

function mapStateToProps ({ edit, caseData }: State) {
  const {
    slug,
    kicker,
    title,
    photoCredit,
    authors,
    translators,
    acknowledgements,
    coverUrl,
    library,
    links,
  } = caseData

  return {
    slug,
    kicker,
    title,
    photoCredit,
    coverUrl,
    authors,
    translators,
    acknowledgements,
    library,
    links,
    editing: edit.inProgress,
  }
}

type Props = {
  slug: string,
  editing: boolean,
  kicker: string,
  title: string,
  photoCredit: string,
  coverUrl: string,
  updateCase: typeof updateCase,
  minimal?: boolean,
  library: Library,
  links: $PropertyType<CaseDataState, 'links'>,
  onBeginEditing?: () => void,
  onFinishEditing?: () => void,
} & Byline

export const UnconnectedBillboardTitle = ({
  slug,
  editing,
  kicker,
  title,
  photoCredit,
  authors,
  translators,
  acknowledgements,
  coverUrl,
  updateCase,
  minimal,
  library,
  links,
  onBeginEditing,
  onFinishEditing,
}: Props) => {
  return (
    <CoverImageContainer src={coverUrl}>
      {!minimal &&
        editing && (
        <ActiveStorageProvider
          endpoint={{
            path: `/cases/${slug}`,
            model: 'Case',
            attribute: 'cover_image',
            method: 'PUT',
          }}
          render={renderProps => (
            <PositionedFileUploadWidget
              message={{ id: 'cases.edit.changeCoverImage' }}
              {...renderProps}
            />
          )}
          onSubmit={({ coverUrl }: CaseDataState) =>
            updateCase({ coverUrl }, false)
          }
        />
      )}

      <h1>
        <span className="c-kicker">
          <EditableText
            className="pt-multiline"
            value={kicker}
            disabled={!editing || minimal}
            placeholder="Snappy kicker"
            onChange={value => updateCase({ kicker: value })}
            onEdit={onBeginEditing}
            onCancel={onFinishEditing}
            onConfirm={onFinishEditing}
          />
        </span>
        <EditableText
          multiline
          value={title}
          disabled={!editing || minimal}
          placeholder="What is the central question of the case?"
          onChange={value => updateCase({ title: value })}
          onEdit={onBeginEditing}
          onCancel={onFinishEditing}
          onConfirm={onFinishEditing}
        />
      </h1>

      {!minimal && (
        <AuthorsList
          canEdit={editing}
          byline={{
            authors,
            translators,
            acknowledgements,
          }}
          onChange={(value: Byline) => updateCase(value)}
          onStartEditing={onBeginEditing}
          onFinishEditing={onFinishEditing}
        />
      )}

      <cite className="o-bottom-right c-photo-credit">
        {!minimal && (
          <EditableText
            multiline
            value={photoCredit}
            disabled={!editing}
            placeholder={editing ? 'Photo credit' : ''}
            onChange={value => updateCase({ photoCredit: value })}
            onEdit={onBeginEditing}
            onCancel={onFinishEditing}
            onConfirm={onFinishEditing}
          />
        )}
      </cite>

      {!minimal && (
        <LibraryLogo
          library={library}
{'fraction_non_alphanumeric': 0.11433756805807622, 'fraction_numerical': 0.0005185377236193933, 'mean_word_length': 2.0909455128205128, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 49, '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': '2389625', 'n_tokens_mistral': 2261, 'n_tokens_neox': 2203, 'n_words': 462}