<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Tooltip from '@material-ui/core/Tooltip';
import Checkbox from '@material-ui/core/Checkbox';
import { registerComponent } from '../../lib/vulcan-lib';
import { forumTypeSetting } from '../../lib/instanceSettings';

const forumDefaultCheckboxLabels = {
  LessWrong: 'Moderators may promote to Frontpage',
  AlignmentForum: 'Moderators may promote to Frontpage',
  EAForum: 'Moderators may promote to Frontpage or Community'
}

const defaultCheckboxLabel = forumDefaultCheckboxLabels[forumTypeSetting.get()]

const defaultTooltipLWAF = ({classes}: {classes: ClassesType}) => <div className={classes.tooltip}>
  <p>LW moderators will consider this post for frontpage</p>
  <p className={classes.guidelines}>Things to aim for:</p>
  <ul>
    <li className={classes.guidelines}>
      Usefulness, novelty and fun
    </li>
    <li className={classes.guidelines}>
      Timeless content (minimize reference to current events)
    </li>
    <li className={classes.guidelines}>
      Explain rather than persuade
    </li>
  </ul>
</div>

const forumDefaultTooltip = {
  LessWrong: defaultTooltipLWAF,
  AlignmentForum: defaultTooltipLWAF,
  EAForum: () => "Uncheck this box if you want your post to stay on your personal blog."
}

const defaultTooltip = forumDefaultTooltip[forumTypeSetting.get()]

const styles = (theme: ThemeType): JssStyles => ({
  submitToFrontpageWrapper: {
    [theme.breakpoints.down('sm')]: {
      width: "100%",
      order:1
    }
  },
  submitToFrontpage: {
    display: "flex",
    alignItems: "center",
    maxWidth: 300,
    [theme.breakpoints.down('sm')]: {
      width: "100%",
      maxWidth: "none",
      justifyContent: "flex-end",
      paddingRight: theme.spacing.unit*3,
    }
  },
  checkboxLabel: {
    fontWeight:500,
    fontFamily: theme.typography.commentStyle.fontFamily,
    fontSize: 16,
    color: "rgba(0,0,0,0.4)",
    verticalAlign: 'middle',
    lineHeight: '1.25em'
  },
  tooltip: {
    '& ul': {
      paddingTop: 0,
      paddingBottom: 0,
      marginTop: theme.spacing.unit/2,
      paddingLeft: theme.spacing.unit*3,
    },
    '& p': {
      marginTop: theme.spacing.unit/2,
      marginBottom: theme.spacing.unit/2
    }
  },
  guidelines: {
    fontStyle: "italic"
  },
});

interface SubmitToFrontpageCheckboxProps extends WithStylesProps {
  fieldName?: string,
  currentValues: any,
  document: any,
  label: any,
  tooltip: any,
}

class SubmitToFrontpageCheckbox extends Component<SubmitToFrontpageCheckboxProps> {
  handleClick = () => {
    const { fieldName = "submitToFrontpage" } = this.props
    const { updateCurrentValues } = this.context
    updateCurrentValues({[fieldName]: !this.getCurrentValue()})
  }
  
  getCurrentValue = () => {
    const { currentValues, document, fieldName = "submitToFrontpage" } = this.props
    let value = true
    if (fieldName in currentValues) {
      value = currentValues[fieldName]
    } else if (fieldName in document) {
      value = document[fieldName]
    }
    return value
  }

  render() {
    const { classes, label=defaultCheckboxLabel, tooltip } = this.props

    const displayedTooltip = tooltip || defaultTooltip({classes})

    return <div className={classes.submitToFrontpageWrapper}>
      <Tooltip title={displayedTooltip}>
        <div className={classes.submitToFrontpage}>
          <Checkbox checked={this.getCurrentValue()} onClick={this.handleClick}/>
          <span className={classes.checkboxLabel}>{label}</span>
        </div>
      </Tooltip>
    </div>
  }
};

(SubmitToFrontpageCheckbox as any).contextTypes = {
  updateCurrentValues: PropTypes.func,
}


const SubmitToFrontpageCheckboxComponent = registerComponent('SubmitToFrontpageCheckbox', SubmitToFrontpageCheckbox, {styles});

declare global {
  interface ComponentTypes {<commit_msg>no need for separate text about promoting to community any more<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Tooltip from '@material-ui/core/Tooltip';
import Checkbox from '@material-ui/core/Checkbox';
import { registerComponent } from '../../lib/vulcan-lib';
import { forumTypeSetting } from '../../lib/instanceSettings';

const defaultTooltipLWAF = ({classes}: {classes: ClassesType}) => <div className={classes.tooltip}>
  <p>LW moderators will consider this post for frontpage</p>
  <p className={classes.guidelines}>Things to aim for:</p>
  <ul>
    <li className={classes.guidelines}>
      Usefulness, novelty and fun
    </li>
    <li className={classes.guidelines}>
      Timeless content (minimize reference to current events)
    </li>
    <li className={classes.guidelines}>
      Explain rather than persuade
    </li>
  </ul>
</div>

const forumDefaultTooltip = {
  LessWrong: defaultTooltipLWAF,
  AlignmentForum: defaultTooltipLWAF,
  EAForum: () => "Uncheck this box if you want your post to stay on your personal blog."
}

const defaultTooltip = forumDefaultTooltip[forumTypeSetting.get()]

const styles = (theme: ThemeType): JssStyles => ({
  submitToFrontpageWrapper: {
    [theme.breakpoints.down('sm')]: {
      width: "100%",
      order:1
    }
  },
  submitToFrontpage: {
    display: "flex",
    alignItems: "center",
    maxWidth: 300,
    [theme.breakpoints.down('sm')]: {
      width: "100%",
      maxWidth: "none",
      justifyContent: "flex-end",
      paddingRight: theme.spacing.unit*3,
    }
  },
  checkboxLabel: {
    fontWeight:500,
    fontFamily: theme.typography.commentStyle.fontFamily,
    fontSize: 16,
    color: "rgba(0,0,0,0.4)",
    verticalAlign: 'middle',
    lineHeight: '1.25em'
  },
  tooltip: {
    '& ul': {
      paddingTop: 0,
      paddingBottom: 0,
      marginTop: theme.spacing.unit/2,
      paddingLeft: theme.spacing.unit*3,
    },
    '& p': {
      marginTop: theme.spacing.unit/2,
      marginBottom: theme.spacing.unit/2
    }
  },
  guidelines: {
    fontStyle: "italic"
  },
});

interface SubmitToFrontpageCheckboxProps extends WithStylesProps {
  fieldName?: string,
  currentValues: any,
  document: any,
  label: any,
  tooltip: any,
}

class SubmitToFrontpageCheckbox extends Component<SubmitToFrontpageCheckboxProps> {
  handleClick = () => {
    const { fieldName = "submitToFrontpage" } = this.props
    const { updateCurrentValues } = this.context
    updateCurrentValues({[fieldName]: !this.getCurrentValue()})
  }
  
  getCurrentValue = () => {
    const { currentValues, document, fieldName = "submitToFrontpage" } = this.props
    let value = true
    if (fieldName in currentValues) {
      value = currentValues[fieldName]
    } else if (fieldName in document) {
      value = document[fieldName]
    }
    return value
  }

  render() {
    const { classes, label='Moderators may promote to Frontpage', tooltip } = this.props

    const displayedTooltip = tooltip || defaultTooltip({classes})

    return <div className={classes.submitToFrontpageWrapper}>
      <Tooltip title={displayedTooltip}>
        <div className={classes.submitToFrontpage}>
          <Checkbox checked={this.getCurrentValue()} onClick={this.handleClick}/>
          <span className={classes.checkboxLabel}>{label}</span>
        </div>
      </Tooltip>
    </div>
  }
};

(SubmitToFrontpageCheckbox as any).contextTypes = {
  updateCurrentValues: PropTypes.func,
}


const SubmitToFrontpageCheckboxComponent = registerComponent('SubmitToFrontpageCheckbox', SubmitToFrontpageCheckbox, {styles});

declare global {
  interface ComponentTypes {
{'fraction_non_alphanumeric': 0.1263437292634373, 'fraction_numerical': 0.007962840079628402, 'mean_word_length': 3.695327102803738, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 61, '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': '828638', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2291, 'n_words': 527}