Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 가게 세부 페이지 찜버튼 추가 #68

Merged
merged 9 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 0 additions & 123 deletions ios/ClientApp.xcworkspace/xcshareddata/swiftpm/Package.resolved

This file was deleted.

1 change: 1 addition & 0 deletions src/apis/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const signInWithKakao = async (): Promise<SessionType | null> => {
if (response) {
console.log('카카오 로그인 성공:', response);
return {
//TODO: JWT 토큰으로 대체 필요
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accessToken: token.accessToken,
refreshToken: token.refreshToken,
accessTokenExpiresAt: new Date(token.accessTokenExpiresAt).getTime(),
Expand Down
14 changes: 13 additions & 1 deletion src/apis/Market.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {MarketType} from '@/types/Market';
import apiClient from './ApiClient';

export const getMarketList = async (
cursorId: number = 0,
size: number = 10,
Expand Down Expand Up @@ -38,3 +37,16 @@ export const getMarket = async (
return null;
}
};

export const updateMarketLike = async (marketId: number): Promise<boolean> => {
try {
const res = await apiClient.post(`/markets/${marketId}/likes`);
if (res) {
return true;
}
return false;
} catch (error) {
console.error('Error in updateMarketLike:', error);
return false;
}
};
5 changes: 3 additions & 2 deletions src/apis/Subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export const getSubscribeList = async (
const res = await apiClient.get<{
markets: SubscribeType[];
hasNext: boolean;
} | null>(`/market/like?cursorId=${cursorId}&size=${size}`);
console.log(res?.markets);
} | null>(`/members/markets/likes`, {
params: {cursorId, size},
});
return res;
} catch (error) {
console.error('Error Subscribed market list:', error);
Expand Down
32 changes: 32 additions & 0 deletions src/components/common/SubscribeIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import {TouchableOpacity} from 'react-native';
import Icon from 'react-native-vector-icons/AntDesign';
import {updateMarketLike} from '@/apis';

type SubscribeIconProps = {
marketIsLiked: boolean;
marketId?: number;
handleSubscribe: () => void;
};

const SubscribeIcon = ({
marketIsLiked,
marketId,
handleSubscribe,
}: SubscribeIconProps) => {
const handleLikePress = async () => {
if (marketId !== undefined) {
const response = await updateMarketLike(marketId);
if (response) {
handleSubscribe();
}
}
};
return (
<TouchableOpacity onPress={handleLikePress}>
<Icon name={marketIsLiked ? 'heart' : 'hearto'} size={24} />
</TouchableOpacity>
);
};

export default SubscribeIcon;
16 changes: 15 additions & 1 deletion src/screens/MarketDetailScreen/MarketDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {ProductType} from '@/types/ProductType';
import {useNavigation} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import {RootStackParamList} from '@/types/StackNavigationType';
import SubscribeIcon from '@/components/common/SubscribeIcon';
import {BottomButton} from '@/components/common';
type CartItem = {
productId: number;
Expand All @@ -28,7 +29,9 @@ const MarketDetailPage = ({
pickupEndAt,
address,
products,
}: Omit<MarketType, 'id' | 'images'>) => {
hasLike,
id,
}: Omit<MarketType, 'images'>) => {
const navigation = useNavigation<StackNavigationProp<RootStackParamList>>();
const [cart, setCart] = useState<CartItem[]>([]);
const [selectedTag, setSelectedTag] = useState<string>('추천메뉴');
Expand All @@ -41,6 +44,7 @@ const MarketDetailPage = ({
{},
);
const [tagWidths, setTagWidths] = useState<{[key: string]: number}>({});
const [marketIsLiked, setMarketIsLiked] = useState<boolean>(hasLike);
const scrollTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const handleCountChange = (productId: number, newCount: number) => {
handleCart(
Expand Down Expand Up @@ -202,6 +206,9 @@ const MarketDetailPage = ({
scrollToSection(tag);
};

const handleSubscribe = () => {
setMarketIsLiked(prevState => !prevState);
};
const navigatePage = () => {
if (cart.length === 0) {
Alert.alert('장바구니가 비어 있습니다.');
Expand Down Expand Up @@ -245,6 +252,13 @@ const MarketDetailPage = ({
)} ~ ${format(pickupEndAt, 'HH시 mm분')}`}</S.MarketSideInfo>
<S.MarketSideInfo>{address}</S.MarketSideInfo>
</S.MarketSideInfoWrapper>
<View>
<SubscribeIcon
marketIsLiked={marketIsLiked}
marketId={id}
handleSubscribe={handleSubscribe}
/>
</View>
<S.SideTagBarScrollView
horizontal
showsHorizontalScrollIndicator={false}
Expand Down
2 changes: 2 additions & 0 deletions src/screens/MarketDetailScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ const MarketDetailScreen = ({navigation, route}: Props) => {
return (
<MarketDetailPage
name={marketDetail.name}
hasLike={marketDetail.hasLike}
pickupStartAt={marketDetail.pickupStartAt}
pickupEndAt={marketDetail.pickupEndAt}
address={marketDetail.address}
products={marketDetail.products}
id={marketDetail.id}
/>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/types/Market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export type MarketType = {
address: string;
products: ProductType[];
images: string[];
hasLike: boolean;
// TODO: 논의 필요
marketId?: number;
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id는 아마도 string 일것같아요

};
Loading