diff --git a/source/component/ShopDetail.js b/source/component/ShopDetail.js index 74f1eca..a912a7a 100644 --- a/source/component/ShopDetail.js +++ b/source/component/ShopDetail.js @@ -25,7 +25,7 @@ import theme from '../Theme.js'; * } */ const ShopDetail = ({Id, setId}) => { - const data = { + const initialData = { id: '1', title: 'The 5th Wave', location: '서울시 동작구 상도로 369', @@ -39,15 +39,20 @@ const ShopDetail = ({Id, setId}) => { }, ], starRate: 4.5, - reviews: [], + reviews: [ + {writer: 'hoyeon', content: 'good', starRate: 5}, + {writer: 'hoyeon', content: '맛있네요', starRate: 3}, + ], }; - const starRateRounded = Math.round(data.starRate); - - const starRateString = '⭐'.repeat(starRateRounded); + const [data, setData] = useState(initialData); const [command, setCommand] = useState(''); + const [isAddReview, setIsAddReview] = useState(false); + const [currentReview, setCurrentReview] = useState(''); + const [currentRate, setCurrentRate] = useState(1); + const onCommandSubmit = () => { if (command === ':q') { setId(0); @@ -55,6 +60,7 @@ const ShopDetail = ({Id, setId}) => { if (command === ':ar') { // TODO : add review setCommand(''); + setIsAddReview(true); } if (command === ':lm') { // TODO : load more reviews @@ -64,6 +70,74 @@ const ShopDetail = ({Id, setId}) => { setCommand(''); }; + useInput((input, key) => { + if (isAddReview) { + if (key.upArrow && currentRate < 5) { + setCurrentRate(prevRate => prevRate + 1); + } else if (key.downArrow && currentRate > 1) { + setCurrentRate(prevRate => prevRate - 1); + } + } + }); + + const onReivewSubmit = () => { + // TODO : add review + setIsAddReview(false); + const updatedReviews = [ + ...data.reviews, + { + writer: 'hoyeon', + content: currentReview, + starRate: currentRate, + }, + ]; + + setData({...data, reviews: updatedReviews}); + setCurrentReview(''); + setCurrentRate(1); + }; + + return ( + <> + + {!isAddReview ? ( + <> + Commands + + :q - quit + + :lm - load more reviews + + :ar - add review + + + + ) : ( + <> + + + + {currentRate} + + ⬆️ / ⬇️ to set rating + + + )} + + ); +}; + +const ShopView = ({data}) => { + const starRateString = '⭐'.repeat(Math.round(data.starRate)); + return ( <> {'{'} @@ -109,7 +183,7 @@ const ShopDetail = ({Id, setId}) => { "reviews" : {'['} - {data.reviews.length == !0 ? : <>} + {data.reviews.length ? : <>} {data.reviews.map((item, index, array) => ( {' '} @@ -123,20 +197,8 @@ const ShopDetail = ({Id, setId}) => { {'}'} - Commands - - :q - quit - - :lm - load more reviews - - :ar - add review - - ); }; + export default ShopDetail;