Skip to content

Commit 6f654dc

Browse files
committed
feat(concerts-list) : 공연 총 개수 조회 api 연결
1 parent 9c5f14f commit 6f654dc

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/components/concert/list/ConcertListContent.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ConcertData } from "@/components/concert/ConcertType";
66
import ListSortClient from "@/components/concert/list/ListSortClient";
77
import { useCallback, useEffect, useRef, useState } from "react";
88
import { toast } from "sonner";
9+
import { totalConcertCount } from "@/lib/api/concerts";
910

1011
export default function ConcertListContent({
1112
initialList,
@@ -17,6 +18,7 @@ export default function ConcertListContent({
1718
const [concertsList, setConcertsList] = useState(initialList);
1819
const [hasMore, setHasMore] = useState(true);
1920
const [loading, setLoading] = useState(false);
21+
const [totalCount, setTotalCount] = useState<number | null>(null);
2022

2123
const oTarget = useRef(null);
2224
const pageRef = useRef(1); // 0 시작 이므로
@@ -83,12 +85,25 @@ export default function ConcertListContent({
8385
setLoading(false);
8486
}, [initialList, sortType]);
8587

88+
useEffect(() => {
89+
const fetchTotalCount = async () => {
90+
const count = await totalConcertCount();
91+
if (count !== null) {
92+
setTotalCount(count);
93+
}
94+
};
95+
96+
fetchTotalCount();
97+
}, []);
98+
8699
return (
87100
<section className="px-15 py-16">
88101
<div className={twMerge(`mx-auto flex w-full max-w-400 flex-col gap-9`)}>
89102
<div className="header flex items-center justify-between">
90103
<div className="flex items-center gap-2">
91-
<span className="text-text-main text-2xl font-bold">{concertsList.length}</span>
104+
<span className="text-text-main text-2xl font-bold">
105+
{totalCount ?? concertsList.length}
106+
</span>
92107
<span className="text-text-main text-lg">items</span>
93108
</div>
94109
<ListSortClient />

src/lib/api/concerts.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,22 @@ export const getIsLikedConcert = async (
206206
return null;
207207
}
208208
};
209+
210+
// 공연 리스트 - 전체 공연 수 불러오기
211+
export const totalConcertCount = async () => {
212+
try {
213+
const res = await ClientApi(`/api/v1/concerts/totalConcertCount`, {
214+
method: "GET",
215+
cache: "no-store",
216+
});
217+
if (!res.ok) {
218+
console.error("API Error:", res.status, res.statusText);
219+
return null;
220+
}
221+
const data = await res.json();
222+
return data.data;
223+
} catch (error) {
224+
console.error("Error fetching users detail:", error);
225+
return null;
226+
}
227+
};

0 commit comments

Comments
 (0)