<commit_before># Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
# See the LICENCE file in the repository root for full licence text.

import { MessageLengthCounter } from './message-length-counter'
import { UserCard } from './user-card'
import mapperGroup from 'beatmap-discussions/mapper-group'
import { ReviewPost } from 'beatmap-discussions/review-post'
import { BigButton } from 'big-button'
import ClickToCopy from 'click-to-copy'
import * as React from 'react'
import { a, button, div, span } from 'react-dom-factories'
import { ReportReportable } from 'report-reportable'
import Editor from 'beatmap-discussions/editor'
import { BeatmapsContext } from 'beatmap-discussions/beatmaps-context'
import { DiscussionsContext } from 'beatmap-discussions/discussions-context'

el = React.createElement

bn = 'beatmap-discussion-post'

export class Post extends React.PureComponent
  constructor: (props) ->
    super props

    @textarea = React.createRef()
    @throttledUpdatePost = _.throttle @updatePost, 1000
    @handleKeyDown = InputHandler.textarea @handleKeyDownCallback
    @xhr = {}
    @cache = {}
    @reviewEditor = React.createRef()

    @state =
      editing: false
      posting: false
      message: @props.post.message


  componentDidMount: =>
    osu.pageChange()


  componentWillUpdate: =>
    @cache = {}


  componentDidUpdate: =>
    osu.pageChange()


  componentWillUnmount: =>
    @throttledUpdatePost.cancel()

    for own _id, xhr of @xhr
      xhr?.abort()


  render: =>
    topClasses = "#{bn} #{bn}--#{@props.type}"
    if @state.editing
      topClasses += " #{bn}--editing"
    topClasses += " #{bn}--deleted" if @props.post.deleted_at?
    topClasses += " #{bn}--unread" if !@props.read && @props.type != 'discussion'

    userGroup = if @isOwner() then mapperGroup else @props.user.groups[0]

    div
      className: topClasses
      key: "#{@props.type}-#{@props.post.id}"
      onClick: =>
        $.publish 'beatmapDiscussionPost:markRead', id: @props.post.id

      div
        className: "#{bn}__content"
        if (!@props.hideUserCard)
          el UserCard,
            user: @props.user
            group: userGroup
        @messageViewer()
        @messageEditor()


  editCancel: =>
    @setState
      editing: false
      message: @props.post.message


  editStart: =>
    @textarea.current?.style.minHeight = "#{@messageBody.getBoundingClientRect().height + 50}px"

    @setState editing: true, =>
      @textarea.current?.focus()
<commit_msg>Use new css modifier toggle<commit_after># Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
# See the LICENCE file in the repository root for full licence text.

import { MessageLengthCounter } from './message-length-counter'
import { UserCard } from './user-card'
import mapperGroup from 'beatmap-discussions/mapper-group'
import { ReviewPost } from 'beatmap-discussions/review-post'
import { BigButton } from 'big-button'
import ClickToCopy from 'click-to-copy'
import * as React from 'react'
import { a, button, div, span } from 'react-dom-factories'
import { ReportReportable } from 'report-reportable'
import Editor from 'beatmap-discussions/editor'
import { BeatmapsContext } from 'beatmap-discussions/beatmaps-context'
import { DiscussionsContext } from 'beatmap-discussions/discussions-context'
import { classWithModifiers } from 'utils/css'

el = React.createElement

bn = 'beatmap-discussion-post'

export class Post extends React.PureComponent
  constructor: (props) ->
    super props

    @textarea = React.createRef()
    @throttledUpdatePost = _.throttle @updatePost, 1000
    @handleKeyDown = InputHandler.textarea @handleKeyDownCallback
    @xhr = {}
    @cache = {}
    @reviewEditor = React.createRef()

    @state =
      editing: false
      posting: false
      message: @props.post.message


  componentDidMount: =>
    osu.pageChange()


  componentWillUpdate: =>
    @cache = {}


  componentDidUpdate: =>
    osu.pageChange()


  componentWillUnmount: =>
    @throttledUpdatePost.cancel()

    for own _id, xhr of @xhr
      xhr?.abort()


  render: =>
    topClasses = classWithModifiers bn,
      "#{@props.type}": true
      deleted: @props.post.deleted_at?
      editing: @state.editing
      unread: !@props.read && @props.type != 'discussion'

    userGroup = if @isOwner() then mapperGroup else @props.user.groups[0]

    div
      className: topClasses
      key: "#{@props.type}-#{@props.post.id}"
      onClick: =>
        $.publish 'beatmapDiscussionPost:markRead', id: @props.post.id

      div
        className: "#{bn}__content"
        if (!@props.hideUserCard)
          el UserCard,
            user: @props.user
            group: userGroup
        @messageViewer()
        @messageEditor()


  editCancel: =>
    @setState
      editing: false
      message: @props.post.message


  editStart: =>
    @textarea.current?.style.minHeight = "#{@messageBody.getBoundingClientRect().height + 50}px"

    @setState editing: true, =>
      @textarea.current?.focus()

{'fraction_non_alphanumeric': 0.12414198862522063, 'fraction_numerical': 0.003530103941949402, 'mean_word_length': 3.2642140468227425, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 27, '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': '6023850', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1551, 'n_words': 384}