Skip to content

Commit 9037874

Browse files
authored
Merge pull request #68 from SanjiJikFarm/feat/#39-homeAPI
2 parents 778b218 + 5b9a0f3 commit 9037874

File tree

8 files changed

+58
-22
lines changed

8 files changed

+58
-22
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { axiosInstance } from '../axios/axios';
2+
import { withErrorBoundary } from '../axios/axios';
3+
4+
/** 이번 달을 인자로 전달하면 탄소 절감량을 반환하는 함수 */
5+
export const getMonthlyCarbonAmount = (month) =>
6+
withErrorBoundary(async () => {
7+
const res = await axiosInstance.get('/carbon/monthly', {
8+
params: { month },
9+
});
10+
return res.data;
11+
});

sanjijikfarm/src/api/like/LikeController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { withErrorBoundary } from '../axios/axios';
44
/** 상품 아이디를 전달하면 찜 리스트에 추가하는 함수 */
55
export function likeProduct(productId) {
66
return withErrorBoundary(async () => {
7-
const res = await axiosInstance.post(`/products/${productId}/like`);
7+
const res = await axiosInstance.get(`/products/${productId}/like`);
88
return res.data;
99
});
1010
}

sanjijikfarm/src/api/profile/profile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ export const updateUserProfileImage = (newKey) =>
3838
});
3939
return res.data;
4040
});
41-

sanjijikfarm/src/components/common/review/ReviewCard.jsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,20 @@ export default function ReviewCard({ review }) {
55
return (
66
<div className="border-gray-1 flex w-full flex-col gap-3 border-b p-4">
77
<div className="flex flex-col gap-1">
8-
<span className="text-body-1 pl-0.5 font-bold">{review.name}</span>
9-
<span className="text-gray-7 text-body-2-med pl-0.5 font-medium">{DateFormatter(review.date)}</span>
8+
<span className="text-body-1 pl-0.5 font-bold">{review.productName}</span>
9+
<span className="text-gray-7 text-body-2-med pl-0.5 font-medium">{DateFormatter(review.createdAt)}</span>
1010
<div className="flex items-center pb-1">
1111
{Array.from({ length: 5 }).map((_, i) => (
1212
<ReviewStarIcon key={i} className={`${i < review.rating ? 'text-main-green' : 'text-gray-3'}`} />
1313
))}
1414
</div>
1515
<span className="bg-pale-green text-body-1 scrollbar-hide max-h-25 overflow-scroll p-2.5 font-medium">
16-
{review.content}
16+
{review.text}
1717
</span>
1818
</div>
19-
{review.reviewImages.length > 0 && (
20-
<div className="scrollbar-hide flex w-full gap-2 overflow-x-auto">
21-
{review.reviewImages.map((imgUrl, index) => (
22-
<div key={index} className="h-20 w-20 flex-shrink-0">
23-
<img className="bg-pale-green h-full w-full object-cover" src={imgUrl} alt={`review img ${index + 1}`} />
24-
</div>
25-
))}
26-
</div>
27-
)}
19+
<div className="h-20 w-20 flex-shrink-0">
20+
<img className="bg-pale-green h-full w-full object-cover" src={review.imageUrl} alt={`review img`} />
21+
</div>
2822
</div>
2923
);
3024
}

sanjijikfarm/src/components/feature/home/MainDecreaseAmount.jsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import { getMonthlyCarbonAmount } from '@/api/home/CarbonController';
14
import TreeIcon from '@/assets/icons/tree.svg';
25

3-
export default function MainDecreaseAmount({ amount }) {
6+
export default function MainDecreaseAmount({ month }) {
7+
const { data, isLoading, error } = useQuery({
8+
queryKey: ['monthlyReducedAmount', month],
9+
queryFn: () => getMonthlyCarbonAmount(month),
10+
enabled: !!month,
11+
staleTime: 1000 * 60,
12+
});
13+
14+
if (isLoading) {
15+
return (
16+
<div className="flex h-45 w-full p-4">
17+
<div className="border-main-green flex h-full w-full animate-pulse flex-col items-center justify-center gap-2 rounded-3xl border-2 bg-gray-100 p-7">
18+
<div className="flex items-center gap-3">
19+
<div className="bg-gray-3 h-6 w-40 rounded-md"></div>
20+
<div className="bg-gray-3 h-6 w-6 rounded-full"></div>
21+
</div>
22+
<div className="flex items-end gap-1">
23+
<div className="bg-gray-3 h-10 w-24 rounded-md"></div>
24+
<div className="bg-gray-3 h-8 w-12 rounded-md"></div>
25+
</div>
26+
</div>
27+
</div>
28+
);
29+
}
30+
31+
if (error) return <div>error</div>;
32+
433
return (
534
<div className="flex h-45 w-full p-4">
635
<div className="border-main-green flex h-full w-full flex-col items-center justify-center gap-2 rounded-3xl border-2 p-7">
736
<div className="flex items-center gap-3">
8-
<span className="text-heading-1 font-bold">이번주 탄소 절감량</span>
37+
<span className="text-heading-1 font-bold">이번달 탄소 절감량</span>
938
<TreeIcon />
1039
</div>
1140
<div className="flex items-end gap-1">
12-
<span className="text-title-0 text- text-main-green font-extrabold">{amount}kg</span>
41+
<span className="text-title-0 text- text-main-green font-extrabold">{data.totalSavedKg}kg</span>
1342
<span className="text-heading-1 font-bold">CO2</span>
1443
</div>
1544
</div>

sanjijikfarm/src/components/feature/localfood/map/Map.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export default function LocalfoodMap({ handleMarkerClick, center, setCenter }) {
1515
} = useQuery({
1616
queryKey: ['shopList'],
1717
queryFn: () => getShopList(),
18+
staleTime: 1000 * 60 * 60 * 24,
19+
cacheTime: Infinity,
20+
refetchOnWindowFocus: false,
21+
refetchOnMount: false,
22+
refetchInterval: false,
1823
});
1924

2025
useEffect(() => {

sanjijikfarm/src/pages/HomePage.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export default function HomePage() {
99
{ url: 'https://via.placeholder.com/600x300', main: 'Main Title', sub: 'Sub Title goes here' },
1010
];
1111

12-
const TEMP_DECREASE_AMOUNT = 50;
13-
1412
const month = new Date().getMonth();
1513

1614
return (
@@ -22,7 +20,7 @@ export default function HomePage() {
2220
<span className="text-heading-1 font-bold">{month + 1}월의 식재료 추천</span>
2321
<FoodSlider month={month + 1} />
2422
</div>
25-
<MainDecreaseAmount amount={TEMP_DECREASE_AMOUNT} />
23+
<MainDecreaseAmount month={month + 1} />
2624
</div>
2725
);
2826
}

sanjijikfarm/src/pages/MyLikesPage.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ export default function MyLikesPage() {
2626

2727
if (isLoading || isError) return;
2828

29-
const allProducts = data?.pages.flatMap((page) => page.contents) ?? [];
29+
const allProducts = data?.pages.flatMap((page) => page.content) ?? [];
3030

3131
return (
3232
<div className="flex h-full w-full">
3333
<div className="scrollbar-hide flex flex-grow flex-col overflow-scroll">
3434
{allProducts.length > 0 ? (
35-
allProducts.map((localfood) => <LikeLocalfoodCard key={localfood.id} localfood={localfood} />)
35+
allProducts.map((localfood) => <LikeLocalfoodCard key={localfood.productId} localfood={localfood} />)
3636
) : (
3737
<LocalfoodEmptyCard text="아직 찜한 메뉴가 없습니다." />
3838
)}

0 commit comments

Comments
 (0)