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">๋ง์ง ์์ธ ์ ๋ณด ></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">๋ง์ง ์์ธ ์ ๋ณด ></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">๋ง์ง ์์ธ ์ ๋ณด ></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

 |
@@ -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",
+ }}
+ >
+ <
+ </Button>
+ <Button
+ onClick={handleOnClickRight}
+ variant="text"
+ className="right-button"
+ style={{
+ backgroundColor: "transparent",
+ zIndex: "10",
+ position: "absolute",
+ right: "0px",
+ }}
+ >
+ >
+ </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,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",
+ }}
+ >
+ <
+ </Button>
+ <Button
+ onClick={handleOnClickRight}
+ variant="text"
+ className="right-button"
+ style={{
+ backgroundColor: "transparent",
+ zIndex: "10",
+ position: "absolute",
+ right: "0px",
+ }}
+ >
+ >
+ </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",
+ }}
+ >
+ <
+ </Button>
+ <Button
+ onClick={handleOnClickRight}
+ variant="text"
+ className="right-button"
+ style={{
+ backgroundColor: "transparent",
+ zIndex: "10",
+ position: "absolute",
+ right: "0px",
+ }}
+ >
+ >
+ </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">๋ง์ง ์์ธ ์ ๋ณด ></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">๋ง์ง ์์ธ ์ ๋ณด ></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">๋ง์ง ์์ธ ์ ๋ณด ></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())
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.