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

[Week9/#33] 9주차 워크북 미션 3 #34

Open
wants to merge 6 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
24 changes: 24 additions & 0 deletions playlist/.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 playlist/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
38 changes: 38 additions & 0 deletions playlist/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import js from '@eslint/js'
import globals from 'globals'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'

export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
settings: { react: { version: '18.3' } },
plugins: {
react,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
17 changes: 17 additions & 0 deletions playlist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!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>Hello React</title>
</head>
<body>
<body>
<div id="root"></div>
<div id="portal"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</body>
</html>
35 changes: 35 additions & 0 deletions playlist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "playlist",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@heroicons/react": "^2.2.0",
"@reduxjs/toolkit": "^2.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
"react-redux": "^9.1.2",
"redux": "^5.0.1",
"styled-components": "^6.1.13",
"zustand": "^5.0.1"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^9.13.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"vite": "^5.4.10"
}
}
1 change: 1 addition & 0 deletions playlist/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.
Empty file added playlist/src/App.css
Empty file.
80 changes: 80 additions & 0 deletions playlist/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*import Navbar from './components/Navbar'
import Footer from './components/Footer'
import CartContainer from './components/CartContainer'
import { useDispatch, useSelector } from 'react-redux'
import { useEffect } from 'react'
import { calculateTotals } from './features/cart/cartSlice'
import ModalPotal from './components/ModalPortal'
import Modal from './components/Modal'

function App() {
const dispatch=useDispatch()
const {cartItems} = useSelector((store)=>store.cart)
const {isOpen} = useSelector((store)=>store.modal)

useEffect(()=>{
dispatch(calculateTotals())
},[cartItems,dispatch])

return (
<>
<header>
<Navbar/>
</header>
<main>
<CartContainer/>
{isOpen&&<ModalPotal>
<Modal>
<h4>담아두신 모든 음반을 삭제하시겠습니까?</h4>
</Modal>
</ModalPotal>}
</main>
<footer>
<Footer/>
</footer>
</>
)
}

export default App;*/

import Navbar from './components/Navbar';
import Footer from './components/Footer';
import CartContainer from './components/CartContainer';
import { useEffect } from 'react';
import ModalPortal from './components/ModalPortal';
import Modal from './components/Modal';
import useCartStore from './features/cart/cartSlice'; // Zustand 장바구니 훅
import useModalStore from './features/modal/modalSlice'; // Zustand 모달 훅

function App() {
const { cartItems, calculateTotals } = useCartStore();
const { isOpen } = useModalStore();

useEffect(() => {
calculateTotals(); // Zustand 메서드 호출
}, [cartItems, calculateTotals]);

return (
<>
<header>
<Navbar />
</header>
<main>
<CartContainer />
{isOpen && (
<ModalPortal>
<Modal>
<h4>담아두신 모든 음반을 삭제하시겠습니까?</h4>
</Modal>
</ModalPortal>
)}
</main>
<footer>
<Footer />
</footer>
</>
);
}

export default App;
1 change: 1 addition & 0 deletions playlist/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading