{"size": 984, "ext": "js", "max_stars_repo_path": "wouldyourathergame/src/components/leaderBoard.js", "max_stars_repo_name": "prasadth16/Prasad-Udacity-Would-You-Rather-Be", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wouldyourathergame/src/components/leaderBoard.js", "max_issues_repo_name": "prasadth16/Prasad-Udacity-Would-You-Rather-Be", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wouldyourathergame/src/components/leaderBoard.js", "max_forks_repo_name": "prasadth16/Prasad-Udacity-Would-You-Rather-Be", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.2307692308, "max_line_length": 122, "alphanum_fraction": 0.5772357724}
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Redirect } from 'react-router-dom'

import LeaderDetails from './leaderdetails'

class LeaderBoard extends Component {
    render() {

        return (
            <div>
                {this.props.userNames.map((user) => (
                    <div key={user.id}>
                        <LeaderDetails user={user} />
                    </div>
                ))}
            </div>
        )
    }
}

function mapStateToObject({ users, authedUser }) {
    let userNames = []
    Object.entries(users).forEach((entry) => userNames.push(entry[1]))

    userNames.sort((a, b) => {
        return (Object.keys(b.answers).length + b.questions.length) - (Object.keys(a.answers).length + a.questions.length)
    })
    return {
        userNames: userNames,
        authedUser: authedUser,
    }

}
const LeaderBoardControl = connect(mapStateToObject)(LeaderBoard)

export default LeaderBoardControl

