code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -1,14 +1,148 @@ -// ํ•„์ˆ˜ import React from 'react'; +import { Link } from 'react-router-dom'; -// ์ปดํฌ๋„ŒํŠธ import Nav from '../../../components/Nav/Nav'; +import Feed from '../Main/Feed/Feed'; +import OtherUserPro from './OtherUserPro/OtherUserPro'; +import FootLists from '../Main/Feed/FootLists/FootLists'; + +import './Main.scss'; class Main extends React.Component { + constructor() { + super(); + this.state = { + feedList: [], + }; + } + + componentDidMount() { + fetch('/data/soojeonglee/feedData.json') + .then(res => res.json()) + .then(data => { + this.setState({ + feedList: data, + }); + }); + } + render() { + // console.log(this.state.feedList); // ๋ฐ์ดํ„ฐ ํ™•์ธ์„ ์œ„ํ•œ ์ฝ˜์†” + const { feedList } = this.state; return ( - <div> + <div className="Main"> <Nav /> + <main> + <div className="feeds"> + {feedList.map(feed => { + return ( + <Feed + key={feed.id} + userName={feed.userName} + src={feed.src} + feedText={feed.feedText} + commentData={feed.commentData} + isLike={feed.isLike} + /> + ); + })} + </div> + <div className="main-right"> + <header className="userAccount"> + <h1> + <Link to="" className="userProfile mainRightProfile"></Link> + <Link to=""> + <strong>wecode_bootcamp</strong> + <span className="accountDec">WeCode - ์œ„์ฝ”๋“œ</span> + </Link> + </h1> + </header> + <aside className="asideBox storyAside"> + <header> + <h2>์Šคํ† ๋ฆฌ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + <ul className="storyUser"> + <OtherUserPro /> + </ul> + </aside> + + <aside className="asideBox recommandAside"> + <header> + <h2>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + + <ul className="recommandUser"> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user5.jpg" + /> + </Link> + <Link to=""> + limpack_official + <span className="followReco">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user6.jpg" + /> + </Link> + <Link to=""> + les_photos_de_cat + <span className="followReco"> + geee____nie๋‹˜ ์™ธ 1๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค. + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user7.jpg" + /> + </Link> + <Link to=""> + mornstar_nail + <span className="followReco"> + effie_yxz๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + </ul> + </aside> + <footer className="main-right-footer"> + <ul className="footList"> + <FootLists /> + </ul> + <span className="copyright">ยฉ 2021 INSTAGRAM FROM FACEBOOK</span> + </footer> + </div> + </main> </div> ); }
JavaScript
๋ฐ์ดํ„ฐ ํ™•์ธ ๋‹ค ํ•˜์…จ๋‚˜์š”~~?
@@ -1,14 +1,148 @@ -// ํ•„์ˆ˜ import React from 'react'; +import { Link } from 'react-router-dom'; -// ์ปดํฌ๋„ŒํŠธ import Nav from '../../../components/Nav/Nav'; +import Feed from '../Main/Feed/Feed'; +import OtherUserPro from './OtherUserPro/OtherUserPro'; +import FootLists from '../Main/Feed/FootLists/FootLists'; + +import './Main.scss'; class Main extends React.Component { + constructor() { + super(); + this.state = { + feedList: [], + }; + } + + componentDidMount() { + fetch('/data/soojeonglee/feedData.json') + .then(res => res.json()) + .then(data => { + this.setState({ + feedList: data, + }); + }); + } + render() { + // console.log(this.state.feedList); // ๋ฐ์ดํ„ฐ ํ™•์ธ์„ ์œ„ํ•œ ์ฝ˜์†” + const { feedList } = this.state; return ( - <div> + <div className="Main"> <Nav /> + <main> + <div className="feeds"> + {feedList.map(feed => { + return ( + <Feed + key={feed.id} + userName={feed.userName} + src={feed.src} + feedText={feed.feedText} + commentData={feed.commentData} + isLike={feed.isLike} + /> + ); + })} + </div> + <div className="main-right"> + <header className="userAccount"> + <h1> + <Link to="" className="userProfile mainRightProfile"></Link> + <Link to=""> + <strong>wecode_bootcamp</strong> + <span className="accountDec">WeCode - ์œ„์ฝ”๋“œ</span> + </Link> + </h1> + </header> + <aside className="asideBox storyAside"> + <header> + <h2>์Šคํ† ๋ฆฌ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + <ul className="storyUser"> + <OtherUserPro /> + </ul> + </aside> + + <aside className="asideBox recommandAside"> + <header> + <h2>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + + <ul className="recommandUser"> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user5.jpg" + /> + </Link> + <Link to=""> + limpack_official + <span className="followReco">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user6.jpg" + /> + </Link> + <Link to=""> + les_photos_de_cat + <span className="followReco"> + geee____nie๋‹˜ ์™ธ 1๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค. + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user7.jpg" + /> + </Link> + <Link to=""> + mornstar_nail + <span className="followReco"> + effie_yxz๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + </ul> + </aside> + <footer className="main-right-footer"> + <ul className="footList"> + <FootLists /> + </ul> + <span className="copyright">ยฉ 2021 INSTAGRAM FROM FACEBOOK</span> + </footer> + </div> + </main> </div> ); }
JavaScript
ํ”ผ์–ด ๋ฆฌ๋ทฐ ์ค‘ Return์˜ ๋น„๋ฐ€์„? ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
Boolean ๋ฐ์ดํ„ฐ ํƒ€์ž… ์ ์šฉ์‹œ์ผœ๋ณด์•˜์•„์š”. ์ž˜ ์„ธ์› ๋˜ ์ฝ”๋“œ๊ฐ€ ์ž‘๋™๋˜์ง€ ์•Š์„๊นŒ ์‹œ๋„ํ•˜๊ธฐ ์–ด๋ ค์› ๋Š”๋ฐ ๊ฒฉ๋ ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹น~
@@ -0,0 +1,61 @@ +.Login { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + + main { + display: flex; + flex-direction: column; + justify-content: space-around; + width: 350px; + height: 380px; + padding: 40px; + border: 1px solid #ccc; + + header { + h1 { + font-family: 'Lobster', cursive; + text-align: center; + } + } + + .loginInputBox { + form { + display: flex; + flex-direction: column; + justify-content: center; + + input { + margin-bottom: 5px; + padding: 9px 8px 7px; + background-color: rgb(250, 250, 250); + border: 1px solid rgb(38, 38, 38); + border-radius: 3px; + } + + .loginBtn { + margin-top: 10px; + padding: 9px 8px 7px; + border: none; + border-radius: 3px; + color: #fff; + background-color: #0096f6; + &:disabled { + background-color: #c0dffd; + } + } + } + } + + footer { + .findPassword { + display: block; + margin-top: 50px; + text-align: center; + color: #00376b; + font-size: 14px; + } + } + } +}
Unknown
๊ธฐ์กด html ์ฝ”๋“œ๋ฅผ ์˜ฎ๊ธฐ๋‹ค ๋ณด๋‹ˆ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์˜€์–ด์š” :) ํ•ด๊ฒฐ๋˜์—ˆ๋‹ต๋‹ˆ๋‹น !!
@@ -0,0 +1,134 @@ +[ + { + "id": 1, + "userName": "eessoo__", + "src": "../images/soojeongLee/user2.jpg", + "feedText": "๐Ÿ’Ÿ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "soojeonglee", + "content": "Hi there.", + "commnetLike": false + }, + { + "id": 3, + "userName": "jaehyunlee", + "content": "Hey.", + "commnetLike": false + }, + { + "id": 4, + "userName": "gyeongminlee", + "content": "Hi.", + "commnetLike": true + } + ], + "isLike": false + }, + { + "id": 2, + "userName": "zz_ing94", + "src": "../../images/soojeongLee/user3.jpg", + "feedText": "Toy story ๐Ÿ’š", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "jisuoh", + "content": "โœจ", + "commnetLike": true + }, + { + "id": 3, + "userName": "jungjunsung", + "content": "coffee", + "commnetLike": false + }, + { + "id": 4, + "userName": "somihwang", + "content": "ํฌํ‚ค", + "commnetLike": true + } + ], + "isLike": false + }, + { + "id": 3, + "userName": "hwayoonci", + "src": "../../images/soojeongLee/user4.jpg", + "feedText": "์˜ค๋Š˜์˜ ์ผ๊ธฐ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "yunkyunglee", + "content": "๊ท€์—ฌ์šด ์Šคํ‹ฐ์ปค", + "commnetLike": true + }, + { + "id": 3, + "userName": "summer", + "content": "๐Ÿถ", + "commnetLike": false + }, + { + "id": 4, + "userName": "uiyeonlee", + "content": "๐Ÿ‘๐Ÿป", + "commnetLike": true + } + ], + "isLike": true + }, + { + "id": 4, + "userName": "cosz_zy", + "src": "../../images/soojeongLee/user5.jpg", + "feedText": "1์ผ ํ™”๊ฐ€ ๐ŸŽจ ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "soojeonglee", + "content": "Hi there.", + "commnetLike": false + }, + { + "id": 3, + "userName": "jaehyunlee", + "content": "Hey.", + "commnetLike": true + }, + { + "id": 4, + "userName": "gyeongminlee", + "content": "Hi.", + "commnetLike": true + } + ], + "isLike": false + } +]
Unknown
fetching ์„ ์—ฐ์Šตํ•ด๋ณด๋ ค๊ณ  ๋งŒ๋“ค์–ด๋ณด์•˜์–ด์š”
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
์ธ์Šคํƒ€๊ทธ๋žจ์—์„œ ์‹ค์ œ ์ข‹์•„์š”๋ฅผ ์ข‹์•„ํ•œ ์ˆซ์ž์— ์ ‘๊ทผํ•˜๊ฒŒ ๋˜๋ฉด ๋ˆ„๊ฐ€ ์ข‹์•„์š”๋ฅผ ๋ˆŒ๋ €๋Š”์ง€ ๋ชฉ๋ก์„ ๋ณผ ์ˆ˜ ์žˆ์–ด์„œ, ์ถ”ํ›„์— ๊ธฐ๋Šฅ์„ ๋„ฃ๊ฒŒ ๋œ๋‹ค๋ฉด button์„ ๋„ฃ์–ด์•ผ ํ•˜์ง€ ์•Š์„๊นŒ ์ƒ๊ฐ์ด ๋“ค์–ด์„œ ๋„ฃ์–ด๋ดค์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,23 @@ +//๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +//์ปดํฌ๋„ŒํŠธ +import { FOOTLIST } from '../FootLists/footData'; + +// css +import './FootLists.scss'; + +export class FootLists extends Component { + render() { + return FOOTLIST.map(footlists => { + return ( + <Link to="" className="listDot" key={footlists.id}> + {footlists.footlist} + </Link> + ); + }); + } +} + +export default FootLists;
JavaScript
๊ผญ ํ’‹ ๋ฆฌ์ŠคํŠธ๋ฅผ... ์ปดํฌ๋„ŒํŠธํ™”ํ•ด๋ณด๊ฒ ์–ด์š”...!!!!
@@ -1,14 +1,148 @@ -// ํ•„์ˆ˜ import React from 'react'; +import { Link } from 'react-router-dom'; -// ์ปดํฌ๋„ŒํŠธ import Nav from '../../../components/Nav/Nav'; +import Feed from '../Main/Feed/Feed'; +import OtherUserPro from './OtherUserPro/OtherUserPro'; +import FootLists from '../Main/Feed/FootLists/FootLists'; + +import './Main.scss'; class Main extends React.Component { + constructor() { + super(); + this.state = { + feedList: [], + }; + } + + componentDidMount() { + fetch('/data/soojeonglee/feedData.json') + .then(res => res.json()) + .then(data => { + this.setState({ + feedList: data, + }); + }); + } + render() { + // console.log(this.state.feedList); // ๋ฐ์ดํ„ฐ ํ™•์ธ์„ ์œ„ํ•œ ์ฝ˜์†” + const { feedList } = this.state; return ( - <div> + <div className="Main"> <Nav /> + <main> + <div className="feeds"> + {feedList.map(feed => { + return ( + <Feed + key={feed.id} + userName={feed.userName} + src={feed.src} + feedText={feed.feedText} + commentData={feed.commentData} + isLike={feed.isLike} + /> + ); + })} + </div> + <div className="main-right"> + <header className="userAccount"> + <h1> + <Link to="" className="userProfile mainRightProfile"></Link> + <Link to=""> + <strong>wecode_bootcamp</strong> + <span className="accountDec">WeCode - ์œ„์ฝ”๋“œ</span> + </Link> + </h1> + </header> + <aside className="asideBox storyAside"> + <header> + <h2>์Šคํ† ๋ฆฌ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + <ul className="storyUser"> + <OtherUserPro /> + </ul> + </aside> + + <aside className="asideBox recommandAside"> + <header> + <h2>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + + <ul className="recommandUser"> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user5.jpg" + /> + </Link> + <Link to=""> + limpack_official + <span className="followReco">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user6.jpg" + /> + </Link> + <Link to=""> + les_photos_de_cat + <span className="followReco"> + geee____nie๋‹˜ ์™ธ 1๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค. + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user7.jpg" + /> + </Link> + <Link to=""> + mornstar_nail + <span className="followReco"> + effie_yxz๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + </ul> + </aside> + <footer className="main-right-footer"> + <ul className="footList"> + <FootLists /> + </ul> + <span className="copyright">ยฉ 2021 INSTAGRAM FROM FACEBOOK</span> + </footer> + </div> + </main> </div> ); }
JavaScript
๋„ค..! ๋ฌด์—‡์ด ์–ด๋””์— ์ „๋‹ฌ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ๊ฐ€ ์–ด๋ ค์›Œ์„œ ๋„ฃ์–ด๋’€์–ด์š” ...!
@@ -1,14 +1,148 @@ -// ํ•„์ˆ˜ import React from 'react'; +import { Link } from 'react-router-dom'; -// ์ปดํฌ๋„ŒํŠธ import Nav from '../../../components/Nav/Nav'; +import Feed from '../Main/Feed/Feed'; +import OtherUserPro from './OtherUserPro/OtherUserPro'; +import FootLists from '../Main/Feed/FootLists/FootLists'; + +import './Main.scss'; class Main extends React.Component { + constructor() { + super(); + this.state = { + feedList: [], + }; + } + + componentDidMount() { + fetch('/data/soojeonglee/feedData.json') + .then(res => res.json()) + .then(data => { + this.setState({ + feedList: data, + }); + }); + } + render() { + // console.log(this.state.feedList); // ๋ฐ์ดํ„ฐ ํ™•์ธ์„ ์œ„ํ•œ ์ฝ˜์†” + const { feedList } = this.state; return ( - <div> + <div className="Main"> <Nav /> + <main> + <div className="feeds"> + {feedList.map(feed => { + return ( + <Feed + key={feed.id} + userName={feed.userName} + src={feed.src} + feedText={feed.feedText} + commentData={feed.commentData} + isLike={feed.isLike} + /> + ); + })} + </div> + <div className="main-right"> + <header className="userAccount"> + <h1> + <Link to="" className="userProfile mainRightProfile"></Link> + <Link to=""> + <strong>wecode_bootcamp</strong> + <span className="accountDec">WeCode - ์œ„์ฝ”๋“œ</span> + </Link> + </h1> + </header> + <aside className="asideBox storyAside"> + <header> + <h2>์Šคํ† ๋ฆฌ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + <ul className="storyUser"> + <OtherUserPro /> + </ul> + </aside> + + <aside className="asideBox recommandAside"> + <header> + <h2>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + + <ul className="recommandUser"> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user5.jpg" + /> + </Link> + <Link to=""> + limpack_official + <span className="followReco">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user6.jpg" + /> + </Link> + <Link to=""> + les_photos_de_cat + <span className="followReco"> + geee____nie๋‹˜ ์™ธ 1๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค. + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user7.jpg" + /> + </Link> + <Link to=""> + mornstar_nail + <span className="followReco"> + effie_yxz๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + </ul> + </aside> + <footer className="main-right-footer"> + <ul className="footList"> + <FootLists /> + </ul> + <span className="copyright">ยฉ 2021 INSTAGRAM FROM FACEBOOK</span> + </footer> + </div> + </main> </div> ); }
JavaScript
ใ…Žใ…Žใ…Ž Return ์€ ์ƒ๋žต๋  ์ˆ˜ ์žˆ๋‹ค ~
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
๊ณ„์‚ฐ๋œ์†์„ฑ๋ช… ๊ตฟ
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
์˜ค....
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
์ด๋Ÿฐ๋ฐฉ๋ฒ•์ด.. ํ”ผ๋“œ๋งˆ๋‹ค ๋Œ“๊ธ€ ๋ฐ์ดํ„ฐ๋ฅผ ์Šคํ…Œ์ดํŠธ๋กœ ํฌํ•จํ•˜๊ฒŒ ํ•ด์ฃผ๋‹ˆ ๋ณด๊ธฐ ์‰ฝ๊ณ  ์ข‹๋„ค์š”
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
์ด๋Ÿฐ ์ฃผ์„๋“ค์€ ๋ถˆํ•„์š”ํ•˜๋‹ˆ๊นŒ ์‚ญ์ œํ•ด์ฃผ์‹œ๋Š”๊ฒŒ ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค!
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
event.target ๋ฐ˜๋ณต๋˜๊ณ  ์žˆ๋Š”๋ฐ ๊ตฌ์กฐ๋ถ„ํ•ดํ•ด์„œ ํ™œ์šฉํ•ด๋ณผ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”! ```const {name,value} = event.target;```
@@ -12,9 +12,7 @@ import com.doubleowner.revibe.domain.user.entity.User; import com.doubleowner.revibe.global.config.auth.UserDetailsImpl; import com.doubleowner.revibe.global.exception.ImageException; -import com.doubleowner.revibe.global.exception.ReviewException; import com.doubleowner.revibe.global.exception.errorCode.ImageErrorCode; -import com.doubleowner.revibe.global.exception.errorCode.ReviewErrorCode; import com.doubleowner.revibe.global.util.S3Uploader; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -35,18 +33,16 @@ public class ReviewService { @Transactional public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile file, User user) { + Payment payment = paymentRepository.findByPaymentId(reviewRequestDto.getPaymentId()).orElseThrow(() -> new RuntimeException()); + if (!user.getEmail().equals(payment.getBuy().getUser().getEmail())) { throw new RuntimeException("๋‚ด๊ฐ€ ๊ตฌ๋งคํ•œ ์ƒํ’ˆ์ด ์•„๋‹™๋‹ˆ๋‹ค."); } Execution execution = executionRepository.findExecutionById(reviewRequestDto.getExecutionId()).orElseThrow(() -> new RuntimeException("๋‚ด์—ญ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")); - String image; - try { - image = s3Uploader.upload(file); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + + String image = uploadImage(file); Review review = Review.builder() .starRate(reviewRequestDto.getStarRate()) @@ -57,30 +53,27 @@ public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile .item(execution.getSell().getOptions().getItem()) .user(user) .build(); + Review save = reviewRepository.save(review); - return Review.toDto(save); + return toDto(save); } + @Transactional(readOnly = true) public List<ReviewResponseDto> findReview(User user) { List<Review> reviewsByUserId = reviewRepository.findReviewsByUserId(user.getId()); - return reviewsByUserId.stream().map(Review::toDto).toList(); + return reviewsByUserId.stream().map(this::toDto).toList(); } @Transactional public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewRequestDto updateReviewRequestDto, MultipartFile file) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, userDetails.getUser().getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, userDetails.getUser().getId()); if (file != null) { - try { - s3Uploader.deleteImage(review.getReviewImage()); - String imageUrl = s3Uploader.upload(file); - review.update(imageUrl); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + this.reUploadImage(review, file); } review.update(updateReviewRequestDto); @@ -89,8 +82,66 @@ public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewReque @Transactional public void deleteReview(Long id, User user) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, user.getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, user.getId()); reviewRepository.delete(review); } + + /** + * DTO๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ + * + * @param review + * @return + */ + private ReviewResponseDto toDto(Review review) { + return ReviewResponseDto.builder() + .reviewId(review.getId()) + .title(review.getTitle()) + .content(review.getContent()) + .starRate(review.getStarRate()) + .createdAt(review.getCreatedAt()) + .image(review.getReviewImage()) + .build(); + } + + /** + * ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ + * + * @param file + * @return + */ + private String uploadImage(MultipartFile file) { + + if (file == null) { + return null; + } + + try { + return s3Uploader.upload(file); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + } + + /** + * ์ด๋ฏธ์ง€ ์žฌ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ (๊ธฐ์กด ์ด๋ฏธ์ง€ ์‚ญ์ œ ํ›„ ์—…๋กœ๋“œ) + * + * @param review + * @param file + */ + private void reUploadImage(Review review, MultipartFile file) { + + try { + s3Uploader.deleteImage(review.getReviewImage()); + String imageUrl = uploadImage(file); + review.update(imageUrl); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + + } + }
Java
_:hammer_and_wrench: Refactor suggestion_ **RuntimeException ๋Œ€์‹  ๋งž์ถคํ˜• ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”** ์ผ๋ฐ˜์ ์ธ `RuntimeException` ๋Œ€์‹  ๋„๋ฉ”์ธ์— ๋งž๋Š” ๋งž์ถคํ˜• ์˜ˆ์™ธ ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ์‹œ ๋” ๊ตฌ์ฒด์ ์ธ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๊ณ , ์˜ˆ์™ธ๋ฅผ ํšจ๊ณผ์ ์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, `PaymentNotFoundException`์„ ์ƒ์„ฑํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: ```java public class PaymentNotFoundException extends RuntimeException { public PaymentNotFoundException(String message) { super(message); } } ``` ๊ทธ๋ฆฌ๊ณ  ์˜ˆ์™ธ๋ฅผ ๋˜์งˆ ๋•Œ: ```diff -.orElseThrow(() -> new RuntimeException("๊ฒฐ์ œ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")); +.orElseThrow(() -> new PaymentNotFoundException("๊ฒฐ์ œ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")); ``` <!-- This is an auto-generated comment by CodeRabbit -->
@@ -12,9 +12,7 @@ import com.doubleowner.revibe.domain.user.entity.User; import com.doubleowner.revibe.global.config.auth.UserDetailsImpl; import com.doubleowner.revibe.global.exception.ImageException; -import com.doubleowner.revibe.global.exception.ReviewException; import com.doubleowner.revibe.global.exception.errorCode.ImageErrorCode; -import com.doubleowner.revibe.global.exception.errorCode.ReviewErrorCode; import com.doubleowner.revibe.global.util.S3Uploader; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -35,18 +33,16 @@ public class ReviewService { @Transactional public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile file, User user) { + Payment payment = paymentRepository.findByPaymentId(reviewRequestDto.getPaymentId()).orElseThrow(() -> new RuntimeException()); + if (!user.getEmail().equals(payment.getBuy().getUser().getEmail())) { throw new RuntimeException("๋‚ด๊ฐ€ ๊ตฌ๋งคํ•œ ์ƒํ’ˆ์ด ์•„๋‹™๋‹ˆ๋‹ค."); } Execution execution = executionRepository.findExecutionById(reviewRequestDto.getExecutionId()).orElseThrow(() -> new RuntimeException("๋‚ด์—ญ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")); - String image; - try { - image = s3Uploader.upload(file); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + + String image = uploadImage(file); Review review = Review.builder() .starRate(reviewRequestDto.getStarRate()) @@ -57,30 +53,27 @@ public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile .item(execution.getSell().getOptions().getItem()) .user(user) .build(); + Review save = reviewRepository.save(review); - return Review.toDto(save); + return toDto(save); } + @Transactional(readOnly = true) public List<ReviewResponseDto> findReview(User user) { List<Review> reviewsByUserId = reviewRepository.findReviewsByUserId(user.getId()); - return reviewsByUserId.stream().map(Review::toDto).toList(); + return reviewsByUserId.stream().map(this::toDto).toList(); } @Transactional public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewRequestDto updateReviewRequestDto, MultipartFile file) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, userDetails.getUser().getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, userDetails.getUser().getId()); if (file != null) { - try { - s3Uploader.deleteImage(review.getReviewImage()); - String imageUrl = s3Uploader.upload(file); - review.update(imageUrl); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + this.reUploadImage(review, file); } review.update(updateReviewRequestDto); @@ -89,8 +82,66 @@ public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewReque @Transactional public void deleteReview(Long id, User user) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, user.getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, user.getId()); reviewRepository.delete(review); } + + /** + * DTO๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ + * + * @param review + * @return + */ + private ReviewResponseDto toDto(Review review) { + return ReviewResponseDto.builder() + .reviewId(review.getId()) + .title(review.getTitle()) + .content(review.getContent()) + .starRate(review.getStarRate()) + .createdAt(review.getCreatedAt()) + .image(review.getReviewImage()) + .build(); + } + + /** + * ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ + * + * @param file + * @return + */ + private String uploadImage(MultipartFile file) { + + if (file == null) { + return null; + } + + try { + return s3Uploader.upload(file); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + } + + /** + * ์ด๋ฏธ์ง€ ์žฌ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ (๊ธฐ์กด ์ด๋ฏธ์ง€ ์‚ญ์ œ ํ›„ ์—…๋กœ๋“œ) + * + * @param review + * @param file + */ + private void reUploadImage(Review review, MultipartFile file) { + + try { + s3Uploader.deleteImage(review.getReviewImage()); + String imageUrl = uploadImage(file); + review.update(imageUrl); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + + } + }
Java
_:hammer_and_wrench: Refactor suggestion_ **RuntimeException ๋Œ€์‹  ๋งž์ถคํ˜• ์˜ˆ์™ธ๋ฅผ ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”** `Execution` ๊ฐ์ฒด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์„ ๋•Œ `RuntimeException`์„ ๋ฐœ์ƒ์‹œํ‚ค๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋„๋ฉ”์ธ์— ๋งž๋Š” ๋งž์ถคํ˜• ์˜ˆ์™ธ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, `ExecutionNotFoundException`์„ ์ƒ์„ฑํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: ```java public class ExecutionNotFoundException extends RuntimeException { public ExecutionNotFoundException(String message) { super(message); } } ``` ๊ทธ๋ฆฌ๊ณ  ์˜ˆ์™ธ๋ฅผ ๋˜์งˆ ๋•Œ: ```diff -Execution execution = executionRepository.findExecutionById(reviewRequestDto.getExecutionId()) - .orElseThrow(() -> new RuntimeException("๋‚ด์—ญ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")); +Execution execution = executionRepository.findExecutionById(reviewRequestDto.getExecutionId()) + .orElseThrow(() -> new ExecutionNotFoundException("๋‚ด์—ญ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")); ``` <!-- This is an auto-generated comment by CodeRabbit -->
@@ -12,9 +12,7 @@ import com.doubleowner.revibe.domain.user.entity.User; import com.doubleowner.revibe.global.config.auth.UserDetailsImpl; import com.doubleowner.revibe.global.exception.ImageException; -import com.doubleowner.revibe.global.exception.ReviewException; import com.doubleowner.revibe.global.exception.errorCode.ImageErrorCode; -import com.doubleowner.revibe.global.exception.errorCode.ReviewErrorCode; import com.doubleowner.revibe.global.util.S3Uploader; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -35,18 +33,16 @@ public class ReviewService { @Transactional public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile file, User user) { + Payment payment = paymentRepository.findByPaymentId(reviewRequestDto.getPaymentId()).orElseThrow(() -> new RuntimeException()); + if (!user.getEmail().equals(payment.getBuy().getUser().getEmail())) { throw new RuntimeException("๋‚ด๊ฐ€ ๊ตฌ๋งคํ•œ ์ƒํ’ˆ์ด ์•„๋‹™๋‹ˆ๋‹ค."); } Execution execution = executionRepository.findExecutionById(reviewRequestDto.getExecutionId()).orElseThrow(() -> new RuntimeException("๋‚ด์—ญ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")); - String image; - try { - image = s3Uploader.upload(file); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + + String image = uploadImage(file); Review review = Review.builder() .starRate(reviewRequestDto.getStarRate()) @@ -57,30 +53,27 @@ public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile .item(execution.getSell().getOptions().getItem()) .user(user) .build(); + Review save = reviewRepository.save(review); - return Review.toDto(save); + return toDto(save); } + @Transactional(readOnly = true) public List<ReviewResponseDto> findReview(User user) { List<Review> reviewsByUserId = reviewRepository.findReviewsByUserId(user.getId()); - return reviewsByUserId.stream().map(Review::toDto).toList(); + return reviewsByUserId.stream().map(this::toDto).toList(); } @Transactional public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewRequestDto updateReviewRequestDto, MultipartFile file) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, userDetails.getUser().getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, userDetails.getUser().getId()); if (file != null) { - try { - s3Uploader.deleteImage(review.getReviewImage()); - String imageUrl = s3Uploader.upload(file); - review.update(imageUrl); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + this.reUploadImage(review, file); } review.update(updateReviewRequestDto); @@ -89,8 +82,66 @@ public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewReque @Transactional public void deleteReview(Long id, User user) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, user.getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, user.getId()); reviewRepository.delete(review); } + + /** + * DTO๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ + * + * @param review + * @return + */ + private ReviewResponseDto toDto(Review review) { + return ReviewResponseDto.builder() + .reviewId(review.getId()) + .title(review.getTitle()) + .content(review.getContent()) + .starRate(review.getStarRate()) + .createdAt(review.getCreatedAt()) + .image(review.getReviewImage()) + .build(); + } + + /** + * ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ + * + * @param file + * @return + */ + private String uploadImage(MultipartFile file) { + + if (file == null) { + return null; + } + + try { + return s3Uploader.upload(file); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + } + + /** + * ์ด๋ฏธ์ง€ ์žฌ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ (๊ธฐ์กด ์ด๋ฏธ์ง€ ์‚ญ์ œ ํ›„ ์—…๋กœ๋“œ) + * + * @param review + * @param file + */ + private void reUploadImage(Review review, MultipartFile file) { + + try { + s3Uploader.deleteImage(review.getReviewImage()); + String imageUrl = uploadImage(file); + review.update(imageUrl); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + + } + }
Java
_:warning: Potential issue_ **์˜ˆ์™ธ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค** `findMyReview` ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ ํ›„, ๋ฆฌ๋ทฐ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋ฆฌ๋ทฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•˜์—ฌ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: ```diff -Review review = reviewRepository.findMyReview(id, userDetails.getUser().getId()); +Review review = reviewRepository.findMyReview(id, userDetails.getUser().getId()) + .orElseThrow(() -> new ReviewNotFoundException("๋ฆฌ๋ทฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")); ``` `ReviewNotFoundException` ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ```java public class ReviewNotFoundException extends RuntimeException { public ReviewNotFoundException(String message) { super(message); } } ``` <!-- This is an auto-generated comment by CodeRabbit -->
@@ -12,9 +12,7 @@ import com.doubleowner.revibe.domain.user.entity.User; import com.doubleowner.revibe.global.config.auth.UserDetailsImpl; import com.doubleowner.revibe.global.exception.ImageException; -import com.doubleowner.revibe.global.exception.ReviewException; import com.doubleowner.revibe.global.exception.errorCode.ImageErrorCode; -import com.doubleowner.revibe.global.exception.errorCode.ReviewErrorCode; import com.doubleowner.revibe.global.util.S3Uploader; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -35,18 +33,16 @@ public class ReviewService { @Transactional public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile file, User user) { + Payment payment = paymentRepository.findByPaymentId(reviewRequestDto.getPaymentId()).orElseThrow(() -> new RuntimeException()); + if (!user.getEmail().equals(payment.getBuy().getUser().getEmail())) { throw new RuntimeException("๋‚ด๊ฐ€ ๊ตฌ๋งคํ•œ ์ƒํ’ˆ์ด ์•„๋‹™๋‹ˆ๋‹ค."); } Execution execution = executionRepository.findExecutionById(reviewRequestDto.getExecutionId()).orElseThrow(() -> new RuntimeException("๋‚ด์—ญ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")); - String image; - try { - image = s3Uploader.upload(file); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + + String image = uploadImage(file); Review review = Review.builder() .starRate(reviewRequestDto.getStarRate()) @@ -57,30 +53,27 @@ public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile .item(execution.getSell().getOptions().getItem()) .user(user) .build(); + Review save = reviewRepository.save(review); - return Review.toDto(save); + return toDto(save); } + @Transactional(readOnly = true) public List<ReviewResponseDto> findReview(User user) { List<Review> reviewsByUserId = reviewRepository.findReviewsByUserId(user.getId()); - return reviewsByUserId.stream().map(Review::toDto).toList(); + return reviewsByUserId.stream().map(this::toDto).toList(); } @Transactional public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewRequestDto updateReviewRequestDto, MultipartFile file) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, userDetails.getUser().getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, userDetails.getUser().getId()); if (file != null) { - try { - s3Uploader.deleteImage(review.getReviewImage()); - String imageUrl = s3Uploader.upload(file); - review.update(imageUrl); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + this.reUploadImage(review, file); } review.update(updateReviewRequestDto); @@ -89,8 +82,66 @@ public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewReque @Transactional public void deleteReview(Long id, User user) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, user.getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, user.getId()); reviewRepository.delete(review); } + + /** + * DTO๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ + * + * @param review + * @return + */ + private ReviewResponseDto toDto(Review review) { + return ReviewResponseDto.builder() + .reviewId(review.getId()) + .title(review.getTitle()) + .content(review.getContent()) + .starRate(review.getStarRate()) + .createdAt(review.getCreatedAt()) + .image(review.getReviewImage()) + .build(); + } + + /** + * ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ + * + * @param file + * @return + */ + private String uploadImage(MultipartFile file) { + + if (file == null) { + return null; + } + + try { + return s3Uploader.upload(file); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + } + + /** + * ์ด๋ฏธ์ง€ ์žฌ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ (๊ธฐ์กด ์ด๋ฏธ์ง€ ์‚ญ์ œ ํ›„ ์—…๋กœ๋“œ) + * + * @param review + * @param file + */ + private void reUploadImage(Review review, MultipartFile file) { + + try { + s3Uploader.deleteImage(review.getReviewImage()); + String imageUrl = uploadImage(file); + review.update(imageUrl); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + + } + }
Java
_:warning: Potential issue_ **์˜ˆ์™ธ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค** `deleteReview` ๋ฉ”์„œ๋“œ์—์„œ๋„ ๋ฆฌ๋ทฐ๋ฅผ ์ฐพ์ง€ ๋ชปํ•  ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: ```diff -Review review = reviewRepository.findMyReview(id, user.getId()); +Review review = reviewRepository.findMyReview(id, user.getId()) + .orElseThrow(() -> new ReviewNotFoundException("๋ฆฌ๋ทฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")); ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
@@ -12,9 +12,7 @@ import com.doubleowner.revibe.domain.user.entity.User; import com.doubleowner.revibe.global.config.auth.UserDetailsImpl; import com.doubleowner.revibe.global.exception.ImageException; -import com.doubleowner.revibe.global.exception.ReviewException; import com.doubleowner.revibe.global.exception.errorCode.ImageErrorCode; -import com.doubleowner.revibe.global.exception.errorCode.ReviewErrorCode; import com.doubleowner.revibe.global.util.S3Uploader; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -35,18 +33,16 @@ public class ReviewService { @Transactional public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile file, User user) { + Payment payment = paymentRepository.findByPaymentId(reviewRequestDto.getPaymentId()).orElseThrow(() -> new RuntimeException()); + if (!user.getEmail().equals(payment.getBuy().getUser().getEmail())) { throw new RuntimeException("๋‚ด๊ฐ€ ๊ตฌ๋งคํ•œ ์ƒํ’ˆ์ด ์•„๋‹™๋‹ˆ๋‹ค."); } Execution execution = executionRepository.findExecutionById(reviewRequestDto.getExecutionId()).orElseThrow(() -> new RuntimeException("๋‚ด์—ญ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")); - String image; - try { - image = s3Uploader.upload(file); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + + String image = uploadImage(file); Review review = Review.builder() .starRate(reviewRequestDto.getStarRate()) @@ -57,30 +53,27 @@ public ReviewResponseDto write(ReviewRequestDto reviewRequestDto, MultipartFile .item(execution.getSell().getOptions().getItem()) .user(user) .build(); + Review save = reviewRepository.save(review); - return Review.toDto(save); + return toDto(save); } + @Transactional(readOnly = true) public List<ReviewResponseDto> findReview(User user) { List<Review> reviewsByUserId = reviewRepository.findReviewsByUserId(user.getId()); - return reviewsByUserId.stream().map(Review::toDto).toList(); + return reviewsByUserId.stream().map(this::toDto).toList(); } @Transactional public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewRequestDto updateReviewRequestDto, MultipartFile file) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, userDetails.getUser().getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, userDetails.getUser().getId()); if (file != null) { - try { - s3Uploader.deleteImage(review.getReviewImage()); - String imageUrl = s3Uploader.upload(file); - review.update(imageUrl); - } catch (IOException e) { - throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); - } + this.reUploadImage(review, file); } review.update(updateReviewRequestDto); @@ -89,8 +82,66 @@ public void updateReview(Long id, UserDetailsImpl userDetails, UpdateReviewReque @Transactional public void deleteReview(Long id, User user) { - Review review = reviewRepository.findReviewByIdAndUser_Id(id, user.getId()).orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + Review review = reviewRepository.findMyReview(id, user.getId()); reviewRepository.delete(review); } + + /** + * DTO๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ + * + * @param review + * @return + */ + private ReviewResponseDto toDto(Review review) { + return ReviewResponseDto.builder() + .reviewId(review.getId()) + .title(review.getTitle()) + .content(review.getContent()) + .starRate(review.getStarRate()) + .createdAt(review.getCreatedAt()) + .image(review.getReviewImage()) + .build(); + } + + /** + * ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ + * + * @param file + * @return + */ + private String uploadImage(MultipartFile file) { + + if (file == null) { + return null; + } + + try { + return s3Uploader.upload(file); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + } + + /** + * ์ด๋ฏธ์ง€ ์žฌ์—…๋กœ๋“œ ๋ฉ”์†Œ๋“œ (๊ธฐ์กด ์ด๋ฏธ์ง€ ์‚ญ์ œ ํ›„ ์—…๋กœ๋“œ) + * + * @param review + * @param file + */ + private void reUploadImage(Review review, MultipartFile file) { + + try { + s3Uploader.deleteImage(review.getReviewImage()); + String imageUrl = uploadImage(file); + review.update(imageUrl); + + } catch (IOException e) { + throw new ImageException(ImageErrorCode.FAILED_UPLOAD_IMAGE); + } + + } + }
Java
_:warning: Potential issue_ **RuntimeException์— ์˜๋ฏธ ์žˆ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”** `orElseThrow`์—์„œ ์˜ˆ์™ธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ฌ ๋•Œ, ํ˜„์žฌ ๋ฉ”์‹œ์ง€๊ฐ€ ์—†๋Š” `RuntimeException`์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋ช…ํ™•ํ•œ ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋ฅผ ํฌํ•จํ•˜์—ฌ ๋ฌธ์ œ์˜ ์›์ธ์„ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: ```diff -Payment payment = paymentRepository.findByPaymentId(reviewRequestDto.getPaymentId()).orElseThrow(() -> new RuntimeException()); +Payment payment = paymentRepository.findByPaymentId(reviewRequestDto.getPaymentId()) + .orElseThrow(() -> new RuntimeException("๊ฒฐ์ œ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")); ``` <!-- suggestion_start --> <details> <summary>๐Ÿ“ Committable suggestion</summary> > โ€ผ๏ธ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion Payment payment = paymentRepository.findByPaymentId(reviewRequestDto.getPaymentId()) .orElseThrow(() -> new RuntimeException("๊ฒฐ์ œ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
@@ -6,6 +6,7 @@ import com.doubleowner.revibe.domain.review.service.ReviewService; import com.doubleowner.revibe.global.common.dto.CommonResponseBody; import com.doubleowner.revibe.global.config.auth.UserDetailsImpl; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -17,31 +18,31 @@ import java.util.List; @RestController -@RequestMapping +@RequestMapping("/api/reviews") @RequiredArgsConstructor public class ReviewController { private final ReviewService reviewService; - @PostMapping(value = "/reviews", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public ResponseEntity<CommonResponseBody<ReviewResponseDto>> writeReview(@AuthenticationPrincipal UserDetailsImpl userDetails, @RequestPart ReviewRequestDto reviewRequestDto, @RequestPart(name = "image", required = false) MultipartFile file) { + @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public ResponseEntity<CommonResponseBody<ReviewResponseDto>> writeReview(@AuthenticationPrincipal UserDetailsImpl userDetails, @Valid @RequestPart ReviewRequestDto reviewRequestDto, @RequestPart(name = "image", required = false) MultipartFile file) { ReviewResponseDto review = reviewService.write(reviewRequestDto, file, userDetails.getUser()); return new ResponseEntity<>(new CommonResponseBody<>("๋ฆฌ๋ทฐ๊ฐ€ ๋“ฑ๋ก๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", review), HttpStatus.CREATED); } - @GetMapping("/reviews") + @GetMapping public ResponseEntity<CommonResponseBody<List<ReviewResponseDto>>> findReviews(@AuthenticationPrincipal UserDetailsImpl userDetails) { List<ReviewResponseDto> read = reviewService.findReview(userDetails.getUser()); return new ResponseEntity<>(new CommonResponseBody<>("๋ฆฌ๋ทฐ๊ฐ€ ์กฐํšŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", read), HttpStatus.OK); } - @PutMapping(value = "/reviews/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public ResponseEntity<CommonResponseBody<Void>> updateReview(@PathVariable Long id, @AuthenticationPrincipal UserDetailsImpl userDetails, @RequestPart UpdateReviewRequestDto updateReviewRequestDto, @RequestPart(name = "image", required = false) MultipartFile file) { + @PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public ResponseEntity<CommonResponseBody<Void>> updateReview(@PathVariable Long id, @AuthenticationPrincipal UserDetailsImpl userDetails, @Valid @RequestPart UpdateReviewRequestDto updateReviewRequestDto, @RequestPart(name = "image", required = false) MultipartFile file) { reviewService.updateReview(id, userDetails, updateReviewRequestDto, file); return new ResponseEntity<>(new CommonResponseBody<>("๋ฆฌ๋ทฐ๊ฐ€ ์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค."), HttpStatus.OK); } - @DeleteMapping("/reviews/{id}") + @DeleteMapping("/{id}") public ResponseEntity<CommonResponseBody<Void>> deleteReview(@PathVariable Long id, @AuthenticationPrincipal UserDetailsImpl userDetails) { reviewService.deleteReview(id, userDetails.getUser()); return new ResponseEntity<>(new CommonResponseBody<>("๋ฆฌ๋ทฐ๊ฐ€ ์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."), HttpStatus.OK);
Java
_:bulb: Codebase verification_ **ํŒŒ์ผ ์—…๋กœ๋“œ ๋ณด์•ˆ ๊ฒ€์ฆ์ด ๋ฏธํกํ•ฉ๋‹ˆ๋‹ค** ํ˜„์žฌ ํŒŒ์ผ ํฌ๊ธฐ ์ œํ•œ(5MB)๋งŒ ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฉฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ค‘์š”ํ•œ ๋ณด์•ˆ ๊ฒ€์ฆ์ด ๋ˆ„๋ฝ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค: 1. ์ด๋ฏธ์ง€ ํŒŒ์ผ ํ˜•์‹ ๊ฒ€์ฆ ๋กœ์ง (ํ—ˆ์šฉ๋œ ํ™•์žฅ์ž: jpg, png ๋“ฑ) 2. Content-Type ๊ฒ€์ฆ (`image/*`) 3. ํŒŒ์ผ๋ช… ๋ณด์•ˆ ์ฒ˜๋ฆฌ (XSS ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ ํŠน์ˆ˜๋ฌธ์ž ์ œ๊ฑฐ ๋“ฑ) ๊ตฌํ˜„ ์ œ์•ˆ: - `FileValidator` ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์œ„ ๊ฒ€์ฆ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๊ณ  `ReviewService`์—์„œ ํ™œ์šฉ - ํŒŒ์ผ ์—…๋กœ๋“œ ์ „ `MediaType.IMAGE_*` ํƒ€์ž… ๊ฒ€์ฆ - Apache Commons IO์˜ `FilenameUtils`๋ฅผ ํ™œ์šฉํ•œ ํŒŒ์ผ๋ช… ์ •๊ทœํ™” <details> <summary>๐Ÿ”— Analysis chain</summary> **Multipart ์š”์ฒญ์— ๋Œ€ํ•œ ๊ฒ€์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.** `@Valid`๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ DTO ๊ฒ€์ฆ์„ ๊ฐ•ํ™”ํ•œ ๊ฒƒ์€ ์ข‹์€ ๊ฐœ์„ ์ด์ง€๋งŒ, ํŒŒ์ผ ์—…๋กœ๋“œ์™€ ๊ด€๋ จํ•˜์—ฌ ๋ช‡ ๊ฐ€์ง€ ๊ฒ€ํ† ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค: 1. ํŒŒ์ผ ํฌ๊ธฐ ์ œํ•œ 2. ํ—ˆ์šฉ๋œ ์ด๋ฏธ์ง€ ํ˜•์‹ ๊ฒ€์ฆ 3. ํŒŒ์ผ๋ช… ๋ณด์•ˆ ์ฒ˜๋ฆฌ ๋‹ค์Œ ์„ค์ •๋“ค์ด ์ ์šฉ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์ฃผ์„ธ์š”: Also applies to: 38-39 </details> <details> <summary>๐Ÿ Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # application.properties/yml์—์„œ ํŒŒ์ผ ์—…๋กœ๋“œ ๊ด€๋ จ ์„ค์ • ํ™•์ธ rg "multipart|spring.servlet.multipart" # ํŒŒ์ผ ๊ฒ€์ฆ ๋กœ์ง ํ™•์ธ rg "MediaType.IMAGE|ContentType|FileValidator" -A 5 ``` Length of output: 2892 --- Script: ```shell #!/bin/bash # Check ReviewService for file validation ast-grep --pattern 'class ReviewService { $$$ writeReview($$$) { $$$ } $$$ }' # Check for any image validation rg -i "image.*validation|validate.*image|file.*type" -A 3 ``` Length of output: 612 </details> <!-- This is an auto-generated comment by CodeRabbit -->
@@ -0,0 +1,45 @@ +package com.example.momogum.repository.redisRepository; + +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +import java.time.Duration; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +@Repository +@RequiredArgsConstructor +public class RedisRepository { + + private final RedisTemplate<String, Object> redisTemplate; + + + // ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒํ•œ postId ์ €์žฅ + public void addViewedPost(String userId, String postId) { + String key = generateKey(userId); + redisTemplate.opsForSet().add(key, postId); + } + + // ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒํ•œ postId ๋ชฉ๋ก ์กฐํšŒ + public Set<Long> getViewedPosts(String userId) { + String key = generateKey(userId); + + return Objects.requireNonNull(redisTemplate.opsForSet().members(key)).stream() + .map(Object::toString) + .map(Long::valueOf) + .collect(Collectors.toSet()); + } + + // Redis Key ์ƒ์„ฑ + private String generateKey(String userId) { + return "user:" + userId + ":viewed"; + } + + // ์„ธ์…˜ ๋งŒ๋ฃŒ ์‹œ๊ฐ„ ์„ค์ • + public void setSessionTimeout(String userId, long timeoutMinutes) { + String key = generateKey(userId); + redisTemplate.expire(key, Duration.ofMinutes(timeoutMinutes)); + } +}
Java
redis template๋ฅผ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ•˜์‹  ๊ฒƒ ๊ฐ™๋„ค์š” ํ™•์‹คํžˆ ์ดํ•ด๋งŒ ์ž˜ ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด crudRepository๋ณด๋‹ค template๊ตฌํ˜„ํ•˜๋Š”๊ฒŒ ์˜๋„๋ฅผ ๋” ์ž˜ ๋‹ด์„ ์ˆ˜ ์žˆ์–ด์„œ ์ข‹์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ณ ์ƒํ•˜์…จ์–ด์š”!
@@ -1,20 +1,59 @@ package com.example.momogum.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisPassword; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; @Configuration +@EnableRedisRepositories public class RedisConfig { + @Value("${spring.data.redis.host}") + private String redisHost; + + @Value("${spring.data.redis.port}") + private int redisPort; + + @Value("${spring.data.redis.password}") + private String redisPassword; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(redisHost, redisPort); + if (redisPassword != null && !redisPassword.isBlank()) { + configuration.setPassword(RedisPassword.of(redisPassword)); + } + return new LettuceConnectionFactory(configuration); + } + @Bean - public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory connectionFactory) { - RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); - redisTemplate.setConnectionFactory(connectionFactory); + public RedisTemplate<String, Object> redisTemplate() { + RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(redisConnectionFactory()); + + // Key์™€ Value์˜ ์ง๋ ฌํ™” ์„ค์ • redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new StringRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); + redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); + + redisTemplate.afterPropertiesSet(); return redisTemplate; } + + @Bean + public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) { + StringRedisTemplate template = new StringRedisTemplate(); + template.setConnectionFactory(redisConnectionFactory); + return template; + } }
Java
์ด๋ ‡๊ฒŒ ์ค‘๋ณต๋˜๋Š” ์„ค์ •๋ถ€๋ถ„์„ ๋”ฐ๋กœ ํด๋ž˜์Šค๋กœ ๋ถ„๋ฆฌํ•˜๋ฉด ๊ฐ€๋…์„ฑ์ด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ex) `private void setSerialzer { redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); } ํ•˜๊ณ  redisTemplate์—์„œ setSerializers(RedisTemplate<String, Object> redisTemplate) ํ•ด์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค (ํ•œ ๋ฒˆ ํ™•์ธ ๋ถ€ํƒ๋“œ๋ ค์š”!) `
@@ -2,11 +2,24 @@ import com.example.momogum.domain.MealDiary; import com.example.momogum.domain.UserEntity; +import com.example.momogum.domain.common.enums.IsRevisit; +import io.lettuce.core.dynamic.annotation.Param; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; public interface MealDiaryRepository extends JpaRepository<MealDiary,Long> { List<MealDiary> findByUserEntity(UserEntity userEntity); + + @Query("SELECT m.id FROM MealDiary m WHERE m.isRevisit = :isRevisit AND m.userEntity.Id!= :userId ORDER BY m.likesCount DESC") + List<Long> findAllByIsRevisit(@Param("isRevisit") IsRevisit isRevisit, @Param("userId")Long userId); + + @Query("SELECT m.id FROM MealDiary m WHERE m.foodCategory = :foodCategory AND m.userEntity.Id != :userId ORDER BY m.likesCount DESC") + List<Long> findAllByFoodCategory(@Param("foodCategory") String foodCategory, @Param("userId")Long userId); + + + List<MealDiary> findByIdIn(List<Long> ids); + }
Java
๋™์  ์ฟผ๋ฆฌ๊ฐ€ ๋งŽ์€ ๊ฒฝ์šฐ queryDsl๋„ ๊ดœ์ฐฎ์•„๋ณด์ž…๋‹ˆ๋‹ค. ์—ฌ๊ฒฌ์ƒ ๋„์ž…ํ•  ์ˆ˜ ์žˆ์œผ๋ฉด ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,45 @@ +package com.example.momogum.repository.redisRepository; + +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +import java.time.Duration; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +@Repository +@RequiredArgsConstructor +public class RedisRepository { + + private final RedisTemplate<String, Object> redisTemplate; + + + // ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒํ•œ postId ์ €์žฅ + public void addViewedPost(String userId, String postId) { + String key = generateKey(userId); + redisTemplate.opsForSet().add(key, postId); + } + + // ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒํ•œ postId ๋ชฉ๋ก ์กฐํšŒ + public Set<Long> getViewedPosts(String userId) { + String key = generateKey(userId); + + return Objects.requireNonNull(redisTemplate.opsForSet().members(key)).stream() + .map(Object::toString) + .map(Long::valueOf) + .collect(Collectors.toSet()); + } + + // Redis Key ์ƒ์„ฑ + private String generateKey(String userId) { + return "user:" + userId + ":viewed"; + } + + // ์„ธ์…˜ ๋งŒ๋ฃŒ ์‹œ๊ฐ„ ์„ค์ • + public void setSessionTimeout(String userId, long timeoutMinutes) { + String key = generateKey(userId); + redisTemplate.expire(key, Duration.ofMinutes(timeoutMinutes)); + } +}
Java
`redisTemplate.opsForSet().members(key)` ์ด๋ถ€๋ถ„์—์„œ NullPointerException์ด ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ.. .. ์ž˜ ๋ชจ๋ฅด์ง€๋งŒ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค
@@ -0,0 +1,111 @@ +package com.example.momogum.service.viewMealDiaryService; + +import com.example.momogum.domain.MealDiary; +import com.example.momogum.domain.MealDiaryImage; + +import com.example.momogum.domain.common.enums.IsRevisit; +import com.example.momogum.repository.mealDiaryRepo.MealDiaryRepository; +import com.example.momogum.repository.redisRepository.RedisRepository; +import com.example.momogum.repository.userEntityRepo.UserEntityRepository; +import com.example.momogum.web.dto.viewMealDiary.ViewMealDiaryDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Comparator; +import java.util.List; + +import java.util.Set; + + +@Service +@RequiredArgsConstructor +public class ViewMealDiaryServiceImpl implements ViewMealDiaryService { + + private final RedisRepository redisRepository; + private final MealDiaryRepository mealDiaryRepository; + private final UserEntityRepository userEntityRepository; + private static final int SIZE = 6; + private static final int TTL_MINUTES = 5; + + /** + * ๋˜ ์˜ฌ๋ž˜์š” ์กฐํšŒ ๋กœ์ง + */ + @Override + public ViewMealDiaryDTO.ViewMealDiaryResponseListDTO getMealDiaryIsRevisitedByLikesCount(Long userId) { + + // "๋˜ ์˜ฌ๋ž˜์š”" ํ‘œ์‹œ๋œ ๋ฐฅ์ผ๊ธฐ ID ๋ฆฌ์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ (์ข‹์•„์š” ๊ฐœ์ˆ˜ ์ˆœ) + List<Long> isRevisitMealDiaryIds = mealDiaryRepository.findAllByIsRevisit(IsRevisit.GOOD, userId); + + // ๊ณตํ†ต ๋กœ์ง ํ˜ธ์ถœ + List<ViewMealDiaryDTO.ViewMealDiaryResponse> responseList = + getUnViewedMealDiaries(userId, isRevisitMealDiaryIds); + System.out.println(responseList); + // ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜ + return new ViewMealDiaryDTO.ViewMealDiaryResponseListDTO(responseList); + } + + /** + * ์Œ์‹ ์นดํ…Œ๊ณ ๋ฆฌ์— ๋”ฐ๋ฅธ ์กฐํšŒ ๋กœ์ง + */ + @Override + public ViewMealDiaryDTO.ViewMealDiaryResponseListDTO getMealDiaryByFoodCategory(Long userId, String foodCategory) { + + // 1. ํŠน์ • ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋ฐฅ์ผ๊ธฐ ID ๋ฆฌ์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ (์ข‹์•„์š” ๊ฐœ์ˆ˜ ์ˆœ) + List<Long> mealDiaryIdsByFoodCategory = mealDiaryRepository.findAllByFoodCategory(foodCategory, userId); + + // 2. ๊ณตํ†ต ๋กœ์ง ํ˜ธ์ถœ + List<ViewMealDiaryDTO.ViewMealDiaryResponse> responseList = + getUnViewedMealDiaries(userId, mealDiaryIdsByFoodCategory); + + // 3. ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜ + return new ViewMealDiaryDTO.ViewMealDiaryResponseListDTO(responseList); + } + + /** + * ๊ณตํ†ต ๋กœ์ง ( ํŠน์ • ์กฐ๊ฑด์— ๋งž๋Š” mealdiary id ๊ฐ’๋“ค์˜ ๋ฆฌ์ŠคํŠธ์—์„œ redis(์ด๋ฏธ ์กฐํšŒ)์— ์žˆ๋Š” id๊ฐ’๋“ค์„ ๋นผ๋Š” ๋กœ์ง + */ + private List<ViewMealDiaryDTO.ViewMealDiaryResponse> getUnViewedMealDiaries( + Long userId, + List<Long> allMealDiaryIds) { + + // redis์—์„œ ์ด๋ฏธ ๋ณธ mealdiary id ๊ฐ€์ ธ์˜ค๊ธฐ + String redisKey = userId.toString(); + Set<Long> viewedPosts = redisRepository.getViewedPosts(redisKey); + + // redis์™€ ๋น„๊ตํ•˜์—ฌ ์ค‘๋ณต ์ œ๊ฑฐ + 6๊ฐœ ๊ฐ€์ ธ์˜ค๊ธฐ + List<Long> unViewedPostIds = allMealDiaryIds.stream() + .filter(id -> !viewedPosts.contains(id)) + .sorted(Comparator.comparingLong(allMealDiaryIds::indexOf)) + .limit(ViewMealDiaryServiceImpl.SIZE) + .toList(); + + // ํ•„ํ„ฐ๋ง๋œ Id๋กœ MealDiary ์—”ํ‹ฐํ‹ฐ ์กฐํšŒ + List<MealDiary> unViewedPosts = mealDiaryRepository.findByIdIn(unViewedPostIds); + unViewedPosts.sort(Comparator.comparingLong(mealDiary -> unViewedPostIds.indexOf(mealDiary.getId()))); + + // MealDiary ์—”ํ‹ฐํ‹ฐ๋ฅผ DTO๋กœ ๋ณ€ํ™˜ + List<ViewMealDiaryDTO.ViewMealDiaryResponse> responseList = unViewedPosts.stream() + .map(post -> ViewMealDiaryDTO.ViewMealDiaryResponse.builder() + .mealDiaryId(post.getId()) + .foodImageURLs(post.getMealDiaryImages().stream() + .map(MealDiaryImage::getImageLink) + .toList()) + .userImageURL(post.getUserEntity().getProfileImage()) + .foodCategory(post.getFoodCategory()) + .keyWord(post.getMealDiaryKeywords().stream() + .map(mealDiaryKeyword -> mealDiaryKeyword.getKeyword().getKeyword()) + .toList()) + .isRevisit(post.getIsRevisit()) + .build()) + .toList(); + + // redis์— ๋ฐ˜ํ™˜๋œ Post ID ์ €์žฅ + responseList.forEach(response -> + redisRepository.addViewedPost(redisKey, response.getMealDiaryId().toString())); + + // redis TTL ์„ค์ • + redisRepository.setSessionTimeout(redisKey, TTL_MINUTES); + + return responseList; + } +}
Java
์ด ๋ถ€๋ถ„์—์„œ id ๋ฐ˜ํ™˜/ dto ๋ณ€ํ™˜, redis ttl ์„ค์ • ์ด๋Ÿฐ์‹์œผ๋กœ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ํด๋ž˜์Šค 3๊ฐœ๋กœ ์ชผ๊ฐœ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค SRP
@@ -0,0 +1,45 @@ +package com.example.momogum.repository.redisRepository; + +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +import java.time.Duration; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +@Repository +@RequiredArgsConstructor +public class RedisRepository { + + private final RedisTemplate<String, Object> redisTemplate; + + + // ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒํ•œ postId ์ €์žฅ + public void addViewedPost(String userId, String postId) { + String key = generateKey(userId); + redisTemplate.opsForSet().add(key, postId); + } + + // ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒํ•œ postId ๋ชฉ๋ก ์กฐํšŒ + public Set<Long> getViewedPosts(String userId) { + String key = generateKey(userId); + + return Objects.requireNonNull(redisTemplate.opsForSet().members(key)).stream() + .map(Object::toString) + .map(Long::valueOf) + .collect(Collectors.toSet()); + } + + // Redis Key ์ƒ์„ฑ + private String generateKey(String userId) { + return "user:" + userId + ":viewed"; + } + + // ์„ธ์…˜ ๋งŒ๋ฃŒ ์‹œ๊ฐ„ ์„ค์ • + public void setSessionTimeout(String userId, long timeoutMinutes) { + String key = generateKey(userId); + redisTemplate.expire(key, Duration.ofMinutes(timeoutMinutes)); + } +}
Java
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค !
@@ -1,20 +1,59 @@ package com.example.momogum.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisPassword; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; @Configuration +@EnableRedisRepositories public class RedisConfig { + @Value("${spring.data.redis.host}") + private String redisHost; + + @Value("${spring.data.redis.port}") + private int redisPort; + + @Value("${spring.data.redis.password}") + private String redisPassword; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(redisHost, redisPort); + if (redisPassword != null && !redisPassword.isBlank()) { + configuration.setPassword(RedisPassword.of(redisPassword)); + } + return new LettuceConnectionFactory(configuration); + } + @Bean - public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory connectionFactory) { - RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); - redisTemplate.setConnectionFactory(connectionFactory); + public RedisTemplate<String, Object> redisTemplate() { + RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(redisConnectionFactory()); + + // Key์™€ Value์˜ ์ง๋ ฌํ™” ์„ค์ • redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new StringRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); + redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); + + redisTemplate.afterPropertiesSet(); return redisTemplate; } + + @Bean + public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) { + StringRedisTemplate template = new StringRedisTemplate(); + template.setConnectionFactory(redisConnectionFactory); + return template; + } }
Java
๊ฐ€๋…์„ฑ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์œ ์ง€๋ณด์ˆ˜์—์„œ๋„ ์ด์ ์ด ์žˆ์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ! ์ง๋ ฌํ™”๊ฐ€ ํ•„์š”ํ•ด์„œ ๊ธ‰ํ•˜๊ฒŒ ์ถ”๊ฐ€ํ•˜๋‹ค ๋ณด๋‹ˆ ์‹œ์•ผ๊ฐ€ ์ข์•„์กŒ๋˜๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ์ถฉ๊ณ  ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค !
@@ -2,11 +2,24 @@ import com.example.momogum.domain.MealDiary; import com.example.momogum.domain.UserEntity; +import com.example.momogum.domain.common.enums.IsRevisit; +import io.lettuce.core.dynamic.annotation.Param; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; public interface MealDiaryRepository extends JpaRepository<MealDiary,Long> { List<MealDiary> findByUserEntity(UserEntity userEntity); + + @Query("SELECT m.id FROM MealDiary m WHERE m.isRevisit = :isRevisit AND m.userEntity.Id!= :userId ORDER BY m.likesCount DESC") + List<Long> findAllByIsRevisit(@Param("isRevisit") IsRevisit isRevisit, @Param("userId")Long userId); + + @Query("SELECT m.id FROM MealDiary m WHERE m.foodCategory = :foodCategory AND m.userEntity.Id != :userId ORDER BY m.likesCount DESC") + List<Long> findAllByFoodCategory(@Param("foodCategory") String foodCategory, @Param("userId")Long userId); + + + List<MealDiary> findByIdIn(List<Long> ids); + }
Java
queryDSL์„ ๊ณ ๋ ค๋ฅผ ํ–ˆ์—ˆ๋Š”๋ฐ ์•„๋ฌด๋ž˜๋„ ์กฐ๊ธˆ์€ ํ›„์ˆœ์œ„๊ฐ€ ๋  ๋“ฏํ•ฉ๋‹ˆ๋‹ค ใ…œใ…œ
@@ -0,0 +1,45 @@ +package com.example.momogum.repository.redisRepository; + +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +import java.time.Duration; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +@Repository +@RequiredArgsConstructor +public class RedisRepository { + + private final RedisTemplate<String, Object> redisTemplate; + + + // ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒํ•œ postId ์ €์žฅ + public void addViewedPost(String userId, String postId) { + String key = generateKey(userId); + redisTemplate.opsForSet().add(key, postId); + } + + // ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒํ•œ postId ๋ชฉ๋ก ์กฐํšŒ + public Set<Long> getViewedPosts(String userId) { + String key = generateKey(userId); + + return Objects.requireNonNull(redisTemplate.opsForSet().members(key)).stream() + .map(Object::toString) + .map(Long::valueOf) + .collect(Collectors.toSet()); + } + + // Redis Key ์ƒ์„ฑ + private String generateKey(String userId) { + return "user:" + userId + ":viewed"; + } + + // ์„ธ์…˜ ๋งŒ๋ฃŒ ์‹œ๊ฐ„ ์„ค์ • + public void setSessionTimeout(String userId, long timeoutMinutes) { + String key = generateKey(userId); + redisTemplate.expire(key, Duration.ofMinutes(timeoutMinutes)); + } +}
Java
ํ˜„์žฌ ๊ฒ€์ฆ์ด๋‚˜ @annotation ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ์ถ”๊ฐ€์ ์ธ mealdiary ์ˆ˜์ • ์‚ฌํ•ญ ๋ฐ˜์˜ํ•ด์„œ ์ง„ํ–‰ํ• ๋ ค๊ณ  ๊ณ„ํš์ค‘์ž…๋‹ˆ๋‹ค. ์กฐ๊ธˆ์”ฉ ๋ณ€๋™์‚ฌํ•ญ์ด ์žˆ์–ด ์ถ”ํ›„ ํ•œ๋ฒˆ์— ๊ฒ€์ฆ ๋‹จ๊ณ„์— ํ•„์š”ํ•œ ๋ถ€๋ถ„์„ ๋ชจ์•„๋‘˜๋ ค๊ณ  ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค !
@@ -0,0 +1,111 @@ +package com.example.momogum.service.viewMealDiaryService; + +import com.example.momogum.domain.MealDiary; +import com.example.momogum.domain.MealDiaryImage; + +import com.example.momogum.domain.common.enums.IsRevisit; +import com.example.momogum.repository.mealDiaryRepo.MealDiaryRepository; +import com.example.momogum.repository.redisRepository.RedisRepository; +import com.example.momogum.repository.userEntityRepo.UserEntityRepository; +import com.example.momogum.web.dto.viewMealDiary.ViewMealDiaryDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Comparator; +import java.util.List; + +import java.util.Set; + + +@Service +@RequiredArgsConstructor +public class ViewMealDiaryServiceImpl implements ViewMealDiaryService { + + private final RedisRepository redisRepository; + private final MealDiaryRepository mealDiaryRepository; + private final UserEntityRepository userEntityRepository; + private static final int SIZE = 6; + private static final int TTL_MINUTES = 5; + + /** + * ๋˜ ์˜ฌ๋ž˜์š” ์กฐํšŒ ๋กœ์ง + */ + @Override + public ViewMealDiaryDTO.ViewMealDiaryResponseListDTO getMealDiaryIsRevisitedByLikesCount(Long userId) { + + // "๋˜ ์˜ฌ๋ž˜์š”" ํ‘œ์‹œ๋œ ๋ฐฅ์ผ๊ธฐ ID ๋ฆฌ์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ (์ข‹์•„์š” ๊ฐœ์ˆ˜ ์ˆœ) + List<Long> isRevisitMealDiaryIds = mealDiaryRepository.findAllByIsRevisit(IsRevisit.GOOD, userId); + + // ๊ณตํ†ต ๋กœ์ง ํ˜ธ์ถœ + List<ViewMealDiaryDTO.ViewMealDiaryResponse> responseList = + getUnViewedMealDiaries(userId, isRevisitMealDiaryIds); + System.out.println(responseList); + // ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜ + return new ViewMealDiaryDTO.ViewMealDiaryResponseListDTO(responseList); + } + + /** + * ์Œ์‹ ์นดํ…Œ๊ณ ๋ฆฌ์— ๋”ฐ๋ฅธ ์กฐํšŒ ๋กœ์ง + */ + @Override + public ViewMealDiaryDTO.ViewMealDiaryResponseListDTO getMealDiaryByFoodCategory(Long userId, String foodCategory) { + + // 1. ํŠน์ • ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋ฐฅ์ผ๊ธฐ ID ๋ฆฌ์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ (์ข‹์•„์š” ๊ฐœ์ˆ˜ ์ˆœ) + List<Long> mealDiaryIdsByFoodCategory = mealDiaryRepository.findAllByFoodCategory(foodCategory, userId); + + // 2. ๊ณตํ†ต ๋กœ์ง ํ˜ธ์ถœ + List<ViewMealDiaryDTO.ViewMealDiaryResponse> responseList = + getUnViewedMealDiaries(userId, mealDiaryIdsByFoodCategory); + + // 3. ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜ + return new ViewMealDiaryDTO.ViewMealDiaryResponseListDTO(responseList); + } + + /** + * ๊ณตํ†ต ๋กœ์ง ( ํŠน์ • ์กฐ๊ฑด์— ๋งž๋Š” mealdiary id ๊ฐ’๋“ค์˜ ๋ฆฌ์ŠคํŠธ์—์„œ redis(์ด๋ฏธ ์กฐํšŒ)์— ์žˆ๋Š” id๊ฐ’๋“ค์„ ๋นผ๋Š” ๋กœ์ง + */ + private List<ViewMealDiaryDTO.ViewMealDiaryResponse> getUnViewedMealDiaries( + Long userId, + List<Long> allMealDiaryIds) { + + // redis์—์„œ ์ด๋ฏธ ๋ณธ mealdiary id ๊ฐ€์ ธ์˜ค๊ธฐ + String redisKey = userId.toString(); + Set<Long> viewedPosts = redisRepository.getViewedPosts(redisKey); + + // redis์™€ ๋น„๊ตํ•˜์—ฌ ์ค‘๋ณต ์ œ๊ฑฐ + 6๊ฐœ ๊ฐ€์ ธ์˜ค๊ธฐ + List<Long> unViewedPostIds = allMealDiaryIds.stream() + .filter(id -> !viewedPosts.contains(id)) + .sorted(Comparator.comparingLong(allMealDiaryIds::indexOf)) + .limit(ViewMealDiaryServiceImpl.SIZE) + .toList(); + + // ํ•„ํ„ฐ๋ง๋œ Id๋กœ MealDiary ์—”ํ‹ฐํ‹ฐ ์กฐํšŒ + List<MealDiary> unViewedPosts = mealDiaryRepository.findByIdIn(unViewedPostIds); + unViewedPosts.sort(Comparator.comparingLong(mealDiary -> unViewedPostIds.indexOf(mealDiary.getId()))); + + // MealDiary ์—”ํ‹ฐํ‹ฐ๋ฅผ DTO๋กœ ๋ณ€ํ™˜ + List<ViewMealDiaryDTO.ViewMealDiaryResponse> responseList = unViewedPosts.stream() + .map(post -> ViewMealDiaryDTO.ViewMealDiaryResponse.builder() + .mealDiaryId(post.getId()) + .foodImageURLs(post.getMealDiaryImages().stream() + .map(MealDiaryImage::getImageLink) + .toList()) + .userImageURL(post.getUserEntity().getProfileImage()) + .foodCategory(post.getFoodCategory()) + .keyWord(post.getMealDiaryKeywords().stream() + .map(mealDiaryKeyword -> mealDiaryKeyword.getKeyword().getKeyword()) + .toList()) + .isRevisit(post.getIsRevisit()) + .build()) + .toList(); + + // redis์— ๋ฐ˜ํ™˜๋œ Post ID ์ €์žฅ + responseList.forEach(response -> + redisRepository.addViewedPost(redisKey, response.getMealDiaryId().toString())); + + // redis TTL ์„ค์ • + redisRepository.setSessionTimeout(redisKey, TTL_MINUTES); + + return responseList; + } +}
Java
๋‹ค์‹œ ์ฝ์–ด ๋ณด๋‹ˆ ๋„ˆ๋ฌด ๋ฐ€์ง‘๋˜์–ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋„ค์š” ,, ์ถ”ํ›„ 2์ฐจ ์„ค๊ณ„ ๋•Œ ์ด ๋ถ€๋ถ„ ๊ผญ ์ธ์ง€ํ•ด์„œ ๋ฆฌํŒฉํ„ฐ๋ง ์ง„ํ–‰ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค !
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
import ์ˆœ์„œ์—๋„ ์œ ์ง€๋ณด์ˆ˜ ๋ฐ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•œ ์ปจ๋ฒค์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์œ„์ฝ”๋“œ์˜ ์ปจ๋ฒค์…˜์€ ๊ฐ„๋žตํ•˜๊ฒŒ ์•„๋ž˜์™€ ๊ฐ™๊ณ , ์ฐธ๊ณ ํ•ด์„œ ์ˆ˜์ •ํ•ด ์ฃผ์„ธ์š”! - ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ - React ๊ด€๋ จ ํŒจํ‚ค์ง€ - ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ - ์ปดํฌ๋„ŒํŠธ - ๊ณตํ†ต ์ปดํฌ๋„ŒํŠธ โ†’ ๋จผ ์ปดํฌ๋„ŒํŠธ โ†’ ๊ฐ€๊นŒ์šด ์ปดํฌ๋„ŒํŠธ - ํ•จ์ˆ˜, ๋ณ€์ˆ˜ ๋ฐ ์„ค์ • ํŒŒ์ผ - ์‚ฌ์ง„ ๋“ฑ ๋ฏธ๋””์–ด ํŒŒ์ผ(`.png`) - css ํŒŒ์ผ (.`scss`)
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
event ๊ฐ์ฒด์—๋Š” ์—ฌ๋Ÿฌ ๋ฐ์ดํ„ฐ๊ฐ€ ๋‹ด๊ฒจ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ์ค‘์—์„œ target์˜ value(input์— ์ž…๋ ฅํ•œ ๊ฐ’)๋งŒ์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ธ์ž๋กœ ์•„์˜ˆ event.target.value๋งŒ์„ ์ธ์ž๋กœ ๋„˜๊ฒจ์„œ ์‚ฌ์šฉํ•˜๋ฉด ์ด ํ•จ์ˆ˜์˜ ์‚ฌ์šฉ์ด ์ข€ ๋” ๋ช…ํ™•ํ•˜๊ฒ ๋„ค์š”!
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
์‹ค์ˆ˜๋กœ ๋ˆŒ๋ €์„ ๊ฒฝ์šฐ์—๋„ ๋ฌด์กฐ๊ฑด list ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๊ฒŒ ๋  ํ…๋ฐ, ์„ ํƒ๊ถŒ์„ ์ค„ ์ˆ˜๋„ ์žˆ๊ฒ ๋„ค์š”. `window.confirm` ํ•จ์ˆ˜์— ๋Œ€ํ•ด ์ฐพ์•„๋ณด๊ณ  ์ ์šฉํ•ด๋ณด์…”๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
fetch ํ•จ์ˆ˜์˜ ์ธ์ž๋Š” ๋ณดํ†ต 2๊ฐœ๊ฐ€ ๋“ค์–ด๊ฐ€๋Š”๋ฐ, ์ง€๊ธˆ์€ ์˜ต์…˜์— ๊ด€๋ จ๋œ ๋‘ ๋ฒˆ์งธ ์ธ์ž๋งŒ ์ž‘์„ฑ๋˜์–ด ์žˆ๋„ค์š”! ์‹ค์ œ๋กœ ํ†ต์‹ ํ•˜์‹ค ๋•Œ์—๋Š” ์ฒซ ๋ฒˆ์งธ ์ธ์ž์ธ `API` ๊ฐ’๋„ ์ž˜ ์ „๋‹ฌํ•ด ์ฃผ์„ธ์š”!
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
๋ถˆํ•„์š”ํ•˜๊ฒŒ 3์ค‘์œผ๋กœ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ, ์ผ๋‹จ ์ตœ์ƒ์œ„์˜ div๋Š” ๋ถˆํ•„์š”ํ•ด ๋ณด์ด๋„ค์š”! ์š”์†Œ๊ฐ€ ์ค‘์ฒฉ๋  ์ˆ˜๋ก, ํ”„๋กœ์ ํŠธ์˜ ๊ทœ๋ชจ๊ฐ€ ์ปค์งˆ ์ˆ˜๋ก ๋กœ๋”ฉ๋˜๋Š” ์‹œ๊ฐ„์ด ๊ธธ์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ๋ถˆํ•„์š”ํ•˜๊ฒŒ ์ค‘์ฒฉ๋œ ์š”์†Œ๋Š” ์ง€์›Œ์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
img ํƒœ๊ทธ์˜ alt ๊ฐ’์€ ์–ด๋””์— ํ™œ์šฉ๋ ๊นŒ์š”? ์ฐพ์•„๋ณด์‹œ๊ณ  ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”!
@@ -0,0 +1,79 @@ +.userBox { + margin: 20px; + gap: 0 24px; + display: flex; + justify-content: center; + flex-direction: column; + + .userWrap { + display: flex; + flex-direction: row; + justify-content: center; + + .user { + width: 50px; + height: 50px; + border-radius: 50%; + } + + .contentBox { + display: flex; + flex-direction: column; + gap: 10px; + margin-left: 20px; + + .userName { + font-size: 20px; + font-weight: 700; + } + + .textArea { + padding: 10px; + border-radius: 6px; + border: 1px solid var(--grey-88, #e0e0e0); + background: var(--white, #fff); + resize: none; + transition: border-color 0.3s; + outline: none; + } + .textArea:hover { + border-color: var(--gray, #999999); + } + + .buttonWrap { + justify-content: space-between; + display: flex; + + .customButton { + width: 120px; + height: 50px; + border-radius: 6px; + } + + .cancelButton { + border: 1px solid var(--blue, #2d71f7); + background: var(--white, #fff); + color: var(--blue, #2d71f7); + cursor: pointer; + } + .cancelButton:hover { + border: 1px solid var(--navy, #083e7f); + background: var(--white, #fff); + color: var(--navy, #083e7f); + } + + .addButton { + border: none; + background: var(--white, #2d71f7); + color: var(--white, #fff); + cursor: pointer; + } + .addButton:hover { + border: none; + background: var(--blue, #083e7f); + color: var(--white, #fff); + } + } + } + } +}
Unknown
PR์ด ๋จธ์ง€๋œ๋‹ค๋ฉด, ์ด ํ”„๋กœ์ ํŠธ์˜ ๋ชจ๋“  button ํƒœ๊ทธ์— `width: 120px, height: 50px` ์†์„ฑ์ด ์ ์šฉ๋˜๊ฒ ๋„ค์š”! ์ด๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์œ„์— ์ž˜ ํ•ด์ฃผ์‹  ๊ฒƒ์ฒ˜๋Ÿผ nesting๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ถ”๊ฐ€๋กœ, ํƒœ๊ทธ ์„ ํƒ์ž์˜ ์‚ฌ์šฉ์€ ๋‹ค์Œ์˜ ๊ฒฝ์šฐ ์™ธ์—๋Š” ์ง€์–‘ํ•˜๋Š” ๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค. 1. ์ „์—ญ์— ์ ์šฉ๋˜์–ด์•ผ ํ•˜๋Š” ์Šคํƒ€์ผ (e.g. common.scss, reset.scss) 2. ์•ž์œผ๋กœ๋„ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ํ™•์‹ ์ด ์žˆ๋Š” ์š”์†Œ className์„ ๋ถ€์—ฌํ•ด์„œ ์Šคํƒ€์ผ ์†์„ฑ ๋ถ€์—ฌํ•ด ์ฃผ์„ธ์š”!
@@ -1,7 +1,17 @@ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap'); - * { box-sizing: border-box; font-family: 'Noto Sans KR', sans-serif; -} \ No newline at end of file +} +body { + width: 100vw; + height: 100vh; + display: flex; + align-items: center; + justify-content: center; +} + +button { + cursor: pointer; +}
Unknown
๊ณต์šฉ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์„œ ์˜ฌ๋ ค์ฃผ์…จ๋Š”๋ฐ, ๊ณต์šฉ ํŒŒ์ผ์˜ ์ˆ˜์ •์€ 1. ํŒ€์›๊ณผ์˜ ์ถฉ๋ถ„ํ•œ ์ƒ์˜ ํ›„์— 2. ํ•ด๋‹น ํŒŒ์ผ๋งŒ ์ˆ˜์ •ํ•˜๋Š” ๋‚ด์šฉ์˜ PR ์„ ์˜ฌ๋ ค์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
๋ฉ˜ํ† ๋ฆฌ๋ทฐ ๋ฐ˜์˜ ์™„๋ฃŒ
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
๋ฉ˜ํ†  ๋ฆฌ๋ทฐ ๋ฐ˜์˜ ์™„๋ฃŒ
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
๋ฉ˜ํ†  ๋ฆฌ๋ทฐ ๋ฐ˜์˜์™„๋ฃŒ
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
alt ์†์„ฑ์€ ํ™”๋ฉด์— ์ด๋ฏธ์ง€๊ฐ€ ํ‘œ์‹œ๋˜์ง€ ์•Š์„๋•Œ ์‚ฌ์šฉ์ž๊ฐ€ ์•Œ ์ˆ˜ ์žˆ๋„๋ก ๋Œ€์ฒด ํ…์ŠคํŠธ๋ฅผ ์ œ๊ณตํ•˜๋Š” ์—ญํ• ์„ ํ•˜๊ธฐ ๋–„๋ฌธ์— alt ๊ฐ’์— userPicture๋ฅผ ๋„ฃ๊ฒ ์๋‹ˆ๋‹ค..
@@ -0,0 +1,79 @@ +.userBox { + margin: 20px; + gap: 0 24px; + display: flex; + justify-content: center; + flex-direction: column; + + .userWrap { + display: flex; + flex-direction: row; + justify-content: center; + + .user { + width: 50px; + height: 50px; + border-radius: 50%; + } + + .contentBox { + display: flex; + flex-direction: column; + gap: 10px; + margin-left: 20px; + + .userName { + font-size: 20px; + font-weight: 700; + } + + .textArea { + padding: 10px; + border-radius: 6px; + border: 1px solid var(--grey-88, #e0e0e0); + background: var(--white, #fff); + resize: none; + transition: border-color 0.3s; + outline: none; + } + .textArea:hover { + border-color: var(--gray, #999999); + } + + .buttonWrap { + justify-content: space-between; + display: flex; + + .customButton { + width: 120px; + height: 50px; + border-radius: 6px; + } + + .cancelButton { + border: 1px solid var(--blue, #2d71f7); + background: var(--white, #fff); + color: var(--blue, #2d71f7); + cursor: pointer; + } + .cancelButton:hover { + border: 1px solid var(--navy, #083e7f); + background: var(--white, #fff); + color: var(--navy, #083e7f); + } + + .addButton { + border: none; + background: var(--white, #2d71f7); + color: var(--white, #fff); + cursor: pointer; + } + .addButton:hover { + border: none; + background: var(--blue, #083e7f); + color: var(--white, #fff); + } + } + } + } +}
Unknown
๋ฉ˜ํ†  ๋ฆฌ๋ทฐ ๋ฐ˜์˜ ์™„๋ฃŒ
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
๋„ต!
@@ -1,14 +1,77 @@ -import React from "react"; -import "./PostAdd.scss"; +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import './PostAdd.scss'; +import { Button } from '../PostAdd/components/Post.jsx'; const PostAdd = () => { + const [comment, setComment] = useState(''); -return( - <div className="postAdd"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); -}; + const handleText = value => { + setComment(value); + }; + console.log(handleText); + + const cancel = () => { + const confirmed = window.confirm( + '์ ์œผ์‹  ๊ธ€์„ ์ทจ์†Œํ•˜๊ณ  post-list๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๊นŒ?', + ); + if (confirmed) { + navigate('/post-list'); + } + }; + + const posting = () => { + if (comment.length >= 1) { + navigate('/post-list'); -export default PostAdd; \ No newline at end of file + fetch({ + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify({ + content: '์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€', + }), + }) + .then(response => response.json) + .then(data => console.log(data)); + } else { + alert('๋‚ด์šฉ์„ ์ž‘์„ฑ์ฃผ์„ธ์š”.'); + } + }; + + return ( + <div className="userBox"> + <div className="userWrap"> + <img className="user" src="/images/user.png" alt="userPicture" /> + <div className="contentBox"> + <div className="userName">NAME</div> + <textarea + onChange={event => handleText(event.target.value)} + className="textArea" + cols="80" + rows="30" + type="text" + value={comment} + /> + + <div className="buttonWrap"> + <Button + className="customButton cancelButton" + buttonName="์ทจ์†Œ" + active={cancel} + /> + <Button + className="customButton addButton" + buttonName="๊ฒŒ์‹œ" + active={posting} + /> + </div> + </div> + </div> + </div> + ); +}; +export default PostAdd;
JavaScript
๋ฉ˜ํ†  ๋ฆฌ๋ทฐ ๋ฐ˜์˜ ์™„๋ฃŒ(?)
@@ -1,18 +1,21 @@ -package com.antique.service; +package com.antique.service.review; import com.antique.domain.Product; import com.antique.domain.Review; -import com.antique.domain.User; import com.antique.dto.review.ReviewRequestDTO; +import com.antique.domain.User; import com.antique.dto.user.GetUserReviewDTO; import com.antique.exception.BaseException; import com.antique.exception.CommonErrorCode; import com.antique.repository.ProductRepository; import com.antique.repository.ReviewRepository; import com.antique.repository.UserRepository; +import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @@ -49,6 +52,7 @@ public List<GetUserReviewDTO> getUserReviews(Long userId) { /* * ๋ฆฌ๋ทฐ ์ž‘์„ฑ */ + @Transactional public Review createReview(ReviewRequestDTO reviewRequest) { User reviewer = userRepository.findById(reviewRequest.getReviewerId()) .orElseThrow(() -> new BaseException(CommonErrorCode.USER_NOT_FOUND)); @@ -67,6 +71,65 @@ public Review createReview(ReviewRequestDTO reviewRequest) { .content(reviewRequest.getContent()) .reviewDate(LocalDateTime.now()) .build(); + + updateUserRating(reviewedUser.getUserId()); + return reviewRepository.save(review); } + + /* + * ๋ฆฌ๋ทฐ ์ˆ˜์ • + */ + @Transactional + public Review updateReview(Long reviewId, ReviewRequestDTO reviewRequest) { + Review review = reviewRepository.findById(reviewId) + .orElseThrow(() -> new BaseException(CommonErrorCode.REVIEW_IS_NOT_EXIST)); + + Long reviewedUserId = review.getReviewedUser().getUserId(); + + review.setRating(reviewRequest.getRating()); + review.setContent(reviewRequest.getContent()); + review.setReviewDate(LocalDateTime.now()); + + updateUserRating(reviewedUserId); + + return reviewRepository.save(review); + } + + /* + * ๋ฆฌ๋ทฐ ์‚ญ์ œ + */ + @Transactional + public void deleteReview(Long reviewId) { + Review review = reviewRepository.findById(reviewId) + .orElseThrow(() -> new BaseException(CommonErrorCode.REVIEW_IS_NOT_EXIST)); + + Long reviewedUserId = review.getReviewedUser().getUserId(); + + updateUserRating(reviewedUserId); + + reviewRepository.delete(review); + } + + /* + * ์‚ฌ์šฉ์ž ํ‰์  update ๋ฉ”์„œ๋“œ + */ + public void updateUserRating(Long userId) { + List<Review> reviews = reviewRepository.findByReviewedUser_UserId(userId); + + if(reviews.isEmpty()) { + userRepository.updateUserRating(userId, 0); + return; + } + + double averageRating = reviews.stream() + .mapToInt(Review::getRating) + .average() + .orElse(0.0); + + BigDecimal roundedRating = BigDecimal.valueOf(averageRating) + .setScale(1, RoundingMode.HALF_UP); + + userRepository.updateUserRating(userId, roundedRating.doubleValue()); + } }
Java
์ˆ˜์ • ๋ฐ ์‚ญ์ œ ๋ฉ”์†Œ๋“œ์— ์•ˆ์ „ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ž‘์—…์„ ์œ„ํ•ด์„œ @Transactional ์–ด๋…ธํ…Œ์ด์…˜์„ ๋ถ™์ด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„~~ ์ฐธ๊ณ ์ž๋ฃŒ https://velog.io/@zedy_dev/Transactional-%EC%96%B4%EB%85%B8%ED%85%8C%EC%9D%B4%EC%85%98%EC%9D%84-%ED%86%B5%ED%95%9C-%ED%8A%B8%EB%9E%9C%EC%9E%AD%EC%85%98-%EA%B4%80%EB%A6%AC-%EB%9E%80-%ED%99%9C%EC%9A%A9%EB%B0%A9%EB%B2%95-%EB%82%B4-%EA%B2%BD%ED%97%98
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react"; import styled from "@emotion/styled"; import { css, Theme } from "@emotion/react"; import CheckIcon from "components/inputs/TextInput/CheckIcon"; -import { TConditionCheck } from "./types/TConditionCheck"; +import { TConditionCheck } from "components/inputs/TextInput/types/TConditionCheck"; interface Props { name?: string; @@ -12,6 +12,7 @@ interface Props { conditionList?: string[]; conditionCheckList?: TConditionCheck[]; multiline?: boolean; + height?: string; onTextChange?: (value: string, isValid: boolean) => void; } @@ -23,6 +24,7 @@ const TextInput: React.FC<Props> = ({ conditionList, conditionCheckList, multiline = false, + height, onTextChange, }) => { const [status, setStatus] = useState(value === "" ? "default" : "success"); // default / success / invalid / focus @@ -76,7 +78,7 @@ const TextInput: React.FC<Props> = ({ }, [enteredValue, status, onTextChange]); return ( - <EmotionWrapper> + <EmotionWrapper height={height}> {label && <span className="label">{label}</span>} {conditionList && ( <div className="spanList"> @@ -179,6 +181,7 @@ const EmotionWrapper = styled.div<Props>` ${({ theme }) => commonStyles(theme)}; position: relative; resize: none; + height: ${({ height }) => height ?? "auto"}; } `;
Unknown
์‚ฌ์†Œํ•˜์ง€๋งŒ `height ?? "auto"` ๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,170 @@ +import styled from "@emotion/styled"; +import IconStarFilled from "components/rating/icons/IconStarFilled"; +import IconStarHalf from "components/rating/icons/IconStarHalf"; +import IconStarOutlined from "components/rating/icons/IconStarOutlined"; +import { HTMLAttributes, useEffect, useState, useRef, useCallback } from "react"; + +interface Props extends HTMLAttributes<HTMLDivElement> { + value: number; // 0 ~ 5 ์‚ฌ์ด์˜ ์ˆซ์ž, ๋ณ„ ๊ฐœ์ˆ˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด 0.5 ๋‹จ์œ„๋กœ ๋ฐ˜์˜ฌ๋ฆผ + isInput?: boolean; // input ๊ธฐ๋Šฅ์„ ํ•˜๋„๋ก ํ•  ์ง€ ์„ค์ • + onSelectedValueChange?: (value: number) => void; +} + +const Rating = ({ value, isInput = false, onSelectedValueChange, ...props }: Props) => { + const [selectedValue, setSelectedValue] = useState<number>(value); + const isMouseDown = useRef<boolean>(false); + const containerRef = useRef<HTMLDivElement>(null); + + // round value to the nearest 0.5 + const startCount = Math.round(selectedValue * 2) / 2; + + const filledStarCount = Math.floor(startCount); + const hasHalfStar = startCount % 1 !== 0; + const emptyStarCount = 5 - filledStarCount - (hasHalfStar ? 1 : 0); + + useEffect(() => { + if (onSelectedValueChange) { + onSelectedValueChange(selectedValue); + } + }, [selectedValue, onSelectedValueChange]); + + const handleOnClick = (event: React.MouseEvent, index: number) => { + const clickX = event.nativeEvent.clientX; // ํด๋ฆญํ•œ ์œ„์น˜์˜ X ์ขŒํ‘œ + + // IconStar... ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ํด๋ฆญํ•œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํŒ๋ณ„ + const containerRect = event.currentTarget.getBoundingClientRect(); + const containerCenterX = (containerRect.left + containerRect.right) / 2; + + if (clickX < containerCenterX) { + setSelectedValue(index + 0.5); + } else { + setSelectedValue(index + 1); + } + }; + + const calculateScore = useCallback((currentX: number) => { + const container = containerRef.current; + if (container) { + const unitSize = container.getBoundingClientRect().width / 10; + const relativeX = currentX - container.getBoundingClientRect().x; + if (relativeX <= 0) setSelectedValue(0.5); + else { + const score = (Math.floor(relativeX / unitSize) + 1) * 0.5; + score > 5 ? setSelectedValue(5) : setSelectedValue(score); + } + } + }, []); + + const handleOnMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = true; + }, []); + + const handleOnMouseLeave = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = false; + }, []); + + const handleOnMouseMove = useCallback( + (event: React.MouseEvent) => { + if (isMouseDown.current) calculateScore(event.clientX); + }, + [calculateScore] + ); + + const handleOnMouseUp = useCallback((event: React.MouseEvent) => { + isMouseDown.current = false; + }, []); + + // For mobile view + const handleOnTouchMove = useCallback( + (event: React.TouchEvent) => { + calculateScore(event.changedTouches[0].clientX); + }, + [calculateScore] + ); + + return ( + <EmotionWrapper isInput={isInput} {...props}> + <div + className="star-container" + onMouseDown={handleOnMouseDown} + onMouseUp={handleOnMouseUp} + onMouseMove={handleOnMouseMove} + onMouseLeave={handleOnMouseLeave} + onTouchMove={handleOnTouchMove} + ref={containerRef} + > + {Array.from({ length: filledStarCount }, (_, index) => + isInput ? ( + <IconStarFilled + key={index} + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, index)} + /> + ) : ( + <IconStarFilled key={index} /> + ) + )} + {hasHalfStar && + (isInput ? ( + <IconStarHalf + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, filledStarCount)} + /> + ) : ( + <IconStarHalf /> + ))} + {Array.from({ length: emptyStarCount }, (_, index) => + isInput ? ( + <IconStarOutlined + key={index} + size={40} + onClick={(event: React.MouseEvent) => + handleOnClick(event, filledStarCount + index + (hasHalfStar ? 1 : 0)) + } + /> + ) : ( + <IconStarOutlined key={index} /> + ) + )} + </div> + {isInput ? ( + <div> + <span className="rating-value-selected">{selectedValue}</span> + <span className="rating-full-marks"> / 5</span> + </div> + ) : ( + <p className="rating-value">{value}</p> + )} + </EmotionWrapper> + ); +}; + +export default Rating; + +const EmotionWrapper = styled.div<{ isInput: boolean }>` + display: flex; + align-items: center; + ${({ isInput }) => (isInput ? "flex-direction: column; gap: 20px;" : "column-gap: 4px;")} + + .star-container { + display: flex; + column-gap: 2px; + } + + color: ${({ theme }) => theme.color.gray400}; + + .rating-full-marks { + font-size: 16px; + font-weight: 300; + } + + .rating-value-selected { + font-size: 32px; + font-weight: 500; + color: ${({ theme }) => theme.color.gray700}; + } + + .rating-value { + font-size: 12px; + } +`;
Unknown
์˜ค ์ด ์ปดํฌ๋„ŒํŠธ๋Š” ์•„์ง Rating์ชฝ์ด ๋จธ์ง€ ๋˜์ง€ ์•Š์•„์„œ ์ผ๋ถ€ ๋‚ด์šฉ์„ ๊ทธ๋Œ€๋กœ ๊ฐ€์ง€๊ณ  ์˜ค์‹  ๋ถ€๋ถ„์ธ๊ฐ€์šฉ~? (+ `isInput` ๋ชจ๋“œ ์ถ”๊ฐ€๋กœ์š”?)
@@ -0,0 +1,170 @@ +import styled from "@emotion/styled"; +import IconStarFilled from "components/rating/icons/IconStarFilled"; +import IconStarHalf from "components/rating/icons/IconStarHalf"; +import IconStarOutlined from "components/rating/icons/IconStarOutlined"; +import { HTMLAttributes, useEffect, useState, useRef, useCallback } from "react"; + +interface Props extends HTMLAttributes<HTMLDivElement> { + value: number; // 0 ~ 5 ์‚ฌ์ด์˜ ์ˆซ์ž, ๋ณ„ ๊ฐœ์ˆ˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด 0.5 ๋‹จ์œ„๋กœ ๋ฐ˜์˜ฌ๋ฆผ + isInput?: boolean; // input ๊ธฐ๋Šฅ์„ ํ•˜๋„๋ก ํ•  ์ง€ ์„ค์ • + onSelectedValueChange?: (value: number) => void; +} + +const Rating = ({ value, isInput = false, onSelectedValueChange, ...props }: Props) => { + const [selectedValue, setSelectedValue] = useState<number>(value); + const isMouseDown = useRef<boolean>(false); + const containerRef = useRef<HTMLDivElement>(null); + + // round value to the nearest 0.5 + const startCount = Math.round(selectedValue * 2) / 2; + + const filledStarCount = Math.floor(startCount); + const hasHalfStar = startCount % 1 !== 0; + const emptyStarCount = 5 - filledStarCount - (hasHalfStar ? 1 : 0); + + useEffect(() => { + if (onSelectedValueChange) { + onSelectedValueChange(selectedValue); + } + }, [selectedValue, onSelectedValueChange]); + + const handleOnClick = (event: React.MouseEvent, index: number) => { + const clickX = event.nativeEvent.clientX; // ํด๋ฆญํ•œ ์œ„์น˜์˜ X ์ขŒํ‘œ + + // IconStar... ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ํด๋ฆญํ•œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํŒ๋ณ„ + const containerRect = event.currentTarget.getBoundingClientRect(); + const containerCenterX = (containerRect.left + containerRect.right) / 2; + + if (clickX < containerCenterX) { + setSelectedValue(index + 0.5); + } else { + setSelectedValue(index + 1); + } + }; + + const calculateScore = useCallback((currentX: number) => { + const container = containerRef.current; + if (container) { + const unitSize = container.getBoundingClientRect().width / 10; + const relativeX = currentX - container.getBoundingClientRect().x; + if (relativeX <= 0) setSelectedValue(0.5); + else { + const score = (Math.floor(relativeX / unitSize) + 1) * 0.5; + score > 5 ? setSelectedValue(5) : setSelectedValue(score); + } + } + }, []); + + const handleOnMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = true; + }, []); + + const handleOnMouseLeave = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = false; + }, []); + + const handleOnMouseMove = useCallback( + (event: React.MouseEvent) => { + if (isMouseDown.current) calculateScore(event.clientX); + }, + [calculateScore] + ); + + const handleOnMouseUp = useCallback((event: React.MouseEvent) => { + isMouseDown.current = false; + }, []); + + // For mobile view + const handleOnTouchMove = useCallback( + (event: React.TouchEvent) => { + calculateScore(event.changedTouches[0].clientX); + }, + [calculateScore] + ); + + return ( + <EmotionWrapper isInput={isInput} {...props}> + <div + className="star-container" + onMouseDown={handleOnMouseDown} + onMouseUp={handleOnMouseUp} + onMouseMove={handleOnMouseMove} + onMouseLeave={handleOnMouseLeave} + onTouchMove={handleOnTouchMove} + ref={containerRef} + > + {Array.from({ length: filledStarCount }, (_, index) => + isInput ? ( + <IconStarFilled + key={index} + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, index)} + /> + ) : ( + <IconStarFilled key={index} /> + ) + )} + {hasHalfStar && + (isInput ? ( + <IconStarHalf + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, filledStarCount)} + /> + ) : ( + <IconStarHalf /> + ))} + {Array.from({ length: emptyStarCount }, (_, index) => + isInput ? ( + <IconStarOutlined + key={index} + size={40} + onClick={(event: React.MouseEvent) => + handleOnClick(event, filledStarCount + index + (hasHalfStar ? 1 : 0)) + } + /> + ) : ( + <IconStarOutlined key={index} /> + ) + )} + </div> + {isInput ? ( + <div> + <span className="rating-value-selected">{selectedValue}</span> + <span className="rating-full-marks"> / 5</span> + </div> + ) : ( + <p className="rating-value">{value}</p> + )} + </EmotionWrapper> + ); +}; + +export default Rating; + +const EmotionWrapper = styled.div<{ isInput: boolean }>` + display: flex; + align-items: center; + ${({ isInput }) => (isInput ? "flex-direction: column; gap: 20px;" : "column-gap: 4px;")} + + .star-container { + display: flex; + column-gap: 2px; + } + + color: ${({ theme }) => theme.color.gray400}; + + .rating-full-marks { + font-size: 16px; + font-weight: 300; + } + + .rating-value-selected { + font-size: 32px; + font-weight: 500; + color: ${({ theme }) => theme.color.gray700}; + } + + .rating-value { + font-size: 12px; + } +`;
Unknown
์˜ค... ๋›ฐ์–ด๋‚œ ์‚ฌ์šฉ์„ฑ์ผ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜† ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,120 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Rating from "components/rating/Rating"; +import IconEditFilledWhite from "components/icons/IconEditFilledWhite"; +import Link from "next/link"; +import dayjs from "dayjs"; + +interface Props { + restaurantId: string; + reviewId: number; + userId: number; + score: number; + content: string; + createdAt: Date; +} + +const ReviewItem: React.FC<Props> = ({ + restaurantId, + reviewId, + userId, + score, + content, + createdAt, +}) => { + const [isExpanded, setIsExpanded] = useState(false); + + const toggleExpansion = () => { + setIsExpanded((isExpanded) => !isExpanded); + }; + + const editLink = `/restaurants/${restaurantId}/review/${reviewId}/edit`; + const displayContent = + content.length > 100 && !isExpanded ? content.slice(0, 100) + "..." : content; + + /** + * TODO 1: userId๋กœ userInfo ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userName = "ํ™๊ธธ๋™"; + const ImgSrc = "/images/profile-image-default-1.png"; + + /** + * TODO 2: ํ˜„์žฌ ๋กœ๊ทธ์ธ๋œ ์œ ์ € ์•„์ด๋”” ๊ฐ€์ ธ์˜ค๊ธฐ (๋ฆฌ๋ทฐ ์ˆ˜์ • ๊ถŒํ•œ ํ™•์ธ์šฉ) + */ + const currentUserId = 1; + + return ( + <EmotionWrapper> + <div className="user-info-score-div"> + <div className="user-info-div"> + <Image src={ImgSrc} alt={"์œ ์ € ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"} width={30} height={30} /> + <span className="user-name">{userName}</span> + <span className="date">{dayjs(createdAt).format("YY/MM/DD")}</span> + {currentUserId === userId && ( + <Link href={editLink}> + <IconEditFilledWhite /> + </Link> + )} + </div> + <Rating value={score} /> + </div> + <div className="content-div"> + <span>{displayContent}</span> + {content.length > 100 && ( + <button onClick={toggleExpansion}>{isExpanded ? "์ ‘๊ธฐ" : "๋” ๋ณด๊ธฐ"}</button> + )} + </div> + </EmotionWrapper> + ); +}; + +export default ReviewItem; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + min-height: 90px; + width: 100%; + background-color: ${({ theme }) => theme.color.white}; + border-radius: 6px; + + padding: 10px; + + .user-info-score-div { + display: flex; + justify-content: space-between; + align-items: center; + + .user-info-div { + display: flex; + gap: 8px; + justify-content: center; + align-items: center; + + span.user-name { + font-size: 16px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + span.date { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray300}; + } + } + } + + .content-div { + span { + line-height: 1.5; + color: ${({ theme }) => theme.color.gray400}; + flex-grow: 1; + margin-right: 8px; + } + + button { + color: ${({ theme }) => theme.color.gray300}; + } + } +`;
Unknown
์˜ค..! ์ €ํฌ๊ฐ€ `dayjs` ๋„ ์“ฐ๊ณ  ์žˆ์–ด์„œ ํ™œ์šฉํ•ด๋ณด์‹œ๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์ด๋Ÿฐ ๊ฒฝ์šฐ ```tsx import dayjs from 'dayjs'; const formattedDate= dayjs(date).format("YY/MM/DD") ``` ์ด๋ ‡๊ฒŒ ํ™œ์šฉํ•ด๋ณผ ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~
@@ -0,0 +1,120 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Rating from "components/rating/Rating"; +import IconEditFilledWhite from "components/icons/IconEditFilledWhite"; +import Link from "next/link"; +import dayjs from "dayjs"; + +interface Props { + restaurantId: string; + reviewId: number; + userId: number; + score: number; + content: string; + createdAt: Date; +} + +const ReviewItem: React.FC<Props> = ({ + restaurantId, + reviewId, + userId, + score, + content, + createdAt, +}) => { + const [isExpanded, setIsExpanded] = useState(false); + + const toggleExpansion = () => { + setIsExpanded((isExpanded) => !isExpanded); + }; + + const editLink = `/restaurants/${restaurantId}/review/${reviewId}/edit`; + const displayContent = + content.length > 100 && !isExpanded ? content.slice(0, 100) + "..." : content; + + /** + * TODO 1: userId๋กœ userInfo ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userName = "ํ™๊ธธ๋™"; + const ImgSrc = "/images/profile-image-default-1.png"; + + /** + * TODO 2: ํ˜„์žฌ ๋กœ๊ทธ์ธ๋œ ์œ ์ € ์•„์ด๋”” ๊ฐ€์ ธ์˜ค๊ธฐ (๋ฆฌ๋ทฐ ์ˆ˜์ • ๊ถŒํ•œ ํ™•์ธ์šฉ) + */ + const currentUserId = 1; + + return ( + <EmotionWrapper> + <div className="user-info-score-div"> + <div className="user-info-div"> + <Image src={ImgSrc} alt={"์œ ์ € ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"} width={30} height={30} /> + <span className="user-name">{userName}</span> + <span className="date">{dayjs(createdAt).format("YY/MM/DD")}</span> + {currentUserId === userId && ( + <Link href={editLink}> + <IconEditFilledWhite /> + </Link> + )} + </div> + <Rating value={score} /> + </div> + <div className="content-div"> + <span>{displayContent}</span> + {content.length > 100 && ( + <button onClick={toggleExpansion}>{isExpanded ? "์ ‘๊ธฐ" : "๋” ๋ณด๊ธฐ"}</button> + )} + </div> + </EmotionWrapper> + ); +}; + +export default ReviewItem; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + min-height: 90px; + width: 100%; + background-color: ${({ theme }) => theme.color.white}; + border-radius: 6px; + + padding: 10px; + + .user-info-score-div { + display: flex; + justify-content: space-between; + align-items: center; + + .user-info-div { + display: flex; + gap: 8px; + justify-content: center; + align-items: center; + + span.user-name { + font-size: 16px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + span.date { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray300}; + } + } + } + + .content-div { + span { + line-height: 1.5; + color: ${({ theme }) => theme.color.gray400}; + flex-grow: 1; + margin-right: 8px; + } + + button { + color: ${({ theme }) => theme.color.gray300}; + } + } +`;
Unknown
`className` ์€ ๋”ฐ๋กœ ์ปจ๋ฒค์…˜์ด ์žˆ๋Š” ๊ฒƒ์€ ์•„๋‹ˆ์ง€๋งŒ ๋Œ€๋ถ€๋ถ„ kebab case ๋ฅผ ์ ์šฉํ•˜๊ณ  ์žˆ์–ด `user-info-score-div` ์ด๋Ÿฐ ์‹์€ ์–ด๋–จ๊นŒ์š”~?
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
์ด `restaurantId` ๊ฐ€ `string[]` ๋„ ๋ฐ›๊ฒŒ ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”~?
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
์•— ์—ฌ๊ธฐ๋„ `over-title-div` ์ด๋ ‡๊ฒŒ ๊ฐ€ ์–ด๋–จ๊นŒ์š” !
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
์—ฌ๊ธฐ๋Š” ์ด ํŽ˜์ด์ง€์—์„œ ๊ฑฐ์˜ ๋ฉ”์ธ ๊ธ‰ ์ œ๋ชฉ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ `<h1 />` ํƒœ๊ทธ ์ •๋„๋กœ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋–จ๊นŒ์š”~? ์•„๋ž˜๋Š” ๋ ˆํผ๋Ÿฐ์Šค์šฉ [ํŽ˜์ด์Šค๋ถ] ์˜ ๋ฉค๋ฒ„ ์ƒ์„ธ ํŽ˜์ด์ง€์ธ๋ฐ ์„œ๋น„์Šค ์ œ๋ชฉ (์ €ํฌ๋กœ ์น˜๋ฉด '์ฉ์ฉ๋Œ€ํ•™') ์€ `<h2/>` ํƒœ๊ทธ, ์œ ์ € ์ด๋ฆ„์€ `<h1/>` ์œผ๋กœ ์‚ฌ์šฉํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €ํฌ๋„ ์˜คํžˆ๋ ค ์ƒ๋‹จ navbar ์—์„œ [์ฉ์ฉ๋Œ€ํ•™] ์„ `<h2 />` ๋กœ ๋ฐ”๊พธ๊ณ  ๋ง›์ง‘์ด๋‚˜ ๋‹จ์ฒด ์ƒ์„ธ ํŽ˜์ด์ง€์—์„œ ๋ง›์ง‘์ด๋ฆ„, ๋‹จ์ฒด์ด๋ฆ„์€ `<h1/>` ์— ๋„ฃ์œผ๋ฉด semantic tagging ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ SEO ์—๋„ ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! cc. @hoon5083 ![image](https://github.com/SystemConsultantGroup/foodhub-frontend/assets/86560973/31909b28-e965-4157-9662-f9cc6f8ddd4c) ![image](https://github.com/SystemConsultantGroup/foodhub-frontend/assets/86560973/9ba5c818-272f-4814-afe4-7d66dd4ed369)
@@ -0,0 +1,85 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Button from "components/button/Button"; + +interface Props { + imgSrcList: string[]; +} + +const RestaurantDetailImgSection: React.FC<Props> = ({ imgSrcList }) => { + const [currentImgIndex, setCurrentImgIndex] = useState(0); + + const handleOnClickRight = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == imgSrcList.length - 1 ? 0 : currentImgIndex + 1 + ); + }; + + const handleOnClickLeft = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == 0 ? imgSrcList.length - 1 : currentImgIndex - 1 + ); + }; + + return ( + <EmotionWrapper> + {imgSrcList.length === 0 ? ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ๊ธฐ๋ณธ ์ด๋ฏธ์ง€" + src={"/images/defaults/default-restaurant-image.png"} + fill + /> + ) : ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ์ด๋ฏธ์ง€" + src={imgSrcList[currentImgIndex]} + fill + /> + )} + <Button + onClick={handleOnClickLeft} + variant="text" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + left: "0px", + }} + > + &lt; + </Button> + <Button + onClick={handleOnClickRight} + variant="text" + className="right-button" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + right: "0px", + }} + > + &gt; + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailImgSection; + +const EmotionWrapper = styled.div` + position: relative; + width: 100%; + height: 120px; + overflow: hidden; + margin-bottom: 10px; + + .restaurant-img { + z-index: 1; + object-fit: cover; + position: absolute; + } +`;
Unknown
ํ˜น์‹œ ์ด ๋ฒ„ํŠผ์€ ํ™”๋ฉด์ƒ์˜ ์–ด๋А ๋ถ€๋ถ„์ธ๊ฐ€์šฉ~? ๋กœ์ปฌ์—์„œ ๋Œ๋ ธ์„ ๋•Œ ๋…ธ์ถœ๋˜์ง€ ์•Š๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ![image](https://github.com/SystemConsultantGroup/foodhub-frontend/assets/86560973/c705c6dd-3624-40d6-8639-8764bd45609d)
@@ -0,0 +1,70 @@ +import styled from "@emotion/styled"; +import RestaurantDetailImgSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailImgSection"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import RestaurantDetailInfoSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailInfoSection"; +import RestaurantDetailReviewSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailReviewSection"; +import Divider from "components/divider/Divider"; +import { restaurant } from "feature/restaurants/restaurantsDetail/mockups/restaurant"; +import { reviewPage1 } from "feature/restaurants/restaurantsDetail/mockups/reviews"; + +interface Props { + restaurantId: string; +} + +const ViewRestaurantDetail: React.FC<Props> = ({ restaurantId }) => { + /** + * TODO 1: ์‚ฌ์šฉ์ž ๊ถŒํ•œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userAuth = 0; + + /** + * TODO 2: ๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + /** + * TODO3: ๋ง›์ง‘์˜ ๋ชจ๋“  ๋ฆฌ๋ทฐ ์กฐํšŒํ•˜๊ธฐ + * - totalScore, totalPages ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ Read Reviews API ํ˜ธ์ถœ + * - ๋ฆฌ๋ทฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ 404 ์—๋Ÿฌ ๋ฐ˜ํ™˜? + */ + const { totalScore, totalCount, totalPages, scoreStatistics } = reviewPage1; + + return ( + <EmotionWrapper> + <RestaurantDetailImgSection imgSrcList={restaurant.imgSrcList} /> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + userAuth={userAuth} + restaurantName={restaurant.name} + restaurantAddress={restaurant.address} + organizationName={restaurant.organizationName} + link={restaurant.link} + /> + <RestaurantDetailInfoSection + restaurantId={restaurantId} + comment={restaurant.comment} + orderTip={restaurant.orderTip} + capacity={restaurant.capacity} + recommendedMenus={restaurant.recommnededMenus} + category={restaurant.category} + delivery={restaurant.delivery} + openingHour={restaurant.openingHour} + tags={restaurant.tags} + totalScore={totalScore} + totalCount={totalCount} + /> + <Divider /> + <RestaurantDetailReviewSection + restaurantId={restaurantId} + userAuth={userAuth} + totalScore={totalScore} + totalCount={totalCount} + totalPages={totalPages} + scoreStatistics={scoreStatistics} + /> + </EmotionWrapper> + ); +}; + +export default ViewRestaurantDetail; + +const EmotionWrapper = styled.div``;
Unknown
์ž„์‹œ ์ฝ”๋“œ์ธ๊ฐ€์š”!? ๊ฐ์ฒด๊ตฌ์กฐ ๋ถ„ํ•ด๋กœ ๋ฐ›์•„์˜ค๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ```tsx const { totalScore, totalCount, totalPages, scoreStatistics } = reviewPage1 ```
@@ -0,0 +1,137 @@ +import styled from "@emotion/styled"; +import Rating from "components/rating/Rating"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import Button from "components/button/Button"; +import TextInput from "components/inputs/TextInput/TextInput"; +import { useState, useCallback } from "react"; +import Checkbox from "components/checkbox/Checkbox"; +import { REVIEW_CONTENT_MAX_VALUE, REVIEW_CONTENT_MIN_VALUE } from "constant/limit"; + +interface Props { + restaurantId: string; + isEditMode: boolean; + reviewId?: string | number | string[]; + score?: number; + content?: string; +} + +const RestaurantsReviewForm: React.FC<Props> = ({ restaurantId, score = 0, content = "" }) => { + const [selectedScroe, setSelectedScore] = useState<number>(score); + const [enteredContent, setEnteredContent] = useState<string>(content); + const [isPublic, setIsPublic] = useState<boolean>(true); + + /** + * TODO: restaurantId๋กœ ๋ง›์ง‘ ์ƒ์„ธ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + const contentMaxLengthCheck = { + condition: (content: string) => { + return content.length <= REVIEW_CONTENT_MAX_VALUE; + }, + messageOnError: "500์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const contentMinLengthCheck = { + condition: (content: string) => { + return content.length >= REVIEW_CONTENT_MIN_VALUE; + }, + messageOnError: "20์ž ์ด์ƒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const handleScoreChange = useCallback((value: number) => { + setSelectedScore(value); + }, []); + + const handleContentChange = useCallback((value: string) => { + setEnteredContent(value); + }, []); + + const handleSetIsPublic = useCallback((value: string) => { + if (value === "true") setIsPublic(true); + else setIsPublic(false); + }, []); + + const handleOnSubmit = () => { + console.log("์ ์ˆ˜ : ", selectedScroe); + console.log("๋ฆฌ๋ทฐ ๋‚ด์šฉ : ", enteredContent); + console.log("๊ณต๊ฐœ ์—ฌ๋ถ€ : ", isPublic); + }; + + return ( + <EmotionWrapper> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + restaurantName="๋ด‰์ˆ˜์œก" + restaurantAddress="๊ฒฝ๊ธฐ๋„ ์ˆ˜์›์‹œ ์ฒœ์ฒœ๋™" + organizationName="์‹œ์Šคํ…œ ์ปจ์„คํ„ดํŠธ ๊ทธ๋ฃน" + isMain={false} + /> + <Rating value={score} isInput onSelectedValueChange={handleScoreChange} /> + <TextInput + label="๋ฆฌ๋ทฐ ๋‚ด์šฉ" + placeholder="๋ง›์ง‘์— ๋Œ€ํ•œ ์†”์งํ•œ ํ‰์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!" + multiline + value={content} + onTextChange={handleContentChange} + conditionCheckList={[contentMaxLengthCheck, contentMinLengthCheck]} + height="150px" + /> + <div className="right-alignment"> + <p className="label">๋ฆฌ๋ทฐ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.</p> + <Checkbox.Group + checkedList={[String(isPublic)]} + setCheckedItem={(value) => handleSetIsPublic(value)} + > + <Checkbox.Item value="true">๊ณต๊ฐœ</Checkbox.Item> + <Checkbox.Item value="false">๋น„๊ณต๊ฐœ</Checkbox.Item> + </Checkbox.Group> + {!isPublic && ( + <p className="description">๋น„๊ณต๊ฐœ๋กœ ์„ค์ •์‹œ, ๋‹จ์ฒด ์™ธ๋ถ€์ธ์—๊ฒŒ๋Š” ๋ฆฌ๋ทฐ๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</p> + )} + </div> + <Button onClick={handleOnSubmit} fullWidth> + ์ž‘์„ฑ ์™„๋ฃŒ + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantsReviewForm; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 30px; + + textarea { + font-size: 16px; + } + + button { + font-size: 16px; + } + + .right-alignment { + margin-top: -15px; + width: 100%; + } + + .label { + margin-top: 20px; + margin-bottom: 10px; + margin-left: 2px; + font-weight: 500; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + .description { + margin-top: 5px; + margin-left: 2px; + font-size: 14px; + font-weight: 200; + color: ${({ theme }) => theme.color.gray600}; + } +`;
Unknown
์˜คํƒ€๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,137 @@ +import styled from "@emotion/styled"; +import Rating from "components/rating/Rating"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import Button from "components/button/Button"; +import TextInput from "components/inputs/TextInput/TextInput"; +import { useState, useCallback } from "react"; +import Checkbox from "components/checkbox/Checkbox"; +import { REVIEW_CONTENT_MAX_VALUE, REVIEW_CONTENT_MIN_VALUE } from "constant/limit"; + +interface Props { + restaurantId: string; + isEditMode: boolean; + reviewId?: string | number | string[]; + score?: number; + content?: string; +} + +const RestaurantsReviewForm: React.FC<Props> = ({ restaurantId, score = 0, content = "" }) => { + const [selectedScroe, setSelectedScore] = useState<number>(score); + const [enteredContent, setEnteredContent] = useState<string>(content); + const [isPublic, setIsPublic] = useState<boolean>(true); + + /** + * TODO: restaurantId๋กœ ๋ง›์ง‘ ์ƒ์„ธ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + const contentMaxLengthCheck = { + condition: (content: string) => { + return content.length <= REVIEW_CONTENT_MAX_VALUE; + }, + messageOnError: "500์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const contentMinLengthCheck = { + condition: (content: string) => { + return content.length >= REVIEW_CONTENT_MIN_VALUE; + }, + messageOnError: "20์ž ์ด์ƒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const handleScoreChange = useCallback((value: number) => { + setSelectedScore(value); + }, []); + + const handleContentChange = useCallback((value: string) => { + setEnteredContent(value); + }, []); + + const handleSetIsPublic = useCallback((value: string) => { + if (value === "true") setIsPublic(true); + else setIsPublic(false); + }, []); + + const handleOnSubmit = () => { + console.log("์ ์ˆ˜ : ", selectedScroe); + console.log("๋ฆฌ๋ทฐ ๋‚ด์šฉ : ", enteredContent); + console.log("๊ณต๊ฐœ ์—ฌ๋ถ€ : ", isPublic); + }; + + return ( + <EmotionWrapper> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + restaurantName="๋ด‰์ˆ˜์œก" + restaurantAddress="๊ฒฝ๊ธฐ๋„ ์ˆ˜์›์‹œ ์ฒœ์ฒœ๋™" + organizationName="์‹œ์Šคํ…œ ์ปจ์„คํ„ดํŠธ ๊ทธ๋ฃน" + isMain={false} + /> + <Rating value={score} isInput onSelectedValueChange={handleScoreChange} /> + <TextInput + label="๋ฆฌ๋ทฐ ๋‚ด์šฉ" + placeholder="๋ง›์ง‘์— ๋Œ€ํ•œ ์†”์งํ•œ ํ‰์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!" + multiline + value={content} + onTextChange={handleContentChange} + conditionCheckList={[contentMaxLengthCheck, contentMinLengthCheck]} + height="150px" + /> + <div className="right-alignment"> + <p className="label">๋ฆฌ๋ทฐ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.</p> + <Checkbox.Group + checkedList={[String(isPublic)]} + setCheckedItem={(value) => handleSetIsPublic(value)} + > + <Checkbox.Item value="true">๊ณต๊ฐœ</Checkbox.Item> + <Checkbox.Item value="false">๋น„๊ณต๊ฐœ</Checkbox.Item> + </Checkbox.Group> + {!isPublic && ( + <p className="description">๋น„๊ณต๊ฐœ๋กœ ์„ค์ •์‹œ, ๋‹จ์ฒด ์™ธ๋ถ€์ธ์—๊ฒŒ๋Š” ๋ฆฌ๋ทฐ๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</p> + )} + </div> + <Button onClick={handleOnSubmit} fullWidth> + ์ž‘์„ฑ ์™„๋ฃŒ + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantsReviewForm; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 30px; + + textarea { + font-size: 16px; + } + + button { + font-size: 16px; + } + + .right-alignment { + margin-top: -15px; + width: 100%; + } + + .label { + margin-top: 20px; + margin-bottom: 10px; + margin-left: 2px; + font-weight: 500; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + .description { + margin-top: 5px; + margin-left: 2px; + font-size: 14px; + font-weight: 200; + color: ${({ theme }) => theme.color.gray600}; + } +`;
Unknown
์š” ๊ฐ’์„ `src/constant/limit.ts` ์—์„œ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์š”~? ํ•˜๋‚˜์˜ ํŒŒ์ผ์—์„œ ๊ฐ ์ตœ๋Œ€๊ธธ์ด๋‚˜ ์ตœ์†Œ๊ธธ์ด ์กฐ๊ฑด ๋“ฑ์„ ๊ด€๋ฆฌํ•ด์ฃผ๋ฉด ๋‚˜์ค‘์— ์ด๋ฅผ ์ฆ๊ฐ€ ๋˜๋Š” ๊ฐ์†Œ์‹œํ‚ฌ ์ผ์ด ์žˆ์„ ๋•Œ ๋Œ€์‘ํ•˜๊ธฐ ์šฉ์ดํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,18 @@ +import styled from "@emotion/styled"; +import RestaurantsReviewForm from "feature/restaurants/restaurantsReview/components/form/RestaurantsReviewForm"; + +interface Props { + restaurantId: string; +} + +const ViewRestaurantReviewCreate: React.FC<Props> = ({ restaurantId }) => { + return ( + <EmotionWrapper> + <RestaurantsReviewForm restaurantId={restaurantId} isEditMode={false} /> + </EmotionWrapper> + ); +}; + +export default ViewRestaurantReviewCreate; + +const EmotionWrapper = styled.div``;
Unknown
์—ฌ๊ธฐ์„œ๋„ `string []` ์„ ํŠน๋ณ„ํžˆ ์ถ”๊ฐ€ํ•ด์ฃผ์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”~?
@@ -0,0 +1,170 @@ +import styled from "@emotion/styled"; +import IconStarFilled from "components/rating/icons/IconStarFilled"; +import IconStarHalf from "components/rating/icons/IconStarHalf"; +import IconStarOutlined from "components/rating/icons/IconStarOutlined"; +import { HTMLAttributes, useEffect, useState, useRef, useCallback } from "react"; + +interface Props extends HTMLAttributes<HTMLDivElement> { + value: number; // 0 ~ 5 ์‚ฌ์ด์˜ ์ˆซ์ž, ๋ณ„ ๊ฐœ์ˆ˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด 0.5 ๋‹จ์œ„๋กœ ๋ฐ˜์˜ฌ๋ฆผ + isInput?: boolean; // input ๊ธฐ๋Šฅ์„ ํ•˜๋„๋ก ํ•  ์ง€ ์„ค์ • + onSelectedValueChange?: (value: number) => void; +} + +const Rating = ({ value, isInput = false, onSelectedValueChange, ...props }: Props) => { + const [selectedValue, setSelectedValue] = useState<number>(value); + const isMouseDown = useRef<boolean>(false); + const containerRef = useRef<HTMLDivElement>(null); + + // round value to the nearest 0.5 + const startCount = Math.round(selectedValue * 2) / 2; + + const filledStarCount = Math.floor(startCount); + const hasHalfStar = startCount % 1 !== 0; + const emptyStarCount = 5 - filledStarCount - (hasHalfStar ? 1 : 0); + + useEffect(() => { + if (onSelectedValueChange) { + onSelectedValueChange(selectedValue); + } + }, [selectedValue, onSelectedValueChange]); + + const handleOnClick = (event: React.MouseEvent, index: number) => { + const clickX = event.nativeEvent.clientX; // ํด๋ฆญํ•œ ์œ„์น˜์˜ X ์ขŒํ‘œ + + // IconStar... ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ํด๋ฆญํ•œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํŒ๋ณ„ + const containerRect = event.currentTarget.getBoundingClientRect(); + const containerCenterX = (containerRect.left + containerRect.right) / 2; + + if (clickX < containerCenterX) { + setSelectedValue(index + 0.5); + } else { + setSelectedValue(index + 1); + } + }; + + const calculateScore = useCallback((currentX: number) => { + const container = containerRef.current; + if (container) { + const unitSize = container.getBoundingClientRect().width / 10; + const relativeX = currentX - container.getBoundingClientRect().x; + if (relativeX <= 0) setSelectedValue(0.5); + else { + const score = (Math.floor(relativeX / unitSize) + 1) * 0.5; + score > 5 ? setSelectedValue(5) : setSelectedValue(score); + } + } + }, []); + + const handleOnMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = true; + }, []); + + const handleOnMouseLeave = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = false; + }, []); + + const handleOnMouseMove = useCallback( + (event: React.MouseEvent) => { + if (isMouseDown.current) calculateScore(event.clientX); + }, + [calculateScore] + ); + + const handleOnMouseUp = useCallback((event: React.MouseEvent) => { + isMouseDown.current = false; + }, []); + + // For mobile view + const handleOnTouchMove = useCallback( + (event: React.TouchEvent) => { + calculateScore(event.changedTouches[0].clientX); + }, + [calculateScore] + ); + + return ( + <EmotionWrapper isInput={isInput} {...props}> + <div + className="star-container" + onMouseDown={handleOnMouseDown} + onMouseUp={handleOnMouseUp} + onMouseMove={handleOnMouseMove} + onMouseLeave={handleOnMouseLeave} + onTouchMove={handleOnTouchMove} + ref={containerRef} + > + {Array.from({ length: filledStarCount }, (_, index) => + isInput ? ( + <IconStarFilled + key={index} + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, index)} + /> + ) : ( + <IconStarFilled key={index} /> + ) + )} + {hasHalfStar && + (isInput ? ( + <IconStarHalf + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, filledStarCount)} + /> + ) : ( + <IconStarHalf /> + ))} + {Array.from({ length: emptyStarCount }, (_, index) => + isInput ? ( + <IconStarOutlined + key={index} + size={40} + onClick={(event: React.MouseEvent) => + handleOnClick(event, filledStarCount + index + (hasHalfStar ? 1 : 0)) + } + /> + ) : ( + <IconStarOutlined key={index} /> + ) + )} + </div> + {isInput ? ( + <div> + <span className="rating-value-selected">{selectedValue}</span> + <span className="rating-full-marks"> / 5</span> + </div> + ) : ( + <p className="rating-value">{value}</p> + )} + </EmotionWrapper> + ); +}; + +export default Rating; + +const EmotionWrapper = styled.div<{ isInput: boolean }>` + display: flex; + align-items: center; + ${({ isInput }) => (isInput ? "flex-direction: column; gap: 20px;" : "column-gap: 4px;")} + + .star-container { + display: flex; + column-gap: 2px; + } + + color: ${({ theme }) => theme.color.gray400}; + + .rating-full-marks { + font-size: 16px; + font-weight: 300; + } + + .rating-value-selected { + font-size: 32px; + font-weight: 500; + color: ${({ theme }) => theme.color.gray700}; + } + + .rating-value { + font-size: 12px; + } +`;
Unknown
๋„ต ๋งž์Šต๋‹ˆ๋‹ค..!
@@ -0,0 +1,85 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Button from "components/button/Button"; + +interface Props { + imgSrcList: string[]; +} + +const RestaurantDetailImgSection: React.FC<Props> = ({ imgSrcList }) => { + const [currentImgIndex, setCurrentImgIndex] = useState(0); + + const handleOnClickRight = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == imgSrcList.length - 1 ? 0 : currentImgIndex + 1 + ); + }; + + const handleOnClickLeft = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == 0 ? imgSrcList.length - 1 : currentImgIndex - 1 + ); + }; + + return ( + <EmotionWrapper> + {imgSrcList.length === 0 ? ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ๊ธฐ๋ณธ ์ด๋ฏธ์ง€" + src={"/images/defaults/default-restaurant-image.png"} + fill + /> + ) : ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ์ด๋ฏธ์ง€" + src={imgSrcList[currentImgIndex]} + fill + /> + )} + <Button + onClick={handleOnClickLeft} + variant="text" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + left: "0px", + }} + > + &lt; + </Button> + <Button + onClick={handleOnClickRight} + variant="text" + className="right-button" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + right: "0px", + }} + > + &gt; + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailImgSection; + +const EmotionWrapper = styled.div` + position: relative; + width: 100%; + height: 120px; + overflow: hidden; + margin-bottom: 10px; + + .restaurant-img { + z-index: 1; + object-fit: cover; + position: absolute; + } +`;
Unknown
์•— ์ด๋ฏธ์ง€ ์Šฌ๋ผ์ด๋”๋ฅผ ๊ตฌํ˜„ํ•˜๋ ค๋‹ค๊ฐ€ ์ผ๋‹จ PR๋ถ€ํ„ฐ ์˜ฌ๋ ธ๋Š”๋ฐ, ํ•ด๋‹น ๋ฒ„ํŠผ์€ ๊ทธ ๊ณผ์ •์—์„œ ์ƒ๊ธด ๋ณ„ ์˜๋ฏธ ์—†๋Š” ๋ฒ„ํŠผ์ž…๋‹ˆ๋‹ค.. ์‚ญ์ œํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,70 @@ +import styled from "@emotion/styled"; +import RestaurantDetailImgSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailImgSection"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import RestaurantDetailInfoSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailInfoSection"; +import RestaurantDetailReviewSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailReviewSection"; +import Divider from "components/divider/Divider"; +import { restaurant } from "feature/restaurants/restaurantsDetail/mockups/restaurant"; +import { reviewPage1 } from "feature/restaurants/restaurantsDetail/mockups/reviews"; + +interface Props { + restaurantId: string; +} + +const ViewRestaurantDetail: React.FC<Props> = ({ restaurantId }) => { + /** + * TODO 1: ์‚ฌ์šฉ์ž ๊ถŒํ•œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userAuth = 0; + + /** + * TODO 2: ๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + /** + * TODO3: ๋ง›์ง‘์˜ ๋ชจ๋“  ๋ฆฌ๋ทฐ ์กฐํšŒํ•˜๊ธฐ + * - totalScore, totalPages ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ Read Reviews API ํ˜ธ์ถœ + * - ๋ฆฌ๋ทฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ 404 ์—๋Ÿฌ ๋ฐ˜ํ™˜? + */ + const { totalScore, totalCount, totalPages, scoreStatistics } = reviewPage1; + + return ( + <EmotionWrapper> + <RestaurantDetailImgSection imgSrcList={restaurant.imgSrcList} /> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + userAuth={userAuth} + restaurantName={restaurant.name} + restaurantAddress={restaurant.address} + organizationName={restaurant.organizationName} + link={restaurant.link} + /> + <RestaurantDetailInfoSection + restaurantId={restaurantId} + comment={restaurant.comment} + orderTip={restaurant.orderTip} + capacity={restaurant.capacity} + recommendedMenus={restaurant.recommnededMenus} + category={restaurant.category} + delivery={restaurant.delivery} + openingHour={restaurant.openingHour} + tags={restaurant.tags} + totalScore={totalScore} + totalCount={totalCount} + /> + <Divider /> + <RestaurantDetailReviewSection + restaurantId={restaurantId} + userAuth={userAuth} + totalScore={totalScore} + totalCount={totalCount} + totalPages={totalPages} + scoreStatistics={scoreStatistics} + /> + </EmotionWrapper> + ); +}; + +export default ViewRestaurantDetail; + +const EmotionWrapper = styled.div``;
Unknown
ํ™•์ธ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,137 @@ +import styled from "@emotion/styled"; +import Rating from "components/rating/Rating"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import Button from "components/button/Button"; +import TextInput from "components/inputs/TextInput/TextInput"; +import { useState, useCallback } from "react"; +import Checkbox from "components/checkbox/Checkbox"; +import { REVIEW_CONTENT_MAX_VALUE, REVIEW_CONTENT_MIN_VALUE } from "constant/limit"; + +interface Props { + restaurantId: string; + isEditMode: boolean; + reviewId?: string | number | string[]; + score?: number; + content?: string; +} + +const RestaurantsReviewForm: React.FC<Props> = ({ restaurantId, score = 0, content = "" }) => { + const [selectedScroe, setSelectedScore] = useState<number>(score); + const [enteredContent, setEnteredContent] = useState<string>(content); + const [isPublic, setIsPublic] = useState<boolean>(true); + + /** + * TODO: restaurantId๋กœ ๋ง›์ง‘ ์ƒ์„ธ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + const contentMaxLengthCheck = { + condition: (content: string) => { + return content.length <= REVIEW_CONTENT_MAX_VALUE; + }, + messageOnError: "500์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const contentMinLengthCheck = { + condition: (content: string) => { + return content.length >= REVIEW_CONTENT_MIN_VALUE; + }, + messageOnError: "20์ž ์ด์ƒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const handleScoreChange = useCallback((value: number) => { + setSelectedScore(value); + }, []); + + const handleContentChange = useCallback((value: string) => { + setEnteredContent(value); + }, []); + + const handleSetIsPublic = useCallback((value: string) => { + if (value === "true") setIsPublic(true); + else setIsPublic(false); + }, []); + + const handleOnSubmit = () => { + console.log("์ ์ˆ˜ : ", selectedScroe); + console.log("๋ฆฌ๋ทฐ ๋‚ด์šฉ : ", enteredContent); + console.log("๊ณต๊ฐœ ์—ฌ๋ถ€ : ", isPublic); + }; + + return ( + <EmotionWrapper> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + restaurantName="๋ด‰์ˆ˜์œก" + restaurantAddress="๊ฒฝ๊ธฐ๋„ ์ˆ˜์›์‹œ ์ฒœ์ฒœ๋™" + organizationName="์‹œ์Šคํ…œ ์ปจ์„คํ„ดํŠธ ๊ทธ๋ฃน" + isMain={false} + /> + <Rating value={score} isInput onSelectedValueChange={handleScoreChange} /> + <TextInput + label="๋ฆฌ๋ทฐ ๋‚ด์šฉ" + placeholder="๋ง›์ง‘์— ๋Œ€ํ•œ ์†”์งํ•œ ํ‰์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!" + multiline + value={content} + onTextChange={handleContentChange} + conditionCheckList={[contentMaxLengthCheck, contentMinLengthCheck]} + height="150px" + /> + <div className="right-alignment"> + <p className="label">๋ฆฌ๋ทฐ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.</p> + <Checkbox.Group + checkedList={[String(isPublic)]} + setCheckedItem={(value) => handleSetIsPublic(value)} + > + <Checkbox.Item value="true">๊ณต๊ฐœ</Checkbox.Item> + <Checkbox.Item value="false">๋น„๊ณต๊ฐœ</Checkbox.Item> + </Checkbox.Group> + {!isPublic && ( + <p className="description">๋น„๊ณต๊ฐœ๋กœ ์„ค์ •์‹œ, ๋‹จ์ฒด ์™ธ๋ถ€์ธ์—๊ฒŒ๋Š” ๋ฆฌ๋ทฐ๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</p> + )} + </div> + <Button onClick={handleOnSubmit} fullWidth> + ์ž‘์„ฑ ์™„๋ฃŒ + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantsReviewForm; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 30px; + + textarea { + font-size: 16px; + } + + button { + font-size: 16px; + } + + .right-alignment { + margin-top: -15px; + width: 100%; + } + + .label { + margin-top: 20px; + margin-bottom: 10px; + margin-left: 2px; + font-weight: 500; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + .description { + margin-top: 5px; + margin-left: 2px; + font-size: 14px; + font-weight: 200; + color: ${({ theme }) => theme.color.gray600}; + } +`;
Unknown
๋ฐœ๊ฒฌ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,137 @@ +import styled from "@emotion/styled"; +import Rating from "components/rating/Rating"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import Button from "components/button/Button"; +import TextInput from "components/inputs/TextInput/TextInput"; +import { useState, useCallback } from "react"; +import Checkbox from "components/checkbox/Checkbox"; +import { REVIEW_CONTENT_MAX_VALUE, REVIEW_CONTENT_MIN_VALUE } from "constant/limit"; + +interface Props { + restaurantId: string; + isEditMode: boolean; + reviewId?: string | number | string[]; + score?: number; + content?: string; +} + +const RestaurantsReviewForm: React.FC<Props> = ({ restaurantId, score = 0, content = "" }) => { + const [selectedScroe, setSelectedScore] = useState<number>(score); + const [enteredContent, setEnteredContent] = useState<string>(content); + const [isPublic, setIsPublic] = useState<boolean>(true); + + /** + * TODO: restaurantId๋กœ ๋ง›์ง‘ ์ƒ์„ธ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + const contentMaxLengthCheck = { + condition: (content: string) => { + return content.length <= REVIEW_CONTENT_MAX_VALUE; + }, + messageOnError: "500์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const contentMinLengthCheck = { + condition: (content: string) => { + return content.length >= REVIEW_CONTENT_MIN_VALUE; + }, + messageOnError: "20์ž ์ด์ƒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const handleScoreChange = useCallback((value: number) => { + setSelectedScore(value); + }, []); + + const handleContentChange = useCallback((value: string) => { + setEnteredContent(value); + }, []); + + const handleSetIsPublic = useCallback((value: string) => { + if (value === "true") setIsPublic(true); + else setIsPublic(false); + }, []); + + const handleOnSubmit = () => { + console.log("์ ์ˆ˜ : ", selectedScroe); + console.log("๋ฆฌ๋ทฐ ๋‚ด์šฉ : ", enteredContent); + console.log("๊ณต๊ฐœ ์—ฌ๋ถ€ : ", isPublic); + }; + + return ( + <EmotionWrapper> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + restaurantName="๋ด‰์ˆ˜์œก" + restaurantAddress="๊ฒฝ๊ธฐ๋„ ์ˆ˜์›์‹œ ์ฒœ์ฒœ๋™" + organizationName="์‹œ์Šคํ…œ ์ปจ์„คํ„ดํŠธ ๊ทธ๋ฃน" + isMain={false} + /> + <Rating value={score} isInput onSelectedValueChange={handleScoreChange} /> + <TextInput + label="๋ฆฌ๋ทฐ ๋‚ด์šฉ" + placeholder="๋ง›์ง‘์— ๋Œ€ํ•œ ์†”์งํ•œ ํ‰์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!" + multiline + value={content} + onTextChange={handleContentChange} + conditionCheckList={[contentMaxLengthCheck, contentMinLengthCheck]} + height="150px" + /> + <div className="right-alignment"> + <p className="label">๋ฆฌ๋ทฐ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.</p> + <Checkbox.Group + checkedList={[String(isPublic)]} + setCheckedItem={(value) => handleSetIsPublic(value)} + > + <Checkbox.Item value="true">๊ณต๊ฐœ</Checkbox.Item> + <Checkbox.Item value="false">๋น„๊ณต๊ฐœ</Checkbox.Item> + </Checkbox.Group> + {!isPublic && ( + <p className="description">๋น„๊ณต๊ฐœ๋กœ ์„ค์ •์‹œ, ๋‹จ์ฒด ์™ธ๋ถ€์ธ์—๊ฒŒ๋Š” ๋ฆฌ๋ทฐ๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</p> + )} + </div> + <Button onClick={handleOnSubmit} fullWidth> + ์ž‘์„ฑ ์™„๋ฃŒ + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantsReviewForm; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 30px; + + textarea { + font-size: 16px; + } + + button { + font-size: 16px; + } + + .right-alignment { + margin-top: -15px; + width: 100%; + } + + .label { + margin-top: 20px; + margin-bottom: 10px; + margin-left: 2px; + font-weight: 500; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + .description { + margin-top: 5px; + margin-left: 2px; + font-size: 14px; + font-weight: 200; + color: ${({ theme }) => theme.color.gray600}; + } +`;
Unknown
๋„ต ์ข‹์Šต๋‹ˆ๋‹ค! ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,85 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Button from "components/button/Button"; + +interface Props { + imgSrcList: string[]; +} + +const RestaurantDetailImgSection: React.FC<Props> = ({ imgSrcList }) => { + const [currentImgIndex, setCurrentImgIndex] = useState(0); + + const handleOnClickRight = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == imgSrcList.length - 1 ? 0 : currentImgIndex + 1 + ); + }; + + const handleOnClickLeft = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == 0 ? imgSrcList.length - 1 : currentImgIndex - 1 + ); + }; + + return ( + <EmotionWrapper> + {imgSrcList.length === 0 ? ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ๊ธฐ๋ณธ ์ด๋ฏธ์ง€" + src={"/images/defaults/default-restaurant-image.png"} + fill + /> + ) : ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ์ด๋ฏธ์ง€" + src={imgSrcList[currentImgIndex]} + fill + /> + )} + <Button + onClick={handleOnClickLeft} + variant="text" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + left: "0px", + }} + > + &lt; + </Button> + <Button + onClick={handleOnClickRight} + variant="text" + className="right-button" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + right: "0px", + }} + > + &gt; + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailImgSection; + +const EmotionWrapper = styled.div` + position: relative; + width: 100%; + height: 120px; + overflow: hidden; + margin-bottom: 10px; + + .restaurant-img { + z-index: 1; + object-fit: cover; + position: absolute; + } +`;
Unknown
์ด๋ฏธ์ง€ ์Šฌ๋ผ์ด๋”๋Š” ์•„์ง ๊ตฌํ˜„ํ•˜์ง€ ์•Š์•˜์ง€๋งŒ, ์ผ๋‹จ ์ด๋ฏธ์ง€ ์ „ํ™˜์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๋ฒ„ํŠผ์€ ๋งŒ๋“ค์–ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค! ์ง€๊ธˆ์€ ๋ฒ„ํŠผ ๋ณด์ผ ๊ฒ๋‹ˆ๋‹ค.
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
์˜ค.. ๋„ต ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋„ ๋ฉ”์ธ์ด ๋˜๋Š” ํ…์ŠคํŠธ(๋ง›์ง‘ ์ด๋ฆ„, ๋‹จ์ฒด ์ด๋ฆ„)์€ `<h1 />`์„ ์‚ฌ์šฉํ•˜๋„๋ก ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ผ๋‹จ ๋ง›์ง‘ ์ƒ์„ธ ํŽ˜์ด์ง€์—์„œ๋Š” ๋ง›์ง‘ ์ด๋ฆ„์„ `<h1 />` ํƒœ๊ทธ๋กœ ์ˆ˜์ • ์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
className์„ ๋ชจ๋‘ kebab case๋กœ ์ˆ˜์ •์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,120 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Rating from "components/rating/Rating"; +import IconEditFilledWhite from "components/icons/IconEditFilledWhite"; +import Link from "next/link"; +import dayjs from "dayjs"; + +interface Props { + restaurantId: string; + reviewId: number; + userId: number; + score: number; + content: string; + createdAt: Date; +} + +const ReviewItem: React.FC<Props> = ({ + restaurantId, + reviewId, + userId, + score, + content, + createdAt, +}) => { + const [isExpanded, setIsExpanded] = useState(false); + + const toggleExpansion = () => { + setIsExpanded((isExpanded) => !isExpanded); + }; + + const editLink = `/restaurants/${restaurantId}/review/${reviewId}/edit`; + const displayContent = + content.length > 100 && !isExpanded ? content.slice(0, 100) + "..." : content; + + /** + * TODO 1: userId๋กœ userInfo ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userName = "ํ™๊ธธ๋™"; + const ImgSrc = "/images/profile-image-default-1.png"; + + /** + * TODO 2: ํ˜„์žฌ ๋กœ๊ทธ์ธ๋œ ์œ ์ € ์•„์ด๋”” ๊ฐ€์ ธ์˜ค๊ธฐ (๋ฆฌ๋ทฐ ์ˆ˜์ • ๊ถŒํ•œ ํ™•์ธ์šฉ) + */ + const currentUserId = 1; + + return ( + <EmotionWrapper> + <div className="user-info-score-div"> + <div className="user-info-div"> + <Image src={ImgSrc} alt={"์œ ์ € ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"} width={30} height={30} /> + <span className="user-name">{userName}</span> + <span className="date">{dayjs(createdAt).format("YY/MM/DD")}</span> + {currentUserId === userId && ( + <Link href={editLink}> + <IconEditFilledWhite /> + </Link> + )} + </div> + <Rating value={score} /> + </div> + <div className="content-div"> + <span>{displayContent}</span> + {content.length > 100 && ( + <button onClick={toggleExpansion}>{isExpanded ? "์ ‘๊ธฐ" : "๋” ๋ณด๊ธฐ"}</button> + )} + </div> + </EmotionWrapper> + ); +}; + +export default ReviewItem; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + min-height: 90px; + width: 100%; + background-color: ${({ theme }) => theme.color.white}; + border-radius: 6px; + + padding: 10px; + + .user-info-score-div { + display: flex; + justify-content: space-between; + align-items: center; + + .user-info-div { + display: flex; + gap: 8px; + justify-content: center; + align-items: center; + + span.user-name { + font-size: 16px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + span.date { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray300}; + } + } + } + + .content-div { + span { + line-height: 1.5; + color: ${({ theme }) => theme.color.gray400}; + flex-grow: 1; + margin-right: 8px; + } + + button { + color: ${({ theme }) => theme.color.gray300}; + } + } +`;
Unknown
className์„ ๋ชจ๋‘ kebab case๋กœ ์ˆ˜์ •์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,120 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Rating from "components/rating/Rating"; +import IconEditFilledWhite from "components/icons/IconEditFilledWhite"; +import Link from "next/link"; +import dayjs from "dayjs"; + +interface Props { + restaurantId: string; + reviewId: number; + userId: number; + score: number; + content: string; + createdAt: Date; +} + +const ReviewItem: React.FC<Props> = ({ + restaurantId, + reviewId, + userId, + score, + content, + createdAt, +}) => { + const [isExpanded, setIsExpanded] = useState(false); + + const toggleExpansion = () => { + setIsExpanded((isExpanded) => !isExpanded); + }; + + const editLink = `/restaurants/${restaurantId}/review/${reviewId}/edit`; + const displayContent = + content.length > 100 && !isExpanded ? content.slice(0, 100) + "..." : content; + + /** + * TODO 1: userId๋กœ userInfo ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userName = "ํ™๊ธธ๋™"; + const ImgSrc = "/images/profile-image-default-1.png"; + + /** + * TODO 2: ํ˜„์žฌ ๋กœ๊ทธ์ธ๋œ ์œ ์ € ์•„์ด๋”” ๊ฐ€์ ธ์˜ค๊ธฐ (๋ฆฌ๋ทฐ ์ˆ˜์ • ๊ถŒํ•œ ํ™•์ธ์šฉ) + */ + const currentUserId = 1; + + return ( + <EmotionWrapper> + <div className="user-info-score-div"> + <div className="user-info-div"> + <Image src={ImgSrc} alt={"์œ ์ € ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"} width={30} height={30} /> + <span className="user-name">{userName}</span> + <span className="date">{dayjs(createdAt).format("YY/MM/DD")}</span> + {currentUserId === userId && ( + <Link href={editLink}> + <IconEditFilledWhite /> + </Link> + )} + </div> + <Rating value={score} /> + </div> + <div className="content-div"> + <span>{displayContent}</span> + {content.length > 100 && ( + <button onClick={toggleExpansion}>{isExpanded ? "์ ‘๊ธฐ" : "๋” ๋ณด๊ธฐ"}</button> + )} + </div> + </EmotionWrapper> + ); +}; + +export default ReviewItem; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + min-height: 90px; + width: 100%; + background-color: ${({ theme }) => theme.color.white}; + border-radius: 6px; + + padding: 10px; + + .user-info-score-div { + display: flex; + justify-content: space-between; + align-items: center; + + .user-info-div { + display: flex; + gap: 8px; + justify-content: center; + align-items: center; + + span.user-name { + font-size: 16px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + span.date { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray300}; + } + } + } + + .content-div { + span { + line-height: 1.5; + color: ${({ theme }) => theme.color.gray400}; + flex-grow: 1; + margin-right: 8px; + } + + button { + color: ${({ theme }) => theme.color.gray300}; + } + } +`;
Unknown
์˜ค ๋„ต ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ๋ฐฉ์‹์œผ๋กœ ์ˆ˜์ • ์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react"; import styled from "@emotion/styled"; import { css, Theme } from "@emotion/react"; import CheckIcon from "components/inputs/TextInput/CheckIcon"; -import { TConditionCheck } from "./types/TConditionCheck"; +import { TConditionCheck } from "components/inputs/TextInput/types/TConditionCheck"; interface Props { name?: string; @@ -12,6 +12,7 @@ interface Props { conditionList?: string[]; conditionCheckList?: TConditionCheck[]; multiline?: boolean; + height?: string; onTextChange?: (value: string, isValid: boolean) => void; } @@ -23,6 +24,7 @@ const TextInput: React.FC<Props> = ({ conditionList, conditionCheckList, multiline = false, + height, onTextChange, }) => { const [status, setStatus] = useState(value === "" ? "default" : "success"); // default / success / invalid / focus @@ -76,7 +78,7 @@ const TextInput: React.FC<Props> = ({ }, [enteredValue, status, onTextChange]); return ( - <EmotionWrapper> + <EmotionWrapper height={height}> {label && <span className="label">{label}</span>} {conditionList && ( <div className="spanList"> @@ -179,6 +181,7 @@ const EmotionWrapper = styled.div<Props>` ${({ theme }) => commonStyles(theme)}; position: relative; resize: none; + height: ${({ height }) => height ?? "auto"}; } `;
Unknown
๋„ต ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
restaurantId๋ฅผ ๋ฐ›์•„์˜ฌ ๋•Œ `const restaurantId = query.restaurantId ?? 0;` ์ด๋ ‡๊ฒŒ๋งŒ ํ–ˆ๋”๋‹ˆ props๋กœ ๋„˜๊ฒจ์ค„ ๋•Œ ํƒ€์ž… ์—๋Ÿฌ๊ฐ€ ๋– ์„œ ์ €๋ ‡๊ฒŒ ์„ค์ •ํ•œ๊ฑด๋ฐ, ํ˜„์žฌ๋Š” `const restaurantId = (query.restaurantId ?? 0) as string;` ์•„์˜ˆ ์ด๋Ÿฐ ์‹์œผ๋กœ ํƒ€์ž…์„ ๋ช…์‹œํ•ด์ฃผ์–ด์„œ props๋กœ ๋ฐ›์•„์˜ฌ ๋•Œ์—๋„ string์œผ๋กœ๋งŒ ๋ฐ›์•„์˜ค๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,18 @@ +import styled from "@emotion/styled"; +import RestaurantsReviewForm from "feature/restaurants/restaurantsReview/components/form/RestaurantsReviewForm"; + +interface Props { + restaurantId: string; +} + +const ViewRestaurantReviewCreate: React.FC<Props> = ({ restaurantId }) => { + return ( + <EmotionWrapper> + <RestaurantsReviewForm restaurantId={restaurantId} isEditMode={false} /> + </EmotionWrapper> + ); +}; + +export default ViewRestaurantReviewCreate; + +const EmotionWrapper = styled.div``;
Unknown
[์—ฌ๊ธฐ](https://github.com/SystemConsultantGroup/foodhub-frontend/pull/27#discussion_r1373127345)์—์„œ ์ด์œ ๋ฅผ ์„ค๋ช…ํ•˜์˜€๊ณ , ํ•ด๋‹น ๋ถ€๋ถ„ string์œผ๋กœ๋งŒ ๋ฐ›์•„์˜ค๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,170 @@ +import styled from "@emotion/styled"; +import IconStarFilled from "components/rating/icons/IconStarFilled"; +import IconStarHalf from "components/rating/icons/IconStarHalf"; +import IconStarOutlined from "components/rating/icons/IconStarOutlined"; +import { HTMLAttributes, useEffect, useState, useRef, useCallback } from "react"; + +interface Props extends HTMLAttributes<HTMLDivElement> { + value: number; // 0 ~ 5 ์‚ฌ์ด์˜ ์ˆซ์ž, ๋ณ„ ๊ฐœ์ˆ˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด 0.5 ๋‹จ์œ„๋กœ ๋ฐ˜์˜ฌ๋ฆผ + isInput?: boolean; // input ๊ธฐ๋Šฅ์„ ํ•˜๋„๋ก ํ•  ์ง€ ์„ค์ • + onSelectedValueChange?: (value: number) => void; +} + +const Rating = ({ value, isInput = false, onSelectedValueChange, ...props }: Props) => { + const [selectedValue, setSelectedValue] = useState<number>(value); + const isMouseDown = useRef<boolean>(false); + const containerRef = useRef<HTMLDivElement>(null); + + // round value to the nearest 0.5 + const startCount = Math.round(selectedValue * 2) / 2; + + const filledStarCount = Math.floor(startCount); + const hasHalfStar = startCount % 1 !== 0; + const emptyStarCount = 5 - filledStarCount - (hasHalfStar ? 1 : 0); + + useEffect(() => { + if (onSelectedValueChange) { + onSelectedValueChange(selectedValue); + } + }, [selectedValue, onSelectedValueChange]); + + const handleOnClick = (event: React.MouseEvent, index: number) => { + const clickX = event.nativeEvent.clientX; // ํด๋ฆญํ•œ ์œ„์น˜์˜ X ์ขŒํ‘œ + + // IconStar... ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ํด๋ฆญํ•œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํŒ๋ณ„ + const containerRect = event.currentTarget.getBoundingClientRect(); + const containerCenterX = (containerRect.left + containerRect.right) / 2; + + if (clickX < containerCenterX) { + setSelectedValue(index + 0.5); + } else { + setSelectedValue(index + 1); + } + }; + + const calculateScore = useCallback((currentX: number) => { + const container = containerRef.current; + if (container) { + const unitSize = container.getBoundingClientRect().width / 10; + const relativeX = currentX - container.getBoundingClientRect().x; + if (relativeX <= 0) setSelectedValue(0.5); + else { + const score = (Math.floor(relativeX / unitSize) + 1) * 0.5; + score > 5 ? setSelectedValue(5) : setSelectedValue(score); + } + } + }, []); + + const handleOnMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = true; + }, []); + + const handleOnMouseLeave = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = false; + }, []); + + const handleOnMouseMove = useCallback( + (event: React.MouseEvent) => { + if (isMouseDown.current) calculateScore(event.clientX); + }, + [calculateScore] + ); + + const handleOnMouseUp = useCallback((event: React.MouseEvent) => { + isMouseDown.current = false; + }, []); + + // For mobile view + const handleOnTouchMove = useCallback( + (event: React.TouchEvent) => { + calculateScore(event.changedTouches[0].clientX); + }, + [calculateScore] + ); + + return ( + <EmotionWrapper isInput={isInput} {...props}> + <div + className="star-container" + onMouseDown={handleOnMouseDown} + onMouseUp={handleOnMouseUp} + onMouseMove={handleOnMouseMove} + onMouseLeave={handleOnMouseLeave} + onTouchMove={handleOnTouchMove} + ref={containerRef} + > + {Array.from({ length: filledStarCount }, (_, index) => + isInput ? ( + <IconStarFilled + key={index} + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, index)} + /> + ) : ( + <IconStarFilled key={index} /> + ) + )} + {hasHalfStar && + (isInput ? ( + <IconStarHalf + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, filledStarCount)} + /> + ) : ( + <IconStarHalf /> + ))} + {Array.from({ length: emptyStarCount }, (_, index) => + isInput ? ( + <IconStarOutlined + key={index} + size={40} + onClick={(event: React.MouseEvent) => + handleOnClick(event, filledStarCount + index + (hasHalfStar ? 1 : 0)) + } + /> + ) : ( + <IconStarOutlined key={index} /> + ) + )} + </div> + {isInput ? ( + <div> + <span className="rating-value-selected">{selectedValue}</span> + <span className="rating-full-marks"> / 5</span> + </div> + ) : ( + <p className="rating-value">{value}</p> + )} + </EmotionWrapper> + ); +}; + +export default Rating; + +const EmotionWrapper = styled.div<{ isInput: boolean }>` + display: flex; + align-items: center; + ${({ isInput }) => (isInput ? "flex-direction: column; gap: 20px;" : "column-gap: 4px;")} + + .star-container { + display: flex; + column-gap: 2px; + } + + color: ${({ theme }) => theme.color.gray400}; + + .rating-full-marks { + font-size: 16px; + font-weight: 300; + } + + .rating-value-selected { + font-size: 32px; + font-weight: 500; + color: ${({ theme }) => theme.color.gray700}; + } + + .rating-value { + font-size: 12px; + } +`;
Unknown
๋ณ„์ ์„ dragํ•˜์—ฌ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋„๋ก ์ถ”๊ฐ€์ ์œผ๋กœ ๊ตฌํ˜„ํ•˜์˜€๋Š”๋ฐ, ๋ฐ์Šคํฌํ†ฑ์—์„œ๋Š” ์ž˜ ๋˜๋Š”๋ฐ ๋ชจ๋ฐ”์ผ์—์„œ๋Š” touchMove ์ด๋ฒคํŠธ๊ฐ€ ์ค‘๊ฐ„์— ๋Š๊ธฐ๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ •ํ™•ํžˆ๋Š” touchMove ๋„์ค‘์— state๋ฅผ ์„ธํŒ…ํ•˜๋ฉด, ํ„ฐ์น˜๋Š” ์ด์–ด์ง€๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์ธ๋ฐ๋„ touchMove๊ฐ€ ์ธ์‹๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. selectedValue๊ฐ€ ๋ฐ”๋€Œ๋ฉด์„œ star๋“ค์ด ๋‹ค์‹œ ๋ Œ๋”๋ง๋˜๋Š” ๊ฒƒ ๋•Œ๋ฌธ์ธ ๊ฒƒ ๊ฐ™์ง€๋งŒ ์ •ํ™•ํžˆ ๋ญ ๋•Œ๋ฌธ์ธ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์„ ์ฐพ๋Š” ์ค‘์ด๊ธด ํ•œ๋ฐ, ํ•˜๋‹ค๊ฐ€ ์•ˆ๋˜๋ฉด ์ด์Šˆ๋กœ ์˜ฌ๋ฆฌ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.. @jaychang99 @hoon5083
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
๋ฆฌ์•กํŠธ ๊ด€๋ จ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ import๊ฐ€ ๋” ์šฐ์„ ์ˆœ์œ„์— ์œ„์น˜ํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
import './Login.scss'; ์œ„๋กœ ๊ฐ€์•ผ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!! ๐Ÿ˜Ž
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
์ˆ˜์ •์™„๋ฃŒ ๐Ÿ˜Š
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
- variable.scss ๋Š” scss ํŒŒ์ผ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— js ์—์„œ import ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด ์˜๋ฏธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. - scss ํŒŒ์ผ์—์„œ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ์— import ํ•ด์ฃผ์„ธ์š”!
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
- ๋‘ ํ•จ์ˆ˜๋Š” ํ•˜๋Š” ์—ญํ• ์ด ๋น„์Šทํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ถฉ๋ถ„ํžˆ ํ•˜๋‚˜์˜ ํ•จ์ˆ˜๋กœ ํ•ฉ์ณ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. - Refactoring CheckList ์ฐธ๊ณ ํ•ด์„œ ์ˆ˜์ •ํ•ด ๋ณด์„ธ์š”!
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
- isActive ๋Š” id ์™€ pw ๋กœ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’์ด์ด๊ธฐ ๋•Œ๋ฌธ์— state ๋กœ ๊ด€๋ฆฌํ•  ํ•„์š”๊ฐ€ ์—†์–ด ๋ณด์ž…๋‹ˆ๋‹ค! - ์•„๋ž˜ ๊ณต์‹ ๋ฌธ์„œ ์ฐธ๊ณ ํ•˜์…”์„œ ์–ด๋–ค ๊ฐ’๋“ค์ด state ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€์ง€ ํŒŒ์•…ํ•ด๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค! https://www.notion.so/wecode/Westagram-React-Refactoring-Checklist-aea297cf88ed4601b769e4b2c2cfd4e1#089493d6bfca438aa328226e327cff92
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
- isActive ๋ฅผ state ๋กœ ๊ด€๋ฆฌํ•  ํ•„์š” ์—†์ด, ์—ฌ๊ธฐ์„œ ๋ฐ”๋กœ true / false ๋ฅผ ๊ณ„์‚ฐํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -1,3 +1,106 @@ -*{ - margin: 0; -} \ No newline at end of file +@import '../../../styles/variable.scss'; + +.Login { + @include flexCenter; + flex-direction: column; + align-items: center; + height: 100vh; + + .loginBox { + display: flex; + flex-direction: column; + justify-content: space-between; + border: $default-border; + width: 430px; + + .logo { + @include flexCenter; + align-items: center; + margin-top: 60px; + + .logoFont { + font-size: 50px; + font-family: 'Lobster'; + } + } + + .loginForm { + display: flex; + flex-direction: column; + justify-content: space-around; + align-items: center; + margin-top: 80px; + + .inputWrap { + display: flex; + flex-direction: column; + justify-content: space-evenly; + align-items: center; + height: 50%; + width: 80%; + + .inputId, + .inputPassword { + width: 100%; + } + + input { + width: 100%; + height: 45px; + margin-bottom: 15px; + padding: 2px 10px; + border-radius: 5px; + background-color: #eeeeef; + border: $default-border; + font-size: inherit; + } + } + + .buttonWrap { + @include flexCenter; + flex-direction: column; + align-items: center; + width: 100%; + height: 40%; + margin-top: 25px; + + .loginBtn { + width: 80%; + height: 45px; + border-radius: 5px; + border: transparent; + background-color: $btn-color-active; + /* background-color: #b2dffc; */ + color: white; + font-size: 20px; + padding-top: 4px; + } + + .loginBtn_disabled { + width: 80%; + height: 45px; + border-radius: 5px; + border: transparent; + background-color: $btn-color-disable; + color: white; + font-size: 20px; + padding-top: 4px; + } + } + } + + .forgotText { + display: flex; + flex-direction: column; + justify-content: flex-end; + align-items: center; + margin: 80px 0 30px 0; + + .forgotPassword { + text-align: end; + margin-bottom: 20px; + color: #2c5581; + } + } + } +}
Unknown
- css ์ž‘์—…์„ ํ•˜์‹ค๋•Œ ๋ฐ”๊นฅ ์š”์†Œ์— ํŠน์ •ํ•œ width / height ๊ฐ’์„ ๋ถ€์—ฌํ•˜์‹œ๋Š” ๊ฒƒ ๋ณด๋‹ค, ๋ฐ”๊นฅ ์š”์†Œ์˜ ํฌ๊ธฐ๋Š” ๋‚ด์šฉ๋ฌผ์˜ ํฌ๊ธฐ + margin / padding ๋“ค์˜ ํ•ฉ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํฌ๊ธฐ๊ฐ€ ๊ฒฐ์ •๋˜๋„๋ก ํ•˜์‹œ๋Š” ๊ฒŒ ๋” ์ข‹์Šต๋‹ˆ๋‹ค. - ํ•ญ์ƒ bottom up ๋ฐฉ์‹์œผ๋กœ ์Šคํƒ€์ผ๋ง ํ•˜๋Š” ์Šต๊ด€์„ ๋“ค์—ฌ์ฃผ์„ธ์š”!
@@ -0,0 +1,26 @@ +import React from 'react'; +import './Aside.scss'; + +import ProfileWrap from './ProfileWrap/ProfileWrap'; +import StoryBox from './StoryBox/StoryBox'; +import RecommendBox from './RecommendBox/RecommendBox'; +import WestaInfoBox from './WestaInfoBox/WestaInfoBox'; + +class Aside extends React.Component { + render() { + return ( + <aside className="sideWrapper"> + <div className="sidebar"> + <div className="profile_bar"> + <ProfileWrap /> + <StoryBox /> + <RecommendBox /> + <WestaInfoBox /> + </div> + </div> + </aside> + ); + } +} + +export default Aside;
JavaScript
- Import ์ˆœ์„œ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”! ์ผ๋ฐ˜์ ์ธ convention์„ ๋”ฐ๋ฅด๋Š” ์ด์œ ๋„ ์žˆ์ง€๋งŒ ์ˆœ์„œ๋งŒ ์ž˜ ์ง€์ผœ์ฃผ์…”๋„ ๊ฐ€๋…์„ฑ์ด ์ข‹์•„์ง‘๋‹ˆ๋‹ค. ์•„๋ž˜ ์ˆœ์„œ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”. - React โ†’ Library(Package) โ†’ Component โ†’ ๋ณ€์ˆ˜ / ์ด๋ฏธ์ง€ โ†’ css ํŒŒ์ผ(scss ํŒŒ์ผ) ```suggestion import React from 'react'; import ProfileWrap from './ProfileWrap/ProfileWrap'; import StoryBox from './StoryBox/StoryBox'; import RecommendBox from './RecommendBox/RecommendBox'; import WestaInfoBox from './WestaInfoBox/WestaInfoBox'; import './Aside.scss'; ```
@@ -0,0 +1,56 @@ +import React from 'react'; +import './Content.scss'; + +import Feed from './Feed/Feed'; +import Aside from './Aside/Aside'; + +class Content extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + + render() { + return ( + <div class="Main"> + <main> + <div className="container"> + <section className="articleWrapper"> + {this.state.feeds.map(e => ( + <Feed + feed_id={e.feed_id} + profile_img={e.profile_img} + profile_id={e.profile_id} + feed_img={e.feed_img} + like_click={e.like_click} + like_user_profile_img={e.like_user_profile_img} + like_user_profile_id={e.like_user_profile_id} + like_num={e.like_num} + post_user_mension={e.post_user_mension} + comments={e.comments} + /> + ))} + </section> + <Aside /> + </div> + </main> + </div> + ); + } +} + +export default Content;
JavaScript
- `http://localhost:3000` ์€ ์ƒ๋žต ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ํฌํŠธ ๋ฒˆํ˜ธ๊ฐ€ ๋‹ฌ๋ผ์ง€๋ฉด(ex. `localhost:3001`) fetch ํ•จ์ˆ˜๋ฅผ ์ผ์ผ์ด ์ˆ˜์ •ํ•ด์ฃผ์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์–ด๋ ค์›Œ์ง‘๋‹ˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ ์ฐธ๊ณ ํ•ด์„œ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”! ```jsx const foo = () => { // fetch("http://localhost:3000/images/1") fetch("/images/1") } ``` - fetchํ•จ์ˆ˜์˜ `get method`๋Š” method์˜ default ๊ฐ’์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ```jsx const foo = () => { fetch(`${cartAPI}/quantity`) .then((res) => res.json()) ```
@@ -0,0 +1,56 @@ +import React from 'react'; +import './Content.scss'; + +import Feed from './Feed/Feed'; +import Aside from './Aside/Aside'; + +class Content extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + + render() { + return ( + <div class="Main"> + <main> + <div className="container"> + <section className="articleWrapper"> + {this.state.feeds.map(e => ( + <Feed + feed_id={e.feed_id} + profile_img={e.profile_img} + profile_id={e.profile_id} + feed_img={e.feed_img} + like_click={e.like_click} + like_user_profile_img={e.like_user_profile_img} + like_user_profile_id={e.like_user_profile_id} + like_num={e.like_num} + post_user_mension={e.post_user_mension} + comments={e.comments} + /> + ))} + </section> + <Aside /> + </div> + </main> + </div> + ); + } +} + +export default Content;
JavaScript
- mock up ๋ฐ์ดํ„ฐ์˜ ํ‚ค ๊ฐ’์€ ์Šค๋„ค์ดํฌ ์ผ€์ด์Šค๋กœ ์‚ฌ์šฉํ•ด์ฃผ์…”๋„ ๋˜์ง€๋งŒ (๋ฐฑ์—”๋“œ์—์„œ๋Š” ๋ณดํ†ต ์Šค๋„ค์ดํฌ ์ผ€์ด์Šค๋ฅผ ์“ฐ๊ธฐ ๋•Œ๋ฌธ์—) props ์˜ ์ด๋ฆ„์€ ์นด๋ฉœ ์ผ€์ด์Šค๋กœ ํ†ต์ผํ•ด ์ฃผ์„ธ์š”!
@@ -1,3 +1,5 @@ -import date from './date.svg'; -export * from './Eyes'; +import date from "./date.svg"; +export * from "./Eyes"; export { date }; +import Logo from "./Logo.svg"; +export { Logo };
TypeScript
svg๋Š” import logo from './logo.svg'; export {logo}; ์ด๋Ÿฐ ์‹์œผ๋กœ ํ•ด์ฃผ์–ด์•ผํ• ํ…๋ฐ ์ง€๊ธˆ ์ •์ƒ ์ž‘๋™ํ•˜์‹œ๋‚˜์š”? ๊ทธ๋ฆฌ๊ณ  ์ด๋ฏธ์ง€๋Š” ์†Œ๋ฌธ์ž๋กœ ๋„ค์ด๋ฐํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,65 @@ +import styled from "styled-components"; +import { Logo } from "../../assets"; +import { useState } from "react"; +import { LoginBtn } from "../header/LoginBtn"; +import { font } from "../../theme"; + +export const Header = () => { + const [isLogined, setIsLogined] = useState<boolean>(false); + + return ( + <Container> + {isLogined && ( + <> + <img src={Logo} alt={"logo"} /> + <Box> + <LeftBox> + <p>ํ•™์ƒ๋ด‰์‚ฌ ์‹œ๊ฐ„ ์กฐํšŒ/๋ถ€์—ฌ</p> + <p>๋ด‰์‚ฌํ™œ๋™ ์‹ ์ฒญ ์กฐํšŒ/์ƒ์„ฑ</p> + <p>๋ด‰์‚ฌ ์ผ์ • ํ™•์ธ</p> + <p>์•Œ๋ฆผ ์ƒ์„ฑ</p> + </LeftBox> + <RightBox> + <p>๋งˆ์ดํŽ˜์ด์ง€</p> + <LoginBtn isLogined={isLogined} /> + </RightBox> + </Box> + </> + )} + {!isLogined && ( + <Box> + <img src={Logo} alt={"logo"} /> + <LoginBtn isLogined={isLogined} /> + </Box> + )} + </Container> + ); +}; + +const Container = styled.div` + width: 100vw; + height: 70px; + display: flex; + align-items: center; + padding: 0 90px; + gap: 82.5px; + font: ${font.Body3}; +`; + +const Box = styled.div` + width: 100%; + display: flex; + justify-content: space-between; +`; + +const LeftBox = styled.div` + display: flex; + gap: 82.5px; + align-items: center; +`; + +const RightBox = styled.div` + display: flex; + align-items: center; + gap: 82.5px; +`;
Unknown
์ด๊ฑด ์™œ ์ด๋ ‡๊ฒŒ ๋ถˆ๋Ÿฌ์˜ค์‹œ๋‚˜์šฉ
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
๊ตฌ์กฐ๋ถ„ํ•ดํ• ๋‹น์„ ์ž˜ ์“ฐ์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
comment๊ด€๋ จ ํ•จ์ˆ˜๋ฅผ ๊น”๋”ํ•˜๊ฒŒ ์ž˜ ์ •๋ฆฌํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
์ปค๋ฉ˜ํŠธ ์ปดํฌ๋„ŒํŠธ์— ํ”„๋กญ์Šค ์ „๋‹ฌ์„ ๊น”๋”ํ•˜๊ฒŒ ์ž˜ ํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
์‚ผํ•ญ์—ฐ์‚ฐ์ž ์‚ฌ์šฉ์„ ์ž˜ ํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
Lifecycle Method๋ฅผ ์ž˜ ์‚ฌ์šฉํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
์ €๋„ ์ ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!๐Ÿ‘
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
๋ฒ„ํŠผ์ด ํ™œ์„ฑํ™”๋  ๋•Œ ์ƒ‰์ƒ ๋ณ€๊ฒฝ๊ณผ ๋น„ํ™œ์„ฑํ™” ๊ธฐ๋Šฅ๊นŒ์ง€ ๊ตฌํ˜„ํ•˜์‹  ์  ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค:)
@@ -0,0 +1,74 @@ +[ + { + "id": 1, + "userName": "bbangho", + "alt": "wecode", + "img": "/images/youngho/hanRiver.jpeg", + "comment": [ + { + "id": 1, + "userName": "bbangho", + "content": "ํ•œ๊ฐ• ๋‹ค๋…€๊ฐ~ โœŒ๏ธ", + "isLiked": true + }, + { + "id": 2, + "userName": "manja", + "content": "ํ•œ๊ฐ• ๊ฐฑ~ ๐Ÿ”ซ ๐Ÿ”ซ", + "isLiked": true + } + ] + }, + { + "id": 2, + "userName": "joonsikyang", + "alt": "wecode", + "img": "/images/youngho/we.jpeg", + "comment": [ + { + "id": 1, + "userName": "joonsikyang", + "content": "Work hard ๐Ÿคฏ", + "isLiked": true + }, + { + "id": 2, + "userName": "bbangho", + "content": "Go for it ๐Ÿคฃ", + "isLiked": false + }, + { + "id": 3, + "userName": "manja", + "content": "๐Ÿ”ฅ๐Ÿ”ฅ", + "isLiked": false + } + ] + }, + { + "id": 3, + "userName": "jayPark", + "alt": "wecode", + "img": "/images/youngho/we.jpeg", + "comment": [ + { + "id": 1, + "userName": "jayPark", + "content": "Let's get it", + "isLiked": true + }, + { + "id": 2, + "userName": "bbanho", + "content": "Skrt~ ๐Ÿ˜Ž", + "isLiked": false + }, + { + "id": 3, + "userName": "gildong", + "content": "Yo~ ๐ŸŒž", + "isLiked": true + } + ] + } +]
Unknown
๋ชฉ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ ๋„ˆ๋ฌด ์ข‹์Šต๋‹ˆ๋‹ค! :)
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
```suggestion <button onClick={this.handleLogin} className={condition ? 'buttonActivate' : 'buttonDisabled'} id="loginButton" disabled={ condition ? false : true} > ๋กœ๊ทธ์ธ </button> ``` ํ•ด๋‹น ์กฐ๊ฑด์„ condition์ด๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด์•„์„œ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๊ฐ€๋…์„ฑ์ด ๋” ์ข‹์•„์ง€๊ฒ ๋„ค์š”! ex) ``` const condition = loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); ```
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
์ฐธ๊ณ ๋กœ ์œ„์˜ ๋ณ€์ˆ˜๋Š” render ํ•จ์ˆ˜ ๋‚ด์—์„œ ์„ ์–ธํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค!!
@@ -0,0 +1,78 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +body { + background-color: #fafafa; +} + +.container { + text-align: center; + width: 600px; + height: 600px; + margin: 50px auto 0 auto; + border: 1px solid #e6e6e6; + background-color: white; +} + +.header { + padding: 30px; + font-family: 'Lobster', cursive; + font-size: 70px; + font-weight: 1px; +} + +.loginForm { + width: 425px; + margin: 0 auto; +} + +#id { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#password { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#loginButton { + display: block; + width: 459px; + margin: 20px 0px auto; + padding: 15px; + border: 0px; + border-radius: 5px; + color: white; + font-size: 20px; +} + +.findPassword { + display: block; + height: 50px; + margin-top: 180px; + font-size: 18px; + text-decoration: none; +} + +.buttonDisabled { + background-color: #c5e1fc; +} + +.buttonActivate { + background-color: #0095f6; +} + +a { + text-decoration: none; +}
Unknown
```suggestion body { background-color: #fafafa; } .container { text-align: center; border: 1px solid #e6e6e6; background-color: white; width: 600px; height: 600px; margin: 50px auto 0 auto; } .header { font-family: 'Lobster', cursive; font-size: 70px; font-weight: 1px; padding: 30px; } ``` ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ์…€๋Ÿญํ„ฐ ์‹œ์ž‘ํ•  ๋•Œ๋Š” ํ•œ ์ค„ ๋„์›Œ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
@@ -0,0 +1,78 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +body { + background-color: #fafafa; +} + +.container { + text-align: center; + width: 600px; + height: 600px; + margin: 50px auto 0 auto; + border: 1px solid #e6e6e6; + background-color: white; +} + +.header { + padding: 30px; + font-family: 'Lobster', cursive; + font-size: 70px; + font-weight: 1px; +} + +.loginForm { + width: 425px; + margin: 0 auto; +} + +#id { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#password { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#loginButton { + display: block; + width: 459px; + margin: 20px 0px auto; + padding: 15px; + border: 0px; + border-radius: 5px; + color: white; + font-size: 20px; +} + +.findPassword { + display: block; + height: 50px; + margin-top: 180px; + font-size: 18px; + text-decoration: none; +} + +.buttonDisabled { + background-color: #c5e1fc; +} + +.buttonActivate { + background-color: #0095f6; +} + +a { + text-decoration: none; +}
Unknown
์˜ํ˜ธ๋‹˜! ์ „์ฒด์ ์œผ๋กœ CSS ์†์„ฑ ์ˆœ์„œ ํ™•์ธํ•ด์„œ ์ ์šฉํ•ด์ฃผ์„ธ์š”~ - ํ•˜๋‚˜์˜ ์š”์†Œ์— ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์†์„ฑ์„ ๋ถ€์—ฌํ•˜๋Š” ๊ฒฝ์šฐ ์ค‘์š”๋„, ๊ด€๋ จ๋„์— ๋”ฐ๋ผ์„œ ๋‚˜๋ฆ„์˜ convention์„ ์ง€์ผœ์„œ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. - ์ผ๋ฐ˜์ ์ธ convention ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆœ์„œ ์ ์šฉํ•ด์ฃผ์„ธ์š”. [CSS property ์ˆœ์„œ] - Layout Properties (position, float, clear, display) - Box Model Properties (width, height, margin, padding) - Visual Properties (color, background, border, box-shadow) - Typography Properties (font-size, font-family, text-align, text-transform) - Misc Properties (cursor, overflow, z-index)
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
import ์ˆœ์„œ๋Š” ์ž˜ ๋งž์ถฐ์ฃผ์…จ๊ณ , ํ•ด๋‹น ๋ถ€๋ถ„์—์„œ๋Š” ์ค„๋ฐ”๊ฟˆ ์—†์ด ์ง„ํ–‰ํ•ด์ฃผ์„ธ์š”~
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
fetchํ•จ์ˆ˜์˜ `get method๋Š” method์˜ default` ๊ฐ’์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ `์ƒ๋žต์ด ๊ฐ€๋Šฅ`ํ•ฉ๋‹ˆ๋‹ค. ๊ณ ๋กœ get method ์š”์ฒญ์‹œ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ๋‘๋ฒˆ์งธ ์ธ์ž๊ฐ€ ์ƒ๋žต ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ```jsx const foo = () => { fetch(`${cartAPI}/quantity`) .then((res) => res.json()) ```