Merge pull request #2309 from ecency/nt/leaderboad-improve

Nt/leaderboad improve
This commit is contained in:
Feruz M 2022-05-21 11:46:09 +03:00 committed by GitHub
commit 7c1661f5f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -8,7 +8,7 @@ import { connect } from 'react-redux';
import { getLeaderboard } from '../../../providers/ecency/ecency';
// Constants
import ROUTES from '../../../constants/routeNames';
import FILTER_OPTIONS, { VALUE } from '../../../constants/options/leaderboard';
// Component
import LeaderboardView from '../view/leaderboardView';
@ -50,6 +50,7 @@ class LeaderboardContainer extends PureComponent {
if (index === undefined) {
index = selectedIndex;
selectedFilter = FILTER_OPTIONS[selectedIndex];
}
let users;

View File

@ -9,6 +9,7 @@ import { FilterBar } from '../../filterBar';
import FILTER_OPTIONS, { VALUE } from '../../../constants/options/leaderboard';
// Styles
import styles from './leaderboardStyles';
import EmptyScreenView from '../../basicUIElements/view/emptyScreen/emptyScreenView';
class LeaderboardView extends PureComponent {
/* Props
@ -40,6 +41,11 @@ class LeaderboardView extends PureComponent {
);
};
_renderEmptyView = () => {
const { refreshing } = this.props;
return <>{refreshing ? <ListPlaceHolder /> : <EmptyScreenView />}</>;
};
render() {
const { users, intl, fetchLeaderBoard, refreshing, selectedIndex } = this.props;
return (
@ -70,7 +76,7 @@ class LeaderboardView extends PureComponent {
refreshing={refreshing}
keyExtractor={(item) => get(item, '_id', Math.random()).toString()}
removeClippedSubviews={false}
ListEmptyComponent={<ListPlaceHolder />}
ListEmptyComponent={this._renderEmptyView}
onRefresh={() => fetchLeaderBoard()}
renderItem={this._renderItem}
contentContainerStyle={styles.listContentContainer}

View File

@ -8,6 +8,7 @@ import { parsePost } from '../../utils/postParser';
import { extractMetadata, makeJsonMetadata } from '../../utils/editor';
import { CommentHistoryItem, LatestMarketPrices, ReceivedVestingShare, Referral, ReferralStat } from './ecency.types';
import { convertCommentHistory, convertLatestQuotes, convertReferral, convertReferralStat } from './converters';
import { isArray } from 'lodash';
@ -394,9 +395,15 @@ export const getFragments = async () => {
export const getLeaderboard = async (duration:'day'|'week'|'month') => {
try{
const response = await ecencyApi.get(`private-api/leaderboard/${duration}`)
return response.data;
const rawData = response.data;
if(!rawData || !isArray(rawData)){
throw new Error('Invalid response returned');
}
return rawData;
} catch(error) {
bugsnagInstance.notify(error)
throw error;
}
}