<commit_before>/* global confirm */
import { Components, registerComponent } from '../../lib/vulcan-lib';
import { withUpdate } from '../../lib/crud/withUpdate';
import React, { useState } from 'react';
import Users from '../../lib/collections/users/collection';
import { Link } from '../../lib/reactRouterWrapper'
import moment from 'moment';
import Typography from '@material-ui/core/Typography';
import { useCurrentUser } from '../common/withUser';
import { useHover } from '../common/withHover'
import withErrorBoundary from '../common/withErrorBoundary'
import red from '@material-ui/core/colors/red';
import DoneIcon from '@material-ui/icons/Done';
import SnoozeIcon from '@material-ui/icons/Snooze';
import DeleteForeverIcon from '@material-ui/icons/DeleteForever';
import RemoveCircleOutlineIcon from '@material-ui/icons/RemoveCircleOutline';
import { Comments } from '../../lib/collections/comments';
import DescriptionIcon from '@material-ui/icons/Description'
import { useMulti } from '../../lib/crud/withMulti';
import { Posts } from '../../lib/collections/posts';
import MessageIcon from '@material-ui/icons/Message'
import Button from '@material-ui/core/Button';

const styles = (theme: ThemeType): JssStyles => ({
  negativeKarma: {
     color: red['A100']
  },
  info: {
    // Wrap between MetaInfo elements. Non-standard CSS which may not work in Firefox.
    wordBreak: "break-word",
    display: "inline-block"
  },
  truncated: {
    maxHeight: 800,
    overflow: "hidden"
  },
  icon: {
    height: 13,
    color: theme.palette.grey[500],
    position: "relative",
    top: 3
  },
  reviewed: {
    backgroundColor: theme.palette.grey[100]
  },
  row: {
    display: "flex",
    justifyContent: "space-between",
    alignItems: "center"
  },
  bigDownvotes: {
    color: theme.palette.error.dark,
  },
  downvotes: {
    color: theme.palette.error.dark,
    opacity: .75
  },
  upvotes: {
    color: theme.palette.primary.dark,
    opacity: .75
  },
  bigUpvotes: {
    color: theme.palette.primary.dark
  }
})
const SunshineNewUsersItem = ({ user, classes, updateUser, allowContentPreview=true }: {
  user: SunshineUsersList,
  classes: ClassesType,
  updateUser?: any,
  allowContentPreview?: boolean,
}) => {
  const currentUser = useCurrentUser();
  const [hidden, setHidden] = useState(false)
  const [truncated, setTruncated] = useState(true)
  const { eventHandlers, hover, anchorEl } = useHover();

  const handleReview = () => {
    updateUser({
      selector: {_id: user._id},
      data: {
        reviewedByUserId: currentUser!._id,
        reviewedAt: new Date(),
        sunshineSnoozed: false,
        needsReview: false,
      }
    })
  }

  const handleSnooze = () => {
    updateUser({
      selector: {_id: user._id},
      data: {
        needsReview: false,
        reviewedAt: new Date(),
        reviewedByUserId: currentUser!._id,
        sunshineSnoozed: true
      }
    })
  }

  const handleBan = async () => {
    if (confirm("Ban this user for 3 months?")) {
      setHidden(true)
      await updateUser({
        selector: {_id: user._id},
        data: {
          reviewedByUserId: currentUser!._id,
          voteBanned: true,
          needsReview: false,
          reviewedAt: new Date(),
          banned: moment().add(3, 'months').toDate()
        }
      })
    }
  }

  const handlePurge = async () => {
    if (confirm("Are you sure you want to delete all this user's posts, comments and votes?")) {
      setHidden(true)
      await updateUser({
        selector: {_id: user._id},
        data: {
          reviewedByUserId: currentUser!._id,
          nullifyVotes: true,
          voteBanned: true,
          deleteContent: true,
          needsReview: false,
          reviewedAt: new Date(),
          banned: moment().add(12, 'months').toDate()
        }
      })
    }
  }

  const { results: posts, loading: postsLoading } = useMulti({
    terms:{view:"sunshineNewUsersPosts", userId: user._id},
    collection: Posts,
    fragmentName: 'SunshinePostsList',
    fetchPolicy: 'cache-and-network',
  });

  const { results: comments, loading: commentsLoading } = useMulti({
    terms:{view:"sunshineNewUsersComments", userId: user._id},
    collection: Comments,
    fragmentName: 'CommentsListWithParentMetadata',
    fetchPolicy: 'cache-and-network',
  });

  const { SunshineListItem, SidebarHoverOver, MetaInfo, SidebarActionMenu, SidebarAction, FormatDate, SunshineNewUserPostsList, SunshineNewUserCommentsList, CommentKarmaWithPreview, PostKarmaWithPreview, LWTooltip, Loading, NewConversationButton } = Components

  if (hidden) { return null }

  const hiddenPostCount = user.maxPostCount - user.postCount
  const hiddenCommentCount = user.maxCommentCount - user.commentCount

  return (
    <span {...eventHandlers}>
      <SunshineListItem hover={hover}>
        <SidebarHoverOver hover={hover} anchorEl={anchorEl}>
          <Typography variant="body2">
            <MetaInfo>
              {user.reviewedAt ? <p><em>Reviewed <FormatDate date={user.reviewedAt}/> ago by {user.reviewedByUserId}</em></p> : null }
              {user.banned ? <p><em>Banned until <FormatDate date={user.banned}/></em></p> : null }
              <div className={classes.row}>
                <div>ReCaptcha Rating: {user.signUpReCaptchaRating || "no rating"}</div>
                {currentUser && <NewConversationButton user={user} currentUser={currentUser}>
                  <Button variant="outlined">Message</Button>
                </NewConversationButton>}
              </div>
              <div dangerouslySetInnerHTML={{__html: user.htmlBio}}/>
              <hr />
              <div className={classes.row}>
                <div className={classes.bigDownvotes}>
                  Big Downvotes: { user.bigDownvoteCount || 0 }
                </div>
                <div className={classes.downvotes}>
                  Downvotes: { user.smallDownvoteCount || 0 }
                </div>
                <div className={classes.upvotes}>
                  Upvotes: { user.smallUpvoteCount || 0 }
                </div>
                <div className={classes.bigUpvotes}>
                  Big Upvotes: { user.bigUpvoteCount || 0 } 
                </div>
              </div>
              <hr />
              <div>
                <LWTooltip title="Post count">
                  <span>
                    { user.postCount || 0 }
                    <DescriptionIcon className={classes.icon}/>
                  </span> 
                </LWTooltip>
                {posts?.map(post => <PostKarmaWithPreview key={post._id} post={post}/>)}
                { hiddenPostCount ? <span> ({hiddenPostCount} deleted)</span> : null} 
              </div>
              {(commentsLoading || postsLoading) && <Loading/>}
              <div>
                <LWTooltip title="Comment count">
                  { user.commentCount || 0 }
                </LWTooltip>
                <MessageIcon className={classes.icon}/> 
                {comments?.map(comment => <CommentKarmaWithPreview key={comment._id} comment={comment}/>)}
                { hiddenCommentCount ? <span> ({hiddenCommentCount} deleted)</span> : null}
              </div>
              <SunshineNewUserPostsList posts={posts} user={user}/><commit_msg>more styling tweaks<commit_after>/* global confirm */
import { Components, registerComponent } from '../../lib/vulcan-lib';
import { withUpdate } from '../../lib/crud/withUpdate';
import React, { useState } from 'react';
import Users from '../../lib/collections/users/collection';
import { Link } from '../../lib/reactRouterWrapper'
import moment from 'moment';
import Typography from '@material-ui/core/Typography';
import { useCurrentUser } from '../common/withUser';
import { useHover } from '../common/withHover'
import withErrorBoundary from '../common/withErrorBoundary'
import red from '@material-ui/core/colors/red';
import DoneIcon from '@material-ui/icons/Done';
import SnoozeIcon from '@material-ui/icons/Snooze';
import DeleteForeverIcon from '@material-ui/icons/DeleteForever';
import RemoveCircleOutlineIcon from '@material-ui/icons/RemoveCircleOutline';
import { Comments } from '../../lib/collections/comments';
import DescriptionIcon from '@material-ui/icons/Description'
import { useMulti } from '../../lib/crud/withMulti';
import { Posts } from '../../lib/collections/posts';
import MessageIcon from '@material-ui/icons/Message'
import Button from '@material-ui/core/Button';

const styles = (theme: ThemeType): JssStyles => ({
  negativeKarma: {
     color: red['A100']
  },
  info: {
    // Wrap between MetaInfo elements. Non-standard CSS which may not work in Firefox.
    wordBreak: "break-word",
    display: "inline-block"
  },
  truncated: {
    maxHeight: 800,
    overflow: "hidden"
  },
  icon: {
    height: 13,
    color: theme.palette.grey[500],
    position: "relative",
    top: 3
  },
  hoverPostIcon: {
    height: 16,
    color: theme.palette.grey[700],
    position: "relative",
    top: 3
  },
  reviewed: {
    backgroundColor: theme.palette.grey[100]
  },
  row: {
    display: "flex",
    justifyContent: "space-between",
    alignItems: "center"
  },
  bigDownvotes: {
    color: theme.palette.error.dark,
  },
  downvotes: {
    color: theme.palette.error.dark,
    opacity: .75
  },
  upvotes: {
    color: theme.palette.primary.dark,
    opacity: .75
  },
  bigUpvotes: {
    color: theme.palette.primary.dark
  },
  hr: {
    height: 0,
    borderTop: "none",
    borderBottom: "1px solid #ccc"
  }
})
const SunshineNewUsersItem = ({ user, classes, updateUser, allowContentPreview=true }: {
  user: SunshineUsersList,
  classes: ClassesType,
  updateUser?: any,
  allowContentPreview?: boolean,
}) => {
  const currentUser = useCurrentUser();
  const [hidden, setHidden] = useState(false)
  const [truncated, setTruncated] = useState(true)
  const { eventHandlers, hover, anchorEl } = useHover();

  const handleReview = () => {
    updateUser({
      selector: {_id: user._id},
      data: {
        reviewedByUserId: currentUser!._id,
        reviewedAt: new Date(),
        sunshineSnoozed: false,
        needsReview: false,
      }
    })
  }

  const handleSnooze = () => {
    updateUser({
      selector: {_id: user._id},
      data: {
        needsReview: false,
        reviewedAt: new Date(),
        reviewedByUserId: currentUser!._id,
        sunshineSnoozed: true
      }
    })
  }

  const handleBan = async () => {
    if (confirm("Ban this user for 3 months?")) {
      setHidden(true)
      await updateUser({
        selector: {_id: user._id},
        data: {
          reviewedByUserId: currentUser!._id,
          voteBanned: true,
          needsReview: false,
          reviewedAt: new Date(),
          banned: moment().add(3, 'months').toDate()
        }
      })
    }
  }

  const handlePurge = async () => {
    if (confirm("Are you sure you want to delete all this user's posts, comments and votes?")) {
      setHidden(true)
      await updateUser({
        selector: {_id: user._id},
        data: {
          reviewedByUserId: currentUser!._id,
          nullifyVotes: true,
          voteBanned: true,
          deleteContent: true,
          needsReview: false,
          reviewedAt: new Date(),
          banned: moment().add(12, 'months').toDate()
        }
      })
    }
  }

  const { results: posts, loading: postsLoading } = useMulti({
    terms:{view:"sunshineNewUsersPosts", userId: user._id},
    collection: Posts,
    fragmentName: 'SunshinePostsList',
    fetchPolicy: 'cache-and-network',
  });

  const { results: comments, loading: commentsLoading } = useMulti({
    terms:{view:"sunshineNewUsersComments", userId: user._id},
    collection: Comments,
    fragmentName: 'CommentsListWithParentMetadata',
    fetchPolicy: 'cache-and-network',
  });

  const { SunshineListItem, SidebarHoverOver, MetaInfo, SidebarActionMenu, SidebarAction, FormatDate, SunshineNewUserPostsList, SunshineNewUserCommentsList, CommentKarmaWithPreview, PostKarmaWithPreview, LWTooltip, Loading, NewConversationButton } = Components

  if (hidden) { return null }

  const hiddenPostCount = user.maxPostCount - user.postCount
  const hiddenCommentCount = user.maxCommentCount - user.commentCount

  return (
    <span {...eventHandlers}>
      <SunshineListItem hover={hover}>
        <SidebarHoverOver hover={hover} anchorEl={anchorEl}>
          <Typography variant="body2">
            <MetaInfo>
              {user.reviewedAt ? <p><em>Reviewed <FormatDate date={user.reviewedAt}/> ago by {user.reviewedByUserId}</em></p> : null }
              {user.banned ? <p><em>Banned until <FormatDate date={user.banned}/></em></p> : null }
              <div className={classes.row}>
                <div>ReCaptcha Rating: {user.signUpReCaptchaRating || "no rating"}</div>
                {currentUser && <NewConversationButton user={user} currentUser={currentUser}>
                  <Button variant="outlined">Message</Button>
                </NewConversationButton>}
              </div>
              <div dangerouslySetInnerHTML={{__html: user.htmlBio}}/>
              <hr className={classes.hr}/>
              <div className={classes.row}>
                <div className={classes.bigDownvotes}>
                  Big Downvotes: { user.bigDownvoteCount || 0 }
                </div>
                <div className={classes.downvotes}>
                  Downvotes: { user.smallDownvoteCount || 0 }
                </div>
                <div className={classes.upvotes}>
                  Upvotes: { user.smallUpvoteCount || 0 }
                </div>
                <div className={classes.bigUpvotes}>
                  Big Upvotes: { user.bigUpvoteCount || 0 } 
                </div>
              </div>
              <hr className={classes.hr}/>
              <div>
                <LWTooltip title="Post count">
                  <span>
                    { user.postCount || 0 }
                    <DescriptionIcon className={classes.hoverPostIcon}/>
                  </span> 
                </LWTooltip>
                {posts?.map(post => <PostKarmaWithPreview key={post._id} post={post}/>)}
                { hiddenPostCount ? <span> ({hiddenPostCount} deleted)</span> : null} 
              </div>
              {(commentsLoading || postsLoading) && <Loading/>}
              <div>
                <LWTooltip title="Comment count">
                  { user.commentCount || 0 }
                </LWTooltip>
                <MessageIcon className={classes.icon}/> 
                {comments?.map(comment => <CommentKarmaWithPreview key={comment._id} comment={comment}/>)}
                { hiddenCommentCount ? <span> ({hiddenCommentCount} deleted)</span> : null}
              </div>
              <SunshineNewUserPostsList posts={posts} user={user}/>
{'fraction_non_alphanumeric': 0.13477615965480044, 'fraction_numerical': 0.004584681769147788, 'mean_word_length': 2.4359508918230253, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 131, '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': '4155672', 'n_tokens_mistral': 4422, 'n_tokens_neox': 4259, 'n_words': 947}