Skip to content

Commit

Permalink
feat: APIから取得したランキングの最大数をもとに、ページネーションの動作を制御する機能を実装
Browse files Browse the repository at this point in the history
  • Loading branch information
araaki12345 committed Apr 6, 2024
1 parent c117a41 commit d374685
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions typing-app/src/components/organism/RankingTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ const RankingTabs = () => {
const [rankingStartFrom, setRankingStartFrom] = useState(1);
const [sortBy, setSortBy] = useState<"accuracy" | "keystrokes">("accuracy");
const [error, setError] = useState<string | undefined>(undefined);
const [totalRankingCount, setTotalRankingCount] = useState<number>(0);

const LIMIT = 10;
const MAXIMUM = 100; // TODO: MAXIMUMをAPIから取得する
const MAXIMUM = totalRankingCount;

const fetchData = async () => {
const { data, error } = await client.GET("/scores/ranking", {
const { data } = await client.GET("/scores/ranking", {
params: {
query: {
sort_by: sortBy,
Expand All @@ -28,7 +29,8 @@ const RankingTabs = () => {
},
});
if (data) {
setScoreRankings(data);
setScoreRankings(data.rankings);
setTotalRankingCount(data.total_count);
} else {
setError("データの取得中にエラーが発生しました。");
}
Expand All @@ -40,6 +42,7 @@ const RankingTabs = () => {
const handleTabChange = (index: number) => {
const sortOption = index === 0 ? "accuracy" : "keystrokes";
setSortBy(sortOption);
setRankingStartFrom(1);
};

const handlePaginationClick = (direction: "next" | "prev") => {
Expand Down

0 comments on commit d374685

Please sign in to comment.