Skip to content

Commit

Permalink
fix(AWCRankingPage): sort issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ppapman1 committed Dec 18, 2022
1 parent c138378 commit c204320
Showing 1 changed file with 15 additions and 70 deletions.
85 changes: 15 additions & 70 deletions src/routes/awc2023/AWCRankingPage.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { useEffect, useReducer, useState } from 'react';
import InfiniteScroll from 'react-infinite-scroll-component';
import SectionTitle from '../../components/global/SectionTitle';
import styled from 'styled-components';
import axios from 'axios';
import { useLocation } from 'react-router-dom';

const apiEndpoint = 'https://api.awc.enak.kr/players';
const apiEndpoint = 'https://api.awc.enak.kr/measure/rank';

const RankingItemBox = styled.div`
display: flex;
Expand Down Expand Up @@ -127,11 +126,7 @@ const RankingItem = ({ rank, playerName, hitMargins, xAccuracy }) => {
label='Multipress'
content={hitMargins[7]}
/>
<ItemHitMargin
color='#C983E2'
label='Miss'
content={hitMargins[8]}
/>
<ItemHitMargin color='#C983E2' label='Miss' content={hitMargins[8]} />
<ItemHitMargin
color='#C983E2'
label='Overload'
Expand Down Expand Up @@ -181,18 +176,6 @@ const AWCRankingPage = () => {
isError: action.error ? true : false
};

case 'HAS_MORE_ITEMS':
return {
...state,
hasMore: action.hasMore
};

case 'ITEM_COUNT':
return {
...state,
itemCount: action.itemCount
};

default:
return state;
}
Expand All @@ -202,8 +185,6 @@ const AWCRankingPage = () => {
isLoading: false,
error: null,
isError: false,
hasMore: true,
itemCount: 0,
items: null
});

Expand All @@ -216,16 +197,11 @@ const AWCRankingPage = () => {

const response = await axios.get(apiEndpoint, {
params: {
page: 0,
size: 30
limit: 800
}
});

dispatch({ type: 'FETCH_RESULT', items: response.data.data.content });
dispatch({
type: 'ITEM_COUNT',
itemCount: response.data.data.totalElements
});
dispatch({ type: 'FETCH_RESULT', items: response.data.data });
} catch (e) {
dispatch({ type: 'FETCH_ERROR', error: e });
}
Expand All @@ -234,55 +210,24 @@ const AWCRankingPage = () => {
fetchData();
}, []);

const fetchMoreData = async () => {
if (state.items.length >= state.itemCount) {
dispatch({ type: 'HAS_MORE_RANKING', hasMore: false });
return;
}

try {
dispatch({ type: 'FETCH_ERROR', error: null });

const response = await axios.get(apiEndpoint, {
params: {
offset: state.items.length,
amount: 30
}
});

dispatch({
type: 'FETCH_RESULT',
items: state.items.concat(response.data.data.content)
});
} catch (e) {
dispatch({ type: 'FETCH_ERROR', error: e });
}
};

return (
<main>
<SectionTitle>AWC 2023 Qualifiers Leaderboard</SectionTitle>

{state.isError ? (
<h2 style={{ margin: 0, marginTop: 12 }}>Oops! An error occurred.</h2>
) : state.isLoading ? null : !state.items ? null : (
<InfiniteScroll
dataLength={state.items.length}
next={fetchMoreData}
hasMore={state.hasMore}
>
{state.items.map((i, index) => {
return (
<RankingItem
rank={index}
playerName={showAsId ? i.playerId : i.playerName}
hitMargins={i.hitMargins}
xAccuracy={i.xacc}
key={index}
/>
);
})}
</InfiniteScroll>
state.items.map((i, index) => {
return (
<RankingItem
rank={index}
playerName={showAsId ? i.playerId : i.playerName}
hitMargins={i.hitMargins}
xAccuracy={i.xacc}
key={index}
/>
);
})
)}
</main>
);
Expand Down

0 comments on commit c204320

Please sign in to comment.