-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from hellokritty/fe_leaderByTopic
added leaderboard frontend component
- Loading branch information
Showing
9 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* ************************************ | ||
* | ||
* @module leaderActions.js | ||
* @author Kritika & Aris | ||
* @date 02/26/2020 | ||
* @description Action Creators for leaderReducer | ||
* | ||
* ************************************ | ||
*/ | ||
|
||
// import actionType constants | ||
import axios from "axios"; | ||
import * as types from "../constants/actionTypes"; | ||
|
||
|
||
// CHECK BACK ON THIS - NOT QUITE DONE YET** | ||
export const getLeaderBoard = () => dispatch => | ||
axios | ||
.get("/api/leaderboard") | ||
.then(({ data }) => { | ||
if (!data.isLoggedIn) { | ||
dispatch({ | ||
type: types.USER_LOGOUT, | ||
payload: data, | ||
}) | ||
} | ||
else { | ||
dispatch({ | ||
type: types.LEADER_BY_TOPIC, | ||
payload: data | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
|
||
const LeaderBox = ({ | ||
mentorId, | ||
username, | ||
totalSnaps, | ||
ranking | ||
}) => ( | ||
<tr> | ||
<td>{ranking}</td> | ||
<td>{username}</td> | ||
<td>{totalSnaps}</td> | ||
</tr> | ||
); | ||
|
||
export default LeaderBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* ************************************ | ||
* | ||
* @module FeedContainer | ||
* @author | ||
* @date | ||
* @description container that renders TicketBox and TicketCreator | ||
* | ||
* ************************************ | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Table } from 'react-bootstrap'; | ||
import { bindActionCreators } from 'redux'; | ||
import * as actions from '../actions/leaderActions'; | ||
|
||
import LeaderBox from '../components/LeaderBox'; | ||
|
||
|
||
const mapStateToProps = state => ({ | ||
leaderList: state.leader.leaderList | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => bindActionCreators(actions, dispatch); | ||
|
||
class LeaderBoard extends Component { | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
componentDidMount() { | ||
this.props.getLeaderBoard(); | ||
} | ||
|
||
render() { | ||
let leaderList; | ||
//this.props.leaderboard = [{leader 1},{leader 2},.....] | ||
if (!this.props.leaderList || this.props.leaderList.length === 0) { | ||
leaderList = <p>No current Rankings </p>; | ||
} else { | ||
leaderList = []; | ||
for (let i = 0; i < this.props.leaderList.length; i++) { | ||
console.log('leaderboard', this.props.leaderList[i]) | ||
let currentLeader; | ||
currentLeader = ( | ||
<LeaderBox | ||
key={`leader${i}`} | ||
mentorId = {this.props.leaderList[i].mentor_id} | ||
username={this.props.leaderList[i].name} | ||
totalSnaps={this.props.leaderList[i].sum} | ||
ranking={i+1} | ||
/> | ||
) | ||
leaderList.push(currentLeader); | ||
} | ||
} | ||
return ( | ||
<div> | ||
<Table> | ||
<thead> | ||
<tr> | ||
<th>Ranking</th> | ||
<th>Username</th> | ||
<th>Total Snaps</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{leaderList} | ||
</tbody> | ||
</Table> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(LeaderBoard); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* ************************************ | ||
* | ||
* @module leaderReducer | ||
* @author Kritika & Aris | ||
* @date 2/26/20 | ||
* @description reducer for leaderboard by topic | ||
* | ||
* ************************************ | ||
*/ | ||
|
||
import * as types from "../constants/actionTypes"; | ||
|
||
const leaderState = { | ||
leaderList: [], | ||
}; | ||
|
||
const leaderReducer = (state = leaderState, action) => { | ||
switch(action.type) { | ||
case types.LEADER_BY_TOPIC: { | ||
return { | ||
leaderList: action.payload.leaderBoard | ||
} | ||
} | ||
|
||
default: | ||
return state; | ||
} | ||
|
||
} | ||
|
||
export default leaderReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters