Skip to content

Commit b308b6f

Browse files
authored
Merge pull request #300 from JEOLLOGA/feat/#299/popular-stay-v2
[FEAT] ์ธ๊ธฐ ํ…œํ”Œ์Šคํ…Œ์ด api v2 ์ „ํ™˜
2 parents 1fc101a + 5228ad1 commit b308b6f

File tree

8 files changed

+44
-47
lines changed

8 files changed

+44
-47
lines changed

โ€Žnext.config.tsโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const withVanillaExtract = createVanillaExtractPlugin();
66
const nextConfig: NextConfig = {
77
reactStrictMode: true,
88
images: {
9-
domains: ['noms.templestay.com'],
9+
domains: ['noms.templestay.com', 'www.templestay.com'],
1010
},
1111
webpack(config) {
1212
config.module.rules.push({

โ€Žsrc/apis/ranking/axios.tsโ€Ž

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { getAxiosInstance } from '@apis/instance';
1+
import instance from '@apis/instance';
22

3-
const getRanking = async (userId: number | null) => {
4-
const axiosInstance = getAxiosInstance();
3+
const getRanking = async () => {
4+
const res = await instance.get('/v2/api/templestay/recommendation');
55

6-
const res = await axiosInstance.get('/ranking', {
7-
params: { userId },
8-
});
96
return res.data;
107
};
118

โ€Žsrc/apis/ranking/index.tsโ€Ž

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import getRanking from '@apis/ranking/axios';
22
import { RankingResponse } from '@apis/ranking/type';
3+
import { ApiResponse } from '@apis/response';
34
import { useQuery } from '@tanstack/react-query';
45

5-
const useGetRanking = (userId: number | null) => {
6-
const { data, isLoading, isError } = useQuery<RankingResponse>({
7-
queryKey: ['ranking', userId],
8-
queryFn: () => getRanking(userId),
6+
const useGetRanking = () => {
7+
const { data, isLoading, isError } = useQuery({
8+
queryKey: ['ranking'],
9+
queryFn: () => getRanking(),
10+
select: (res: ApiResponse<RankingResponse>) => res.data.recommendTemplestays,
911
});
1012

1113
return { data, isLoading, isError };

โ€Žsrc/apis/ranking/type.tsโ€Ž

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
// api ๊ด€๋ จ interface ๋ฐ type ์ •๋ฆฌ
2-
31
export interface Temple {
4-
ranking: number;
5-
templestayId: number;
6-
templeName: string;
7-
tag: string;
8-
region: string;
9-
liked: boolean;
2+
id: number;
3+
rank: number;
4+
templestayName: string;
105
imgUrl: string;
6+
region: string;
7+
templeName: string;
8+
wish: boolean;
119
}
1210

1311
export interface RankingResponse {
14-
rankings: Temple[];
12+
recommendTemplestays: Temple[];
1513
}

โ€Žsrc/components/card/popularCard/PopularCard.tsxโ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import * as styles from './popularCard.css';
1010

1111
interface PopularCardProps {
1212
ranking: number;
13-
templeName: string;
13+
templestayName: string;
1414
templeLoc: string;
1515
templeImg: string;
16-
tag: string;
16+
templeName: string;
1717
isLiked?: boolean;
1818
onLikeToggle: (liked: boolean) => void;
1919
link: string;
2020
}
2121

2222
const PopularCard = ({
2323
ranking,
24-
templeName,
24+
templestayName,
2525
templeLoc,
2626
templeImg,
27-
tag,
27+
templeName,
2828
isLiked = false,
2929
onLikeToggle,
3030
link,
@@ -55,19 +55,19 @@ const PopularCard = ({
5555
<div className={styles.imgBox}>
5656
<Image
5757
src={templeImg}
58-
alt={`${templeName} ๋Œ€ํ‘œ ์ด๋ฏธ์ง€`}
58+
alt={`${templestayName} ๋Œ€ํ‘œ ์ด๋ฏธ์ง€`}
5959
fill
6060
style={{ objectFit: 'cover' }}
6161
/>
6262
<RankBtn ranking={ranking} />
6363
</div>
6464
<div className={styles.bottomWrapper}>
6565
<div className={styles.bottomContainer}>
66-
<h3 className={styles.templeName}>{templeName}</h3>
66+
<h3 className={styles.templestayName}>{templestayName}</h3>
6767
<div className={styles.bottomBox}>
6868
<span>{templeLoc}</span>
6969
<Icon.IcnDivider />
70-
<span>#{tag}</span>
70+
<span>{templeName}</span>
7171
</div>
7272
</div>
7373
<button className={styles.likeBtn} onClick={handleLikeClick}>

โ€Žsrc/components/card/popularCard/popularCard.css.tsโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const templeInfoBox = style({
1717
flexDirection: 'column',
1818
});
1919

20-
export const templeName = style({
20+
export const templestayName = style({
2121
...theme.FONTS.h3Sb18,
2222
textAlign: 'left',
2323
});

โ€Žsrc/components/carousel/popularCarousel/PopularCarousel.tsxโ€Ž

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ const PopularCarousel = ({ onRequireLogin }: PopularCarouselProps) => {
2121
const addWishlistMutation = useAddWishlist();
2222
const removeWishlistMutation = useRemoveWishlist();
2323

24-
const { data, isLoading, isError } = useGetRanking(userId);
24+
const { data, isLoading, isError } = useGetRanking();
2525

2626
const { currentIndex, carouselRef, transformStyle, handleDragChange, handleDragEnd } =
2727
useCarousel({
28-
itemCount: data?.rankings?.length || 0,
28+
itemCount: data?.length || 0,
2929
moveDistance: 355,
3030
});
3131

@@ -65,23 +65,23 @@ const PopularCarousel = ({ onRequireLogin }: PopularCarouselProps) => {
6565
onDragChange: handleDragChange,
6666
onDragEnd: handleDragEnd,
6767
})}>
68-
{data?.rankings &&
69-
data.rankings.map((rankings) => (
68+
{data &&
69+
data.map((temple) => (
7070
<PopularCard
71-
key={rankings.templestayId}
72-
ranking={rankings.ranking}
73-
templeName={rankings.templeName}
74-
templeLoc={rankings.region}
75-
templeImg={rankings.imgUrl}
76-
isLiked={rankings.liked}
77-
tag={rankings.tag}
78-
onLikeToggle={(liked: boolean) => handleLikeToggle(rankings.templestayId, liked)}
79-
link={`/detail/${rankings.templestayId}`}
71+
key={temple.id}
72+
ranking={temple.rank}
73+
templestayName={temple.templestayName}
74+
templeLoc={temple.region}
75+
templeImg={temple.imgUrl}
76+
isLiked={temple.wish}
77+
templeName={temple.templeName}
78+
onLikeToggle={(liked: boolean) => handleLikeToggle(temple.id, liked)}
79+
link={`/detail/${temple.id}`}
8080
/>
8181
))}
8282
</div>
8383
</div>
84-
<CarouselIndex total={data?.rankings?.length || 0} currentIndex={currentIndex} />
84+
<CarouselIndex total={data?.length || 0} currentIndex={currentIndex} />
8585
</section>
8686
);
8787
};

โ€Žsrc/stories/PopularCard.stories.tsโ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const meta = {
1212
ranking: {
1313
control: { type: 'number' },
1414
},
15-
templeName: {
15+
templestayName: {
1616
control: { type: 'text' },
1717
},
1818
templeLoc: {
@@ -21,7 +21,7 @@ const meta = {
2121
templeImg: {
2222
control: { type: 'text' },
2323
},
24-
tag: {
24+
templeName: {
2525
control: { type: 'text' },
2626
},
2727

@@ -34,11 +34,11 @@ const meta = {
3434
},
3535
args: {
3636
ranking: 1,
37-
templeName: '๋ด‰์€์‚ฌ',
38-
templeLoc: '์„œ์šธ',
37+
templestayName: '๋ด‰์„ ์‚ฌ ์‚ฌ๋ถ€๋Œ€์ค‘๊ณผ ํ•จ๊ป˜ํ•˜๋Š” ์„ ๋ช…์ƒ',
38+
templeLoc: '๊ฒฝ๊ธฐ',
3939
templeImg:
4040
'https://img.danawa.com/images/descFiles/6/110/5109431_agiLaciMHn_1659098198501.jpeg',
41-
tag: '๋ฐฉ๊ธ‹๋ฐฉ๊ธ‹',
41+
templeName: '๋ด‰์„ ์‚ฌ',
4242
link: 'https://www.gototemplestay.com/',
4343
isLiked: false,
4444
onLikeToggle: () => alert('Liked'),

0 commit comments

Comments
ย (0)