From 3225d02bf42e1df017602e1998002c58643415e6 Mon Sep 17 00:00:00 2001 From: MinSeo <138097126+m1nse0kim@users.noreply.github.com> Date: Sat, 1 Jun 2024 22:05:46 +0900 Subject: [PATCH] =?UTF-8?q?[KAN-131]=20=EA=B0=80=EA=B2=8C=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EB=A6=AC=EB=B7=B0=20UI=20=EA=B0=9C=EC=84=A0=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=94=EB=89=B4=20=EA=B8=B0=EB=B3=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=B2=98=EB=A6=AC=20(#46)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/svg.js | 16 +- src/screens/detail/StoreDetailScreen.js | 209 +++++++++++++++--------- 2 files changed, 143 insertions(+), 82 deletions(-) diff --git a/src/assets/svg.js b/src/assets/svg.js index d925661..c908643 100644 --- a/src/assets/svg.js +++ b/src/assets/svg.js @@ -144,7 +144,7 @@ export const svgXml = { starEmpty: ` - + `, shop: ` @@ -412,5 +412,19 @@ export const svgXml = { `, + thumbupOn: ` + + + + + + `, + thumbupOff: ` + + + + + + `, }, }; diff --git a/src/screens/detail/StoreDetailScreen.js b/src/screens/detail/StoreDetailScreen.js index 899b79a..db4fdaf 100644 --- a/src/screens/detail/StoreDetailScreen.js +++ b/src/screens/detail/StoreDetailScreen.js @@ -96,7 +96,7 @@ export default function StoreDetailScreen(props) { const data = response.data.data; const dataReview = responseReview.data.data; - console.log('Restaurant heart:', data.restaurant); + console.log('storedata: ', data); setRestaurant(data); setIsHearted(data.restaurant.isLike); @@ -139,6 +139,38 @@ export default function StoreDetailScreen(props) { Alert.alert('클립보드에 복사되었습니다.'); } + const handleReviewLikedState = async (review) => { + try { + const newReviewLikedState = !review.item.isLike; + const updatedReviewList = reviewList.map((item) => + item.id === review.item.id + ? { ...item, isLike: newReviewLikedState, likeCount: newReviewLikedState ? item.likeCount + 1 : item.likeCount - 1 } + : item + ); + setReviewList(updatedReviewList); + const ret = await axios.post( + `${API_URL}/v1/restaurants/reviews/${review.item.id}/like`, + { + isLike: newReviewLikedState, + }, + { + headers: {Authorization: `Bearer ${context.accessToken}`}, + }, + ); + + console.log('isReviewLike: ', ret.data); + } catch (error) { + console.error('Error updating review liked:', error); + + const rollbackReviewList = reviewList.map((item) => + item.id === review.item.id + ? { ...item, isLike: review.item.isLike, likeCount: review.item.likeCount } + : item + ); + setReviewList(rollbackReviewList); + } + } + const handleLoadMoreMenus = () => { setMenuCount(menuCount + 4); }; @@ -154,35 +186,24 @@ export default function StoreDetailScreen(props) { const renderMenuItem = ({item}) => ( <> - {item.imageUrl ? ( - <> - - - - ) : ( - - - 음식 사진 준비중 - + + - )} + {item.name} {item.description} @@ -196,7 +217,8 @@ export default function StoreDetailScreen(props) { const renderReviewItem = ({item}) => { const rating = item.rating; const likeCount = item.likeCount; - const viewCount = item.viewCount; + + console.log("review: ", item); const renderStars = () => { const stars = []; @@ -236,30 +258,47 @@ export default function StoreDetailScreen(props) { )} {item.username} + handleReviewLikedState({item})}> + + {`좋아요 ${likeCount}`} {renderStars()} - {item.content} + + + {item.imageUrls.length > 0 ? ( + <> + {item.content} + ( + + )} + keyExtractor={(image, index) => `${item.id}-${index}`} + /> + + ) : ( + <> + {item.content} + + )} + + - ( - - )} - keyExtractor={(image, index) => `${item.id}-${index}`} - /> ); @@ -269,24 +308,24 @@ export default function StoreDetailScreen(props) { <> - - + + @@ -378,12 +417,14 @@ export default function StoreDetailScreen(props) { width={24} height={24} /> - - 위치: {restaurant.restaurant.detailInfo.address} - - {onCopy(restaurant.restaurant.detailInfo.address)}}> - 복사 - + + + 위치: {restaurant.restaurant.detailInfo.address} + + {onCopy(restaurant.restaurant.detailInfo.address)}}> + 복사 + +