<commit_before>import React, { PureComponent } from 'react';
import { Components, registerComponent } from '../../lib/vulcan-lib';
import { withUpdate } from '../../lib/crud/withUpdate';
import withUser from '../common/withUser';
import Users from '../../lib/collections/users/collection';
import { Link } from '../../lib/reactRouterWrapper';
import classNames from 'classnames';
import { getRecommendationSettings } from './RecommendationsAlgorithmPicker'
import { withContinueReading } from './withContinueReading';
import {AnalyticsContext} from "../../lib/analyticsEvents";
import Hidden from '@material-ui/core/Hidden';
export const curatedUrl = "/allPosts?filter=curated&sortedBy=new&timeframe=allTime"

const styles = theme => ({
  section: {
    marginTop: -12,
  },
  continueReadingList: {
    marginBottom: theme.spacing.unit*2,
  },
  subsection: {
    marginBottom: theme.spacing.unit*2,
  },
  footerWrapper: {
    display: "flex",
    justifyContent: "flex-end",
    marginTop: 12,
    [theme.breakpoints.down('sm')]: {
      justifyContent: "center",
    }
  },
  footer: {
    color: theme.palette.lwTertiary.main,
    flexGrow: 1,
    flexWrap: "wrap",
    maxWidth: 450,
    display: "flex",
    justifyContent: "space-around",
  },
  loggedOutFooter: {
    maxWidth: 450,
    marginLeft: "auto"
  },
  sequenceGrid: {
    marginTop: 2,
    marginBottom: 2,
  },
  loggedOutCustomizeLabel: {
    fontSize: "1rem",
    fontStyle: "italic"
  }
});

const defaultFrontpageSettings = {
  method: "sample",
  count: 3,
  scoreOffset: 0,
  scoreExponent: 3,
  personalBlogpostModifier: 0,
  frontpageModifier: 10,
  curatedModifier: 50,
}


interface ExternalProps {
  configName: string
}
interface RecommendationsAndCuratedProps extends ExternalProps, WithUserProps, WithStylesProps {
  continueReading: any,
}
interface RecommendationsAndCuratedState {
  showSettings: boolean,
  settings: any,
}

class RecommendationsAndCurated extends PureComponent<RecommendationsAndCuratedProps,RecommendationsAndCuratedState> {
  state: RecommendationsAndCuratedState = {
    showSettings: false,
    settings: null,
  }

  toggleSettings = () => {
    this.setState(prevState => ({showSettings: !prevState.showSettings}))
  }

  changeSettings = (newSettings) => {
    this.setState({
      settings: newSettings
    });
  }

  render() {
    const { continueReading, classes, currentUser, configName } = this.props;
    const { showSettings } = this.state
    const { SequencesGridWrapper, LoginPopupButton, RecommendationsAlgorithmPicker, SingleColumnSection, SettingsIcon, ContinueReadingList, PostsList2, RecommendationsList, SectionTitle, SectionSubtitle, BookmarksList, LWTooltip } = Components;

    const settings = getRecommendationSettings({settings: this.state.settings, currentUser, configName})

    const continueReadingTooltip = <div>
      <div>The next posts in sequences you've started reading, but not finished.</div>
    </div>

    const bookmarksTooltip = <div>
      <div>Individual posts that you've bookmarked</div>
      <div><em>(Click to see all)</em></div>
    </div>

    // Disabled during 2018 Review [and coronavirus]
    const allTimeTooltip = <div>
      <div>
        Recently curated posts, as well as a random sampling of top-rated posts of all time
        {settings.onlyUnread && " that you haven't read yet"}.
      </div>
      <div><em>(Click to see more recommendations)</em></div>
    </div>

    // defaultFrontpageSettings does not contain anything that overrides a user
    // editable setting, so the reverse ordering here is fine
    const frontpageRecommendationSettings = {
      ...settings,
      ...defaultFrontpageSettings,
      count: currentUser ? 3 : 2,
    }

    const renderBookmarks = ((currentUser?.bookmarkedPostsMetadata?.length || 0) > 0) && !settings.hideBookmarks
    const renderContinueReading = currentUser && (continueReading?.length > 0) && !settings.hideContinueReading
 
    return <SingleColumnSection className={classes.section}>
      <SectionTitle title="Recommendations" divider={false}>
        {currentUser && 
          <LWTooltip title="Customize your recommendations">
            <SettingsIcon showIcon={false} onClick={this.toggleSettings} label="Customize"/>
          </LWTooltip>
        }
          {/* <LoginPopupButton title="Logged In users can adjust their recommendation settings">
            <SettingsIcon label="Customize Recommendations"/>
          </LoginPopupButton>
        } */}
      </SectionTitle>

      {showSettings &&
        <RecommendationsAlgorithmPicker
          configName={configName}
          settings={frontpageRecommendationSettings}
          onChange={(newSettings) => this.changeSettings(newSettings)}
        /> }

      {!currentUser && <div>
          <Hidden smDown implementation="css">
            <div className={classes.sequenceGrid}>
              <SequencesGridWrapper<commit_msg>remove login button<commit_after>import React, { PureComponent } from 'react';
import { Components, registerComponent } from '../../lib/vulcan-lib';
import { withUpdate } from '../../lib/crud/withUpdate';
import withUser from '../common/withUser';
import Users from '../../lib/collections/users/collection';
import { Link } from '../../lib/reactRouterWrapper';
import classNames from 'classnames';
import { getRecommendationSettings } from './RecommendationsAlgorithmPicker'
import { withContinueReading } from './withContinueReading';
import {AnalyticsContext} from "../../lib/analyticsEvents";
import Hidden from '@material-ui/core/Hidden';
export const curatedUrl = "/allPosts?filter=curated&sortedBy=new&timeframe=allTime"

const styles = theme => ({
  section: {
    marginTop: -12,
  },
  continueReadingList: {
    marginBottom: theme.spacing.unit*2,
  },
  subsection: {
    marginBottom: theme.spacing.unit*2,
  },
  footerWrapper: {
    display: "flex",
    justifyContent: "flex-end",
    marginTop: 12,
    [theme.breakpoints.down('sm')]: {
      justifyContent: "center",
    }
  },
  footer: {
    color: theme.palette.lwTertiary.main,
    flexGrow: 1,
    flexWrap: "wrap",
    maxWidth: 450,
    display: "flex",
    justifyContent: "space-around",
  },
  loggedOutFooter: {
    maxWidth: 450,
    marginLeft: "auto"
  },
  sequenceGrid: {
    marginTop: 2,
    marginBottom: 2,
  },
  loggedOutCustomizeLabel: {
    fontSize: "1rem",
    fontStyle: "italic"
  }
});

const defaultFrontpageSettings = {
  method: "sample",
  count: 3,
  scoreOffset: 0,
  scoreExponent: 3,
  personalBlogpostModifier: 0,
  frontpageModifier: 10,
  curatedModifier: 50,
}


interface ExternalProps {
  configName: string
}
interface RecommendationsAndCuratedProps extends ExternalProps, WithUserProps, WithStylesProps {
  continueReading: any,
}
interface RecommendationsAndCuratedState {
  showSettings: boolean,
  settings: any,
}

class RecommendationsAndCurated extends PureComponent<RecommendationsAndCuratedProps,RecommendationsAndCuratedState> {
  state: RecommendationsAndCuratedState = {
    showSettings: false,
    settings: null,
  }

  toggleSettings = () => {
    this.setState(prevState => ({showSettings: !prevState.showSettings}))
  }

  changeSettings = (newSettings) => {
    this.setState({
      settings: newSettings
    });
  }

  render() {
    const { continueReading, classes, currentUser, configName } = this.props;
    const { showSettings } = this.state
    const { SequencesGridWrapper, RecommendationsAlgorithmPicker, SingleColumnSection, SettingsIcon, ContinueReadingList, PostsList2, RecommendationsList, SectionTitle, SectionSubtitle, BookmarksList, LWTooltip } = Components;

    const settings = getRecommendationSettings({settings: this.state.settings, currentUser, configName})

    const continueReadingTooltip = <div>
      <div>The next posts in sequences you've started reading, but not finished.</div>
    </div>

    const bookmarksTooltip = <div>
      <div>Individual posts that you've bookmarked</div>
      <div><em>(Click to see all)</em></div>
    </div>

    // Disabled during 2018 Review [and coronavirus]
    const allTimeTooltip = <div>
      <div>
        Recently curated posts, as well as a random sampling of top-rated posts of all time
        {settings.onlyUnread && " that you haven't read yet"}.
      </div>
      <div><em>(Click to see more recommendations)</em></div>
    </div>

    // defaultFrontpageSettings does not contain anything that overrides a user
    // editable setting, so the reverse ordering here is fine
    const frontpageRecommendationSettings = {
      ...settings,
      ...defaultFrontpageSettings,
      count: currentUser ? 3 : 2,
    }

    const renderBookmarks = ((currentUser?.bookmarkedPostsMetadata?.length || 0) > 0) && !settings.hideBookmarks
    const renderContinueReading = currentUser && (continueReading?.length > 0) && !settings.hideContinueReading
 
    return <SingleColumnSection className={classes.section}>
      <SectionTitle title="Recommendations" divider={false}>
        {currentUser && 
          <LWTooltip title="Customize your recommendations">
            <SettingsIcon showIcon={false} onClick={this.toggleSettings} label="Customize"/>
          </LWTooltip>
        }
      </SectionTitle>

      {showSettings &&
        <RecommendationsAlgorithmPicker
          configName={configName}
          settings={frontpageRecommendationSettings}
          onChange={(newSettings) => this.changeSettings(newSettings)}
        /> }

      {!currentUser && <div>
          <Hidden smDown implementation="css">
            <div className={classes.sequenceGrid}>
              <SequencesGridWrapper
{'fraction_non_alphanumeric': 0.11710963455149502, 'fraction_numerical': 0.0070598006644518275, 'mean_word_length': 3.587142857142857, 'pattern_counts': {'":': 0, '<': 70, '<?xml version=': 0, '>': 82, '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': '3753259', 'n_tokens_mistral': 2851, 'n_tokens_neox': 2685, 'n_words': 649}