diff --git a/src/components/basicUIElements/view/userListItem/userListItem.js b/src/components/basicUIElements/view/userListItem/userListItem.js index 8d4b2eb0e..a073b4380 100644 --- a/src/components/basicUIElements/view/userListItem/userListItem.js +++ b/src/components/basicUIElements/view/userListItem/userListItem.js @@ -18,19 +18,34 @@ const UserListItem = ({ handleOnLongPress, isClickable, text, + middleText, + rightTextStyle, }) => ( handleOnLongPress && handleOnLongPress()} disabled={!isClickable} onPress={() => handleOnPress && handleOnPress()} > - + {itemIndex && {itemIndex}} {text || username} {description && {description}} + {middleText && ( + + + {middleText} + + + )} {isHasRightItem && ( {rightText} diff --git a/src/components/basicUIElements/view/userListItem/userListItemStyles.js b/src/components/basicUIElements/view/userListItem/userListItemStyles.js index 661be7b69..e72cf5859 100644 --- a/src/components/basicUIElements/view/userListItem/userListItemStyles.js +++ b/src/components/basicUIElements/view/userListItem/userListItemStyles.js @@ -47,6 +47,7 @@ export default EStyleSheet.create({ rightWrapper: { textAlign: 'center', alignItems: 'center', + width: 80, }, text: { color: '$iconColor', @@ -68,4 +69,7 @@ export default EStyleSheet.create({ fontSize: 10, marginRight: 17, }, + middleWrapper: { + marginRight: 30, + }, }); diff --git a/src/components/leaderboard/container/leaderboardContainer.js b/src/components/leaderboard/container/leaderboardContainer.js index 9c9b8925b..7be2a9fd7 100644 --- a/src/components/leaderboard/container/leaderboardContainer.js +++ b/src/components/leaderboard/container/leaderboardContainer.js @@ -48,7 +48,7 @@ class LeaderboardContainer extends PureComponent { }); }; - _fetchLeaderBoard = async () => { + _fetchLeaderBoard = async selectedFilter => { const { intl, isConnected } = this.props; let users; @@ -57,7 +57,7 @@ class LeaderboardContainer extends PureComponent { this.setState({ refreshing: true }); try { - users = await getLeaderboard(); + users = await getLeaderboard(selectedFilter); } catch (error) { Alert.alert( intl.formatMessage({ id: 'alert.error' }), diff --git a/src/components/leaderboard/view/leaderboardStyles.js b/src/components/leaderboard/view/leaderboardStyles.js index 98d213c31..a3d240fcc 100644 --- a/src/components/leaderboard/view/leaderboardStyles.js +++ b/src/components/leaderboard/view/leaderboardStyles.js @@ -5,12 +5,29 @@ export default EStyleSheet.create({ flex: 1, padding: 8, }, - text: { + title: { color: '$primaryDarkGray', fontSize: 14, fontWeight: 'bold', marginLeft: 20, fontFamily: '$primaryFont', paddingBottom: 10, + flexGrow: 1, + }, + rewardText: { + color: '$primaryBlue', + }, + columnTitleWrapper: { + flexDirection: 'row', + marginTop: 10, + justifyContent: 'flex-end', + }, + columnTitle: { + color: '$primaryDarkGray', + fontSize: 12, + fontWeight: 'bold', + marginRight: 40, + marginBottom: 10, + fontFamily: '$primaryFont', }, }); diff --git a/src/components/leaderboard/view/leaderboardView.js b/src/components/leaderboard/view/leaderboardView.js index 0d471e90e..0ba7ed7dd 100644 --- a/src/components/leaderboard/view/leaderboardView.js +++ b/src/components/leaderboard/view/leaderboardView.js @@ -1,11 +1,12 @@ -import React, { PureComponent } from 'react'; +import React, { PureComponent, Fragment } from 'react'; import { View, FlatList, Text } from 'react-native'; import { injectIntl } from 'react-intl'; import get from 'lodash/get'; // Components import { UserListItem, ListPlaceHolder } from '../../basicUIElements'; - +import { FilterBar } from '../../filterBar'; +import FILTER_OPTIONS, { VALUE } from '../../../constants/options/leaderboard'; // Styles import styles from './leaderboardStyles'; @@ -28,9 +29,11 @@ class LeaderboardView extends PureComponent { isHasRightItem isClickable isBlackRightColor - rightText={get(item, 'count')} + rightText={get(item, 'points')} + middleText={get(item, 'count')} itemIndex={index + 1} handleOnPress={() => handleOnUserPress(get(item, '_id'))} + rightTextStyle={styles.rewardText} /> ); }; @@ -39,22 +42,37 @@ class LeaderboardView extends PureComponent { const { users, intl, fetchLeaderBoard, refreshing } = this.props; return ( - - - {intl.formatMessage({ - id: 'notification.leaderboard_title', - })} - - get(item, '_id', Math.random()).toString()} - removeClippedSubviews={false} - ListEmptyComponent={} - onRefresh={() => fetchLeaderBoard()} - renderItem={({ item, index }) => this._renderItem(item, index)} + + fetchLeaderBoard(FILTER_OPTIONS[selectedIndex])} /> - + + + + + {intl.formatMessage({ + id: 'notification.leaderboard_title', + })} + + Activities + Reward + + + get(item, '_id', Math.random()).toString()} + removeClippedSubviews={false} + ListEmptyComponent={} + onRefresh={() => fetchLeaderBoard()} + renderItem={({ item, index }) => this._renderItem(item, index)} + /> + + ); } } diff --git a/src/constants/options/leaderboard.js b/src/constants/options/leaderboard.js new file mode 100644 index 000000000..d9081c929 --- /dev/null +++ b/src/constants/options/leaderboard.js @@ -0,0 +1,3 @@ +export default ['day', 'week', 'month']; + +export const VALUE = ['Daily', 'Weekly', 'Montly']; diff --git a/src/providers/esteem/esteem.js b/src/providers/esteem/esteem.js index b20843e73..ff2b3b3cd 100644 --- a/src/providers/esteem/esteem.js +++ b/src/providers/esteem/esteem.js @@ -131,7 +131,10 @@ export const addFavorite = (currentUsername, targetUsername) => export const removeFavorite = (currentUsername, targetUsername) => api.delete(`/favoriteUser/${currentUsername}/${targetUsername}`); -export const getLeaderboard = () => api.get('/leaderboard').then(resp => resp.data); +export const getLeaderboard = duration => + api.get('/leaderboard', { params: { duration } }).then(resp => { + return resp.data; + }); export const getActivities = data => new Promise((resolve, reject) => {