<commit_before>import { Components, registerComponent, withUpdate } from 'meteor/vulcan:core';
import React, { PureComponent } from 'react';
import withUser from '../common/withUser';
import Tooltip from '@material-ui/core/Tooltip';
import Users from 'meteor/vulcan:users';
import { withRouter, Link } from '../../lib/reactRouterWrapper.js';

class HomeLatestPosts extends PureComponent {

  toggleFilter = () => {
    const { updateUser, currentUser, router } = this.props

    let query = _.clone(router.location.query) || {view: "magic"}
    const currentFilter = query.filter || (currentUser && currentUser.currentFrontpageFilter) || "frontpage";

    const newFilter = (currentFilter === "frontpage") ? "includeMetaAndPersonal" : "frontpage"
    if (currentUser) {
      updateUser({
        selector: { _id: currentUser._id},
        data: {
          currentFrontpageFilter: newFilter,
        },
      })
    }
    query.filter = newFilter
    const location = { pathname: router.location.pathname, query };
    router.replace(location);
  }

  render () {
    const { currentUser, router } = this.props;
    const { SingleColumnSection, SectionTitle, PostsList2, SectionFooterCheckbox } = Components

    const query = _.clone(router.location.query) || {}
    const currentFilter = query.filter || (currentUser && currentUser.currentFrontpageFilter) || "frontpage";
    const limit = parseInt(query.limit) || 10

    const recentPostsTerms = {
      ...query,
      view: "magic",
      filter: currentFilter,
      forum: true,
      limit:limit
    }

    const latestTitle = (
      <p>
        <p>Recent posts, sorted by a mix of 'new' and 'highly upvoted'.</p>
        <p>By default shows only frontpage posts, and can optionally include personal blogposts.</p>
        <p><em>Moderators promote posts to frontpage if they seem to be:</em>
          <ul>
            <li>Aiming to explain rather than persuade</li>
            <li>Relatively timeless (avoiding reference to current events or local social knowledge)</li>
            <li>Reasonably relevant to the average LW user</li>
          </ul>
        </p>
      </p>
    )

    return (
      <SingleColumnSection>
        <SectionTitle title={<Tooltip title={latestTitle} placement="left-start"><span>Latest Posts</span></Tooltip>}/>
        <PostsList2 terms={recentPostsTerms}>
          <Link to={"/allPosts"}>View All Posts</Link>
          <SectionFooterCheckbox 
            onClick={this.toggleFilter} 
            value={!(currentFilter === "frontpage")} 
            label={"Include Personal Posts"} 
            />
        </PostsList2>
      </SingleColumnSection>
    )<commit_msg>Fix nesting errors in HomeLatestPosts<commit_after>import { Components, registerComponent, withUpdate } from 'meteor/vulcan:core';
import React, { PureComponent } from 'react';
import withUser from '../common/withUser';
import Tooltip from '@material-ui/core/Tooltip';
import Users from 'meteor/vulcan:users';
import { withRouter, Link } from '../../lib/reactRouterWrapper.js';

class HomeLatestPosts extends PureComponent {

  toggleFilter = () => {
    const { updateUser, currentUser, router } = this.props

    let query = _.clone(router.location.query) || {view: "magic"}
    const currentFilter = query.filter || (currentUser && currentUser.currentFrontpageFilter) || "frontpage";

    const newFilter = (currentFilter === "frontpage") ? "includeMetaAndPersonal" : "frontpage"
    if (currentUser) {
      updateUser({
        selector: { _id: currentUser._id},
        data: {
          currentFrontpageFilter: newFilter,
        },
      })
    }
    query.filter = newFilter
    const location = { pathname: router.location.pathname, query };
    router.replace(location);
  }

  render () {
    const { currentUser, router } = this.props;
    const { SingleColumnSection, SectionTitle, PostsList2, SectionFooterCheckbox } = Components

    const query = _.clone(router.location.query) || {}
    const currentFilter = query.filter || (currentUser && currentUser.currentFrontpageFilter) || "frontpage";
    const limit = parseInt(query.limit) || 10

    const recentPostsTerms = {
      ...query,
      view: "magic",
      filter: currentFilter,
      forum: true,
      limit:limit
    }

    const latestTitle = (
      <div>
        <p>Recent posts, sorted by a mix of 'new' and 'highly upvoted'.</p>
        <p>By default shows only frontpage posts, and can optionally include personal blogposts.</p>
        <p><em>Moderators promote posts to frontpage if they seem to be:</em></p>
        <ul>
          <li>Aiming to explain rather than persuade</li>
          <li>Relatively timeless (avoiding reference to current events or local social knowledge)</li>
          <li>Reasonably relevant to the average LW user</li>
        </ul>
      </div>
    )

    return (
      <SingleColumnSection>
        <SectionTitle title={<Tooltip title={latestTitle} placement="left-start"><span>Latest Posts</span></Tooltip>}/>
        <PostsList2 terms={recentPostsTerms}>
          <Link to={"/allPosts"}>View All Posts</Link>
          <SectionFooterCheckbox 
            onClick={this.toggleFilter} 
            value={!(currentFilter === "frontpage")} 
            label={"Include Personal Posts"} 
            />
        </PostsList2>
      </SingleColumnSection>
    )
{'fraction_non_alphanumeric': 0.12432128814828684, 'fraction_numerical': 0.001872308556450103, 'mean_word_length': 2.904970760233918, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 65, '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': '2272227', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1479, 'n_words': 387}