Skip to content
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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions week03/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Empty file added week03/README.md
Empty file.
28,702 changes: 28,702 additions & 0 deletions week03/package-lock.json

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions week03/package.json
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"
]
}
}
Binary file added week03/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions week03/public/index.html
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>
Binary file added week03/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week03/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions week03/public/manifest.json
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"
}
3 changes: 3 additions & 0 deletions week03/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
97 changes: 97 additions & 0 deletions week03/src/App.jsx
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean 변수니까 isCorrect 이런식으로 '정답 여부'가 변수명에 포함되면 이해하기 좋지 않을까요?
지금은 answer 라는 명사여서 string이 들어갈 것 같은 변수라서요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오,,,,이런게 좋은변수,함수명 짓기군요...!! 앞으로 코딩할때 신경써서 작성해야겠네요!!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 저도 이름 잘 못 짓거든요 ㅋㅋ 같이 노력해요

const [reset, setReset] = useState();

const checkPerson = (example) => {
if (example === people[index][0]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

people[index][0]은 다른 사람이 봤을 때는 이해하기 힘들 것 같아요.
그리고 example이라는 변수명도 무엇을 의미하는지 한번에 이해하기 힘들었어요.
변수명을 이해하기 쉽게 바꿔보는 건 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

people 자체를 props로 넘겨주면 image, example, person, length props는 없어도 될 것 같은데 어떻게 생각하시나요?
props가 너무 많으면 코드를 봤을 때 이해하기 힘들 수 있고, 다른 곳에서 재사용하기도 힘들 수 있을 것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 제 생각에는
Content를 함수같은 느낌으로 바라보면,
people로 인자로 전달받은 컴포넌트에서 변수를 설정해줄 텐데
그럼 변수를 설정할때 전달한 컴포넌트로 가서 확인하고 변수를 설정하고 하는 작업의 번거로움도 있을거 같아요!!
그래서 해당 변수가 존재하는 컴포넌트에서 각각의 변수를 나누어서 전달하는게 좋다고 생각해서 저렇게 코딩한거 같아요!

하지만 개발자가 충분히 객체정보에 대한 이해도가 있거나, 복잡하지 않은 객체에 대해서는 말해준것처럼 넘겨주는것도 좋은거 같네요!!

Copy link

@leeseooo leeseooo Nov 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 이해했어요! 그렇게 생각할 수 있을 것 같아요
저도 다시 한 번 고민해봤는데요, people 변수를 배열 안의 배열(이차원배열)로 만들지 않고
key,value를 가진 객체로 만드는 건 어떨까요?
image, example, person 을 프로퍼티로 가진 객체로 people을 변경한다면
props로 people만 넘겨주더라도 그 안에서 다시 구조분해 할당을 해서 사용할 수 있을 것 같아요.

)}
{index === people.length && (
<Content
point={point}
image={image5}
Comment on lines +72 to +88
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index와 people.length를 이용해서 조건부 렌더링으로 잘 보여주고 있는 것 같아요!

그런데 72번째 줄과 85번째 줄의 조건이 동일하니까 하나로 묶고,
73번째 줄 Content 컴포넌트를 하나로 묶어서,
삼항연산자(? : )로 나타내는 건 어떨까요?

삼항연산자로 표현하는 게 항상 정답은 아니지만 . . . 좀 더 가독성 좋은 방식으로 조건부 렌더링을 해주면 좋을 것 같은데 어떠신가요

Copy link
Collaborator Author

@myeongheonhong myeongheonhong Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2가지의 케이스로 나뉠 때에는 삼항연산자가 좋은거 같아요!!
위에 예시에서는 작거나 같거나 클수도 있는 조건이면 저런식으로 표현해주는게 더 좋을거 같다는 생각이 드네요!
위의 예시에서 삼항연산자를 사용하게 되는 경우에는 작지 않은 경우에는 두가지(같음,큰경우)가 있기 때문에 해당 조건식으로 나타내봤습니당!!
(사실 삼항연산자는 생각도 못해봤습니다,,,,^^;;;;;)

  • Done 컴포넌트는 합치는게 좋겠네요!!ㅎㅎㄱㅅㄱㅅ

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 다시 고민해보니깐
index < people.length 일 때, 그렇지 않을 때 두 가지로 나눠서 컴포넌트를 보여주면 좋을 것 같아요
index === people.length 일 때 보여주고 있는 Content 컴포넌트랑 Done 컴포넌트를 합쳐도 될 것 같아요
지영언니가 땅콩먹는 이미지 Content가 문제에 해당하는게 아니라 사실은 끝났을때 보여주는 거니까요.
어떻게 생각혀

example={people[index - 1][2]}
person={people[index - 1][0]}
checkPerson={checkPerson}
resetGame={resetGame}
/>
)}
</Container>
);
}
92 changes: 92 additions & 0 deletions week03/src/components/Content.jsx
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App.jsx에서 point state가 0으로 초기화 되어있는데 이 코드도 꼭 필요한가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props 꺼내서 쓰는 거 좋은 것 같아요~👍👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

갓지영님이 일려주셨습니다!!>_<

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질투나네요~ 저한테도 물어봐주세요~

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ


return (
<StyledContent>
<StyledScore>{props.point} 점</StyledScore>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

point 변수 비구조화할당 해주는거 빠짐~

<ImageBox src={image}></ImageBox>
{index !== length && (
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거는 똑같은 코드가 중복적으로 반복되고 있으니까 map()을 이용해보면 어떨까여

)}
<BtnWrap>
<ResetBtn onClick={resetGame}>다시하기</ResetBtn>
</BtnWrap>
</StyledContent>
);
}
15 changes: 15 additions & 0 deletions week03/src/components/Header.jsx
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>;
}
Binary file added week03/src/image/공유.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week03/src/image/마동석.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week03/src/image/서프라이즈.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week03/src/image/손석구.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week03/src/image/윤지영.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions week03/src/index.jsx
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>
);
Loading