-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 2 commits
85192db
f61cf18
6060bad
046b809
e458d4a
3fea2a3
715a29d
9c697c2
ae2c9ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import {TouchableOpacity} from 'react-native'; | ||
import Icon from 'react-native-vector-icons/AntDesign'; | ||
import {CommonResponseType} from '@/types/CommonResponseType'; | ||
import apiClient from '@/apis/ApiClient'; | ||
|
||
type SubscribeIconProps = { | ||
marketIsLiked: boolean; | ||
marketId?: number; | ||
handleSubscribe: () => void; | ||
}; | ||
|
||
const SubscribeIcon = ({ | ||
marketIsLiked, | ||
marketId, | ||
handleSubscribe, | ||
}: SubscribeIconProps) => { | ||
const handleLikePress = async () => { | ||
try { | ||
let res; | ||
if (marketIsLiked) { | ||
console.log('DEL'); | ||
res = await apiClient.del<CommonResponseType | null>( | ||
`/market/${marketId}/like`, | ||
); | ||
} else { | ||
console.log('POST'); | ||
res = await apiClient.post<CommonResponseType | null>( | ||
`/market/${marketId}/like`, | ||
); | ||
} | ||
handleSubscribe(); | ||
return res; | ||
} catch (error) { | ||
console.error('Error subscribe', error); | ||
return null; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 각 서버에 요청을 보내는 코드들은 apis/ 폴더 아래에 파일을 선언해서 추가해주세요. + javascript에서 빈 객체( ![]() + 카톡으로 상민이형이랑 나눈 api endpoint관련해서는 확정되면 그렇게 수정하시죠. |
||
}; | ||
|
||
return ( | ||
<TouchableOpacity onPress={handleLikePress}> | ||
<Icon name={marketIsLiked ? 'heart' : 'hearto'} size={24} /> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
export default SubscribeIcon; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type CommonResponseType = { | ||
code: number; | ||
message: string; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response 타입까지 알 필요는 없을 것 같아요. 그래도 강력한 타입을 지원하려면 apiClient에서 선언하는 rest method의 구현에서 사용할 수는 있을 것 같습니다. // CommonResponseType.ts
export type CommonResponseType<T> = {
code: number;
message: string;
data?: T;
}; // ApiClient.ts
const get = async <T>(url: string): Promise<T | null> => {
try {
const res: AxiosResponse<CommonResponseType<T>> = await this.axiosInstance.get(url);
if (res.data.code === 200 && res.data.data) {
return res.data.data;
}
return null;
} catch (error) {
console.error(error);
return null;
}
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,7 @@ export type MarketType = { | |
address: string; | ||
products: ProductType[]; | ||
images: string[]; | ||
isLike: boolean; | ||
// TODO: 논의 필요 | ||
marketId?: number; | ||
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. id는 아마도 string 일것같아요 |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅