-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3주차 기본과제] 당신 누구얒! #5
base: main
Are you sure you want to change the base?
Changes from 11 commits
8373745
e9666ad
9eac4db
f2ed87c
add1dc8
3d3c8e5
db9c988
67a3a4c
41b1ba7
3185fc2
133600c
7dd695d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "week03", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/user-event": "^13.5.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-scripts": "5.0.1", | ||
"styled-components": "^5.3.6", | ||
"styled-reset": "^4.4.2", | ||
"web-vitals": "^2.1.4" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
name="description" | ||
content="Web site created using create-react-app" | ||
/> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
|
||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>인물퀴즈 게임</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
|
||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
|
||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
}, | ||
{ | ||
"src": "logo192.png", | ||
"type": "image/png", | ||
"sizes": "192x192" | ||
}, | ||
{ | ||
"src": "logo512.png", | ||
"type": "image/png", | ||
"sizes": "512x512" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import Header from './components/Header'; | ||
import Content from './components/Content'; | ||
|
||
import styled from 'styled-components'; | ||
import { useEffect, useState } from 'react'; | ||
import image1 from './image/공유.jpeg'; | ||
import image2 from './image/마동석.jpeg'; | ||
import image3 from './image/서프라이즈.jpeg'; | ||
import image4 from './image/손석구.jpg'; | ||
import image5 from './image/윤지영.jpeg'; | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
height: 100vh; | ||
background-color: #ecc9c9; | ||
`; | ||
|
||
const Done = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
height: 40px; | ||
font-size: 32px; | ||
font-weight: 700; | ||
`; | ||
|
||
const people = [ | ||
['공유', image1, ['홍명헌', '정현욱', '이주함', '공유', '김형겸']], | ||
['마동석', image2, ['박현지', '장명지', '이서영', '마동석', '윤지영']], | ||
['이수완', image3, ['이수완', '이수안', '서프라이즈 걔', '이수온', '이수']], | ||
['손석구', image4, ['김필', '홍명헌', '손석구', '발석구', '티벳여우']], | ||
]; | ||
|
||
export default function App() { | ||
const [index, setIndex] = useState(0); | ||
const [point, setPoint] = useState(0); | ||
const [answer, setAnswer] = useState(false); | ||
const [reset, setReset] = useState(); | ||
|
||
const checkPerson = (example) => { | ||
if (example === people[index][0]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. people[index][0]은 다른 사람이 봤을 때는 이해하기 힘들 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수명..함수명... 가독성 높이기 동참하겠습니다...!! |
||
alert('정답!!'); | ||
setAnswer(true); | ||
} else { | ||
alert('땡!!'); | ||
setAnswer(false); | ||
} | ||
}; | ||
|
||
const resetGame = () => { | ||
setReset(true); | ||
}; | ||
|
||
useEffect(() => { | ||
if (reset === true) { | ||
setIndex(0); | ||
setPoint(0); | ||
} | ||
setReset(false); | ||
}, [reset]); | ||
|
||
useEffect(() => { | ||
if (answer) { | ||
setPoint(point + 1); | ||
setIndex(index + 1); | ||
} | ||
setAnswer(false); | ||
}, [answer]); | ||
|
||
return ( | ||
<Container> | ||
<Header /> | ||
{index === people.length && <Done>!끝!</Done>} | ||
{index < people.length && ( | ||
<Content | ||
point={point} | ||
image={people[index][1]} | ||
example={people[index][2]} | ||
person={people[index][0]} | ||
checkPerson={checkPerson} | ||
resetGame={resetGame} | ||
index={index} | ||
lenght={people.length} | ||
/> | ||
Comment on lines
+74
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. people 자체를 props로 넘겨주면 image, example, person, length props는 없어도 될 것 같은데 어떻게 생각하시나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음 제 생각에는 하지만 개발자가 충분히 객체정보에 대한 이해도가 있거나, 복잡하지 않은 객체에 대해서는 말해준것처럼 넘겨주는것도 좋은거 같네요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 이해했어요! 그렇게 생각할 수 있을 것 같아요 |
||
)} | ||
{index === people.length && ( | ||
<Content | ||
point={point} | ||
image={image5} | ||
Comment on lines
+72
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. index와 people.length를 이용해서 조건부 렌더링으로 잘 보여주고 있는 것 같아요! 그런데 72번째 줄과 85번째 줄의 조건이 동일하니까 하나로 묶고, 삼항연산자로 표현하는 게 항상 정답은 아니지만 . . . 좀 더 가독성 좋은 방식으로 조건부 렌더링을 해주면 좋을 것 같은데 어떠신가요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2가지의 케이스로 나뉠 때에는 삼항연산자가 좋은거 같아요!!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지금 다시 고민해보니깐 |
||
example={people[index - 1][2]} | ||
person={people[index - 1][0]} | ||
checkPerson={checkPerson} | ||
resetGame={resetGame} | ||
/> | ||
)} | ||
</Container> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import styled from 'styled-components'; | ||
|
||
const StyledContent = styled.main` | ||
height: 700px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
|
||
const StyledScore = styled.nav` | ||
height: 80px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 36px; | ||
font-weight: 700; | ||
`; | ||
|
||
const ImageBox = styled.img` | ||
width: 400px; | ||
height: 400px; | ||
border-radius: 5px; | ||
object-fit: cover; | ||
`; | ||
|
||
const NameList = styled.div` | ||
list-style: none; | ||
width: 400px; | ||
height: 40px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-top: 20px; | ||
`; | ||
|
||
const NameItem = styled.button` | ||
list-style: none; | ||
width: 75px; | ||
height: 35px; | ||
`; | ||
|
||
const ResetBtn = styled.button` | ||
list-style: none; | ||
width: 210px; | ||
height: 35px; | ||
`; | ||
|
||
const BtnWrap = styled.div` | ||
height: 80px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
margin-top: 20px; | ||
`; | ||
|
||
Content.defaultProps = { | ||
point: '0', | ||
}; | ||
Comment on lines
+57
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. App.jsx에서 point state가 0으로 초기화 되어있는데 이 코드도 꼭 필요한가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 그렇군요...!!ㅎㅎㅎ불필요한거 같습니다!! 반영하겠습니당ㅎㅎㅎ |
||
|
||
export default function Content(props) { | ||
const { image, example, checkPerson, resetGame, index, length } = props; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. props 꺼내서 쓰는 거 좋은 것 같아요~👍👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 갓지영님이 일려주셨습니다!!>_< There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 질투나네요~ 저한테도 물어봐주세요~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ |
||
|
||
return ( | ||
<StyledContent> | ||
<StyledScore>{props.point} 점</StyledScore> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. point 변수 비구조화할당 해주는거 빠짐~ |
||
<ImageBox src={image}></ImageBox> | ||
{index !== length && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. index가 length보다 커지면 안되니깐 index < length 가 더 정확해보여요!! |
||
<NameList> | ||
<NameItem onClick={() => checkPerson(example[0])}> | ||
{example[0]} | ||
</NameItem> | ||
<NameItem onClick={() => checkPerson(example[1])}> | ||
{example[1]} | ||
</NameItem> | ||
<NameItem onClick={() => checkPerson(example[2])}> | ||
{example[2]} | ||
</NameItem> | ||
<NameItem onClick={() => checkPerson(example[3])}> | ||
{example[3]} | ||
</NameItem> | ||
<NameItem onClick={() => checkPerson(example[4])}> | ||
{example[4]} | ||
</NameItem> | ||
</NameList> | ||
Comment on lines
+69
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거는 똑같은 코드가 중복적으로 반복되고 있으니까 map()을 이용해보면 어떨까여 |
||
)} | ||
<BtnWrap> | ||
<ResetBtn onClick={resetGame}>다시하기</ResetBtn> | ||
</BtnWrap> | ||
</StyledContent> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import styled from 'styled-components'; | ||
|
||
const StyledHeader = styled.header` | ||
height: 100px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 32px; | ||
font-weight: 700; | ||
color: white; | ||
`; | ||
|
||
export default function Header() { | ||
return <StyledHeader>👩🏻🦰👩🏻🦳인물퀴즈 게임👨🏻🦳👨🏻🦰</StyledHeader>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App'; | ||
import { Reset } from 'styled-reset'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
root.render( | ||
<React.StrictMode> | ||
<Reset/> | ||
<App /> | ||
</React.StrictMode> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean 변수니까
isCorrect
이런식으로 '정답 여부'가 변수명에 포함되면 이해하기 좋지 않을까요?지금은 answer 라는 명사여서 string이 들어갈 것 같은 변수라서요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오,,,,이런게 좋은변수,함수명 짓기군요...!! 앞으로 코딩할때 신경써서 작성해야겠네요!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
근데 저도 이름 잘 못 짓거든요 ㅋㅋ 같이 노력해요