Skip to content

Commit 2aeed1a

Browse files
authored
�feat: 가게 세부 페이지 찜버튼 추가 (#68)
* feat: 가게 세부 페이지 찜버튼 추가 * style: 타입 파일 폴더 이동 * fix: api 코드 분리 * fix: tsc error * fix: tsc error number to string * fix: 찜 api 통합 대응 * fix: 미사용 더미 삭제 * fix: CommonResponseType.ts 삭제
1 parent e3268a9 commit 2aeed1a

File tree

8 files changed

+69
-127
lines changed

8 files changed

+69
-127
lines changed

ios/ClientApp.xcworkspace/xcshareddata/swiftpm/Package.resolved

-123
This file was deleted.

src/apis/Login.ts

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const signInWithKakao = async (): Promise<SessionType | null> => {
127127
if (response) {
128128
console.log('카카오 로그인 성공:', response);
129129
return {
130+
//TODO: JWT 토큰으로 대체 필요
130131
accessToken: token.accessToken,
131132
refreshToken: token.refreshToken,
132133
accessTokenExpiresAt: new Date(token.accessTokenExpiresAt).getTime(),

src/apis/Market.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {MarketType} from '@/types/Market';
22
import apiClient from './ApiClient';
3-
43
export const getMarketList = async (
54
cursorId: number = 0,
65
size: number = 10,
@@ -38,3 +37,16 @@ export const getMarket = async (
3837
return null;
3938
}
4039
};
40+
41+
export const updateMarketLike = async (marketId: number): Promise<boolean> => {
42+
try {
43+
const res = await apiClient.post(`/markets/${marketId}/likes`);
44+
if (res) {
45+
return true;
46+
}
47+
return false;
48+
} catch (error) {
49+
console.error('Error in updateMarketLike:', error);
50+
return false;
51+
}
52+
};

src/apis/Subscribe.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export const getSubscribeList = async (
1212
const res = await apiClient.get<{
1313
markets: SubscribeType[];
1414
hasNext: boolean;
15-
} | null>(`/market/like?cursorId=${cursorId}&size=${size}`);
16-
console.log(res?.markets);
15+
} | null>(`/members/markets/likes`, {
16+
params: {cursorId, size},
17+
});
1718
return res;
1819
} catch (error) {
1920
console.error('Error Subscribed market list:', error);
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import {TouchableOpacity} from 'react-native';
3+
import Icon from 'react-native-vector-icons/AntDesign';
4+
import {updateMarketLike} from '@/apis';
5+
6+
type SubscribeIconProps = {
7+
marketIsLiked: boolean;
8+
marketId?: number;
9+
handleSubscribe: () => void;
10+
};
11+
12+
const SubscribeIcon = ({
13+
marketIsLiked,
14+
marketId,
15+
handleSubscribe,
16+
}: SubscribeIconProps) => {
17+
const handleLikePress = async () => {
18+
if (marketId !== undefined) {
19+
const response = await updateMarketLike(marketId);
20+
if (response) {
21+
handleSubscribe();
22+
}
23+
}
24+
};
25+
return (
26+
<TouchableOpacity onPress={handleLikePress}>
27+
<Icon name={marketIsLiked ? 'heart' : 'hearto'} size={24} />
28+
</TouchableOpacity>
29+
);
30+
};
31+
32+
export default SubscribeIcon;

src/screens/MarketDetailScreen/MarketDetailPage.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {ProductType} from '@/types/ProductType';
1616
import {useNavigation} from '@react-navigation/native';
1717
import {StackNavigationProp} from '@react-navigation/stack';
1818
import {RootStackParamList} from '@/types/StackNavigationType';
19+
import SubscribeIcon from '@/components/common/SubscribeIcon';
1920
import {BottomButton} from '@/components/common';
2021
type CartItem = {
2122
productId: number;
@@ -28,7 +29,9 @@ const MarketDetailPage = ({
2829
pickupEndAt,
2930
address,
3031
products,
31-
}: Omit<MarketType, 'id' | 'images'>) => {
32+
hasLike,
33+
id,
34+
}: Omit<MarketType, 'images'>) => {
3235
const navigation = useNavigation<StackNavigationProp<RootStackParamList>>();
3336
const [cart, setCart] = useState<CartItem[]>([]);
3437
const [selectedTag, setSelectedTag] = useState<string>('추천메뉴');
@@ -41,6 +44,7 @@ const MarketDetailPage = ({
4144
{},
4245
);
4346
const [tagWidths, setTagWidths] = useState<{[key: string]: number}>({});
47+
const [marketIsLiked, setMarketIsLiked] = useState<boolean>(hasLike);
4448
const scrollTimeoutRef = useRef<NodeJS.Timeout | null>(null);
4549
const handleCountChange = (productId: number, newCount: number) => {
4650
handleCart(
@@ -202,6 +206,9 @@ const MarketDetailPage = ({
202206
scrollToSection(tag);
203207
};
204208

209+
const handleSubscribe = () => {
210+
setMarketIsLiked(prevState => !prevState);
211+
};
205212
const navigatePage = () => {
206213
if (cart.length === 0) {
207214
Alert.alert('장바구니가 비어 있습니다.');
@@ -245,6 +252,13 @@ const MarketDetailPage = ({
245252
)} ~ ${format(pickupEndAt, 'HH시 mm분')}`}</S.MarketSideInfo>
246253
<S.MarketSideInfo>{address}</S.MarketSideInfo>
247254
</S.MarketSideInfoWrapper>
255+
<View>
256+
<SubscribeIcon
257+
marketIsLiked={marketIsLiked}
258+
marketId={id}
259+
handleSubscribe={handleSubscribe}
260+
/>
261+
</View>
248262
<S.SideTagBarScrollView
249263
horizontal
250264
showsHorizontalScrollIndicator={false}

src/screens/MarketDetailScreen/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ const MarketDetailScreen = ({navigation, route}: Props) => {
4040
return (
4141
<MarketDetailPage
4242
name={marketDetail.name}
43+
hasLike={marketDetail.hasLike}
4344
pickupStartAt={marketDetail.pickupStartAt}
4445
pickupEndAt={marketDetail.pickupEndAt}
4546
address={marketDetail.address}
4647
products={marketDetail.products}
48+
id={marketDetail.id}
4749
/>
4850
);
4951
};

src/types/Market.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ export type MarketType = {
88
address: string;
99
products: ProductType[];
1010
images: string[];
11+
hasLike: boolean;
12+
// TODO: 논의 필요
13+
marketId?: number;
1114
};

0 commit comments

Comments
 (0)