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

Study #6

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions study/test/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions study/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
8 changes: 8 additions & 0 deletions study/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
13 changes: 13 additions & 0 deletions study/test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions study/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "test",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"vite": "^5.2.0"
}
}
1 change: 1 addition & 0 deletions study/test/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions study/test/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
142 changes: 142 additions & 0 deletions study/test/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import styled from '@emotion/styled';
import { useState } from 'react';

const App = () => {
const [recommend, setRecommend] = useState('');
const [foodType, setFoodType] = useState(false);
const [selectedFoodType, setSelectedFoodType] = useState('');
const [category, setCategory] = useState(false);
const [selectedCategory, setSelectedCategory] = useState('');
const [broth, setBroth] = useState(false);
const [selectedBroth, setSelectedBroth] = useState('');

const handleSoupSelection = (brothOption) => {
setSelectedBroth(brothOption);
};

const handleRecommendation = (type) => {
setRecommend(type);
};

const handleStartButtonClick = () => {
setFoodType(true);
setRecommend(null);
};

const handleFoodSelection = (food) => {
setSelectedFoodType(food);
setCategory(false);
};

const handleNextClick = () => {
setCategory(true);
setFoodType(false);
setRecommend(null);
};

const handleCategorySelection = (category) => {
setSelectedCategory(category);
};

return (
<Body>
Copy link
Contributor

Choose a reason for hiding this comment

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

Body라는 컴포넌트명이 이 컴포넌트의 역할을 정확히 명시해주지 않는 것 같아요 ! 가독성있는 코드를 고려해보면 좋겠습니다!
예를 들면 MenuSelectWrapper ~

<div>
<h1>오늘의 점매추</h1>
<h3>원하는 추천 방식을 골라줘</h3>
</div>
<ButtonWrapper>
{/* 음식유형 화면 체크 =!foodType */}
{!foodType && (!recommend || recommend === 'taste') &&(
<Button selected={recommend === 'taste'} onClick={() => handleRecommendation('taste')}>
취향대로 추천
</Button>
) }
<SmallButtonWrapper>
{!foodType && (!recommend || recommend === 'random') && (
<Button selected={recommend === 'random'}onClick={() => handleRecommendation('random')}>
랜덤 추천
</Button>
) }
</SmallButtonWrapper>
</ButtonWrapper>
{recommend && (
<StartButton onClick={handleStartButtonClick}>
시작
</StartButton>
)}
{foodType && (
<div>
<ButtonFoodType selected={selectedFoodType === 'Korean'} onClick={() => handleFoodSelection('Korean')}>한식</ButtonFoodType>
<ButtonFoodType selected={selectedFoodType === 'Chinese'} onClick={() => handleFoodSelection('Chinese')}>중식</ButtonFoodType>
<ButtonFoodType selected={selectedFoodType === 'Japanese'} onClick={() => handleFoodSelection('Japanese')}>일식</ButtonFoodType>
</div>
)}

{selectedFoodType && (
<div>
<Button onClick={handleNextClick}>다음으로</Button>
</div>
)}
{category && (
<div>
<ButtonFoodType selected={selectedCategory === 'Rice'} onClick={() => handleCategorySelection('Rice')}>밥</ButtonFoodType>
<ButtonFoodType selected={selectedCategory === 'Noodle'} onClick={() => handleCategorySelection('Noodle')}>면</ButtonFoodType>
<ButtonFoodType selected={selectedCategory === 'Mseafood'} onClick={() => handleCategorySelection('Mseafood')}>고기/해물</ButtonFoodType>
</div>
)}
Comment on lines +80 to +86
Copy link
Contributor

Choose a reason for hiding this comment

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

이부분을 선택해도 그대로 렌더링 되어있네요! 이건 step이라는 상태를 관리하면서
step=0일 땐 이부분을 렌더링하고 step=1일 땐 아래 국물 컴포넌트를 렌더링 하는 구조로 가면 좋을 것 같아요!
그럴러면 지금 이부분 음식 종류 컴포넌트와 국물컴포넌트(국물을 선택하는 컴포넌트) 는 컴포넌트로 따로 분리해주는 것이 코드 가독성이 좋겠죠 지금 이 App내에 너무 많은 역할을 하는 코드가 있는 것 같습니다

{selectedCategory && (
<div>
<Button onClick={() => setBroth(true)}>다음으로</Button>
</div>
)}
{broth && (
<div>
<ButtonFoodType selected={selectedBroth === 'soup'} onClick={() => handleSoupSelection('soup')}>국물O</ButtonFoodType>
<ButtonFoodType selected={selectedBroth === 'nosoup'} onClick={() => handleSoupSelection('nosoup')}>국물X</ButtonFoodType>
Copy link
Contributor

Choose a reason for hiding this comment

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

nonSoup로 값을 정하면 더 좋을 것 같네요 soup가 없다 가 아니라 soup가 아니다 이니까요!
그리고 가독성을 위한 카멜케이스 사용도 추천합니다

</div>
)}
</Body>
);
};

export default App;

const Button = styled.button`
cursor: pointer;
background: blue;
color: black;
padding: ${(props) => props.selected ? '3rem 4.5rem' : '2rem 3rem'};
margin: 0.8rem;
font-weight: bold;
&:hover {
background-color: white;
color: gray;
}
`;

const StartButton = styled(Button)`
padding: 1rem 2rem;
background: red;
`;

const ButtonWrapper = styled.div`
display: flex;
gap: 1.5rem;
`;

const Body = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`;

const SmallButtonWrapper = styled.div`
display: flex;
`;

const ButtonFoodType = styled(Button)`
//선택시 색깔변경
background: ${(props) => props.selected ? 'white' : 'blue'};
color: ${(props) => props.selected ? 'gray' : 'black'};
`;
Loading