Skip to content
Merged
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 judy/Week9/cart/.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?
54 changes: 54 additions & 0 deletions judy/Week9/cart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# React + TypeScript + 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) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:

```js
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:

```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
```
28 changes: 28 additions & 0 deletions judy/Week9/cart/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions judy/Week9/cart/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 + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions judy/Week9/cart/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "cart",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@reduxjs/toolkit": "^2.8.2",
"@tailwindcss/vite": "^4.1.8",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"react-icons": "^5.5.0",
"react-redux": "^9.2.0",
"tailwindcss": "^4.1.8",
"zustand": "^5.0.5"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"@vitejs/plugin-react-swc": "^3.9.0",
"eslint": "^9.25.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"typescript": "~5.8.3",
"typescript-eslint": "^8.30.1",
"vite": "^6.3.5"
}
}
1 change: 1 addition & 0 deletions judy/Week9/cart/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 judy/Week9/cart/src/App.css
Empty file.
18 changes: 18 additions & 0 deletions judy/Week9/cart/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Provider } from "react-redux";
import "./App.css";
import { Header } from "./components/Header";
import { CartPage } from "./page/CartPage";
import store from "./store/store";

function App() {
return (
<Provider store={store}>
<div className="flex flex-col w-screen h-screen">
<Header />
<CartPage />
</div>
</Provider>
);
}

export default App;
1 change: 1 addition & 0 deletions judy/Week9/cart/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.
11 changes: 11 additions & 0 deletions judy/Week9/cart/src/components/BlurBackground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface Props {
children: React.ReactNode;
}

export const BlurBackground = ({ children }: Props) => {
return (
<div className="h-screen w-screen inset-0 flex items-center justify-center z-40 bg-black/50 fixed">
{children}
</div>
);
};
54 changes: 54 additions & 0 deletions judy/Week9/cart/src/components/CartItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useCartActions } from "../hooks/useCartStore";
import type { IFCart } from "../types/cart";

interface Props {
item: IFCart;
}

export const CartItem = ({ item }: Props) => {
const { increase, decrease, removeItem } = useCartActions();

const handleIncreaseCount = () => {
increase(item.id);
};
const handleDecreaseCount = () => {
if (item.amount === 1) {
removeItem(item.id);
return;
}
decrease(item.id);
};
return (
<div className="w-full flex justify-between border-b-1 border-neutral-200 pb-5 px-3">
<div className="flex gap-3">
<img src={item.img} alt="앨범 커버" className="w-25 rounded-sm" />

<div className="flex flex-col justify-center">
<div className="font-bold text-lg">{item.title}</div>
<div className="font-semibold text-neutral-500 text-sm">
{item.singer}
</div>
<div className="font-bold text-sm">${item.price}</div>
</div>
</div>

<div className="flex items-center">
<button
className="w-6 h-6 bg-neutral-300 flex items-center justify-center rounded-sm cursor-pointer"
onClick={handleDecreaseCount}
>
-
</button>
<div className="w-8 h-6 flex justify-center items-center rounded-sm border-2 border-neutral-300">
{item.amount}
</div>
<button
className="w-6 h-6 bg-neutral-300 flex items-center justify-center rounded-sm cursor-pointer"
onClick={handleIncreaseCount}
>
+
</button>
</div>
</div>
);
};
23 changes: 23 additions & 0 deletions judy/Week9/cart/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FaShoppingCart } from "react-icons/fa";
import { useEffect } from "react";
import { useCartActions, useCartInfo } from "../hooks/useCartStore";

export const Header = () => {
const { amount, cartItems } = useCartInfo();
const { sumPrice } = useCartActions();
// const { amount, cartItems } = useSelector((state) => state.cart);
// const dispatch = useDispatch();

useEffect(() => {
sumPrice();
}, [cartItems, sumPrice]);
return (
<div className="w-full h-15 bg-black flex justify-between px-5 items-center text-white fixed">
<div className="text-2xl font-bold">JYPLAYLIST</div>
<div className="flex items-center gap-3">
<FaShoppingCart size={20} />
<span>{amount}</span>
</div>
</div>
);
};
36 changes: 36 additions & 0 deletions judy/Week9/cart/src/components/RemoveModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useCartActions } from "../hooks/useCartStore";
import { useDispatch } from "../hooks/useCustomRedux";
import { closeModal } from "../slices/modalSlice";

export const RemoveModal = () => {
const dispatch = useDispatch();
const { clearCart } = useCartActions();

const handleClose = () => {
dispatch(closeModal());
};

const handleRemove = () => {
clearCart();
dispatch(closeModal());
};
return (
<div className="w-60 h-30 bg-white flex flex-col gap-2 justify-center items-center rounded-sm">
<div className="font-bold">정말 삭제하시겠습니까?</div>
<div className="flex gap-8">
<button
className="bg-neutral-300 px-2 py-1 rounded-sm cursor-pointer"
onClick={handleClose}
>
아니요
</button>
<button
className="py-1 px-2 bg-red-600 text-white rounded-sm cursor-pointer"
onClick={handleRemove}
>
</button>
</div>
</div>
);
};
Loading
Loading