Skip to content
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 new8-1/.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 new8-1/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 new8-1/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 },
],
},
},
]
13 changes: 13 additions & 0 deletions new8-1/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>Hello React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions new8-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "save",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.60.5",
"@tanstack/react-query-devtools": "^5.60.5",
"axios": "^1.7.7",
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-component": "^2.8.0",
"styled-components": "^6.1.13"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^9.9.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"vite": "^5.4.1"
}
}
1 change: 1 addition & 0 deletions new8-1/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 new8-1/src/App.css
Empty file.
159 changes: 159 additions & 0 deletions new8-1/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import React, { useState } from "react";
import { useQuery, useMutation } from "@tanstack/react-query";
import { getTodoList, postTodo, patchTodo, deleteTodo } from "./api/todo";
import styled from "styled-components";
import { queryClient } from "./main";

function App() {
const [title, setTitle] = useState("");
const [content, setContent] = useState("");

// Todo 목록 불러오기
const { data: todos, isLoading } = useQuery({
queryKey: ["todos"],
queryFn: getTodoList,
});

// Todo 생성
const { mutate: createTodo } = useMutation(postTodo, {
onSuccess: () => {
queryClient.invalidateQueries(["todos"]);
setTitle("");
setContent("");
},
});

// Todo 수정
const { mutate: updateTodo } = useMutation(patchTodo, {
onSuccess: () => {
queryClient.invalidateQueries(["todos"]);
},
});

// Todo 삭제
const { mutate: removeTodo } = useMutation(deleteTodo, {
onSuccess: () => {
queryClient.invalidateQueries(["todos"]);
},
});

const handleSubmit = (e) => {
e.preventDefault();
if (title && content) {
createTodo({ title, content });
}
};

return (
<Wrapper>
<Header>⚡ UMC ToDoList ⚡</Header>
<Form onSubmit={handleSubmit}>
<Input
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="제목을 입력해주세요"
/>
<Input
value={content}
onChange={(e) => setContent(e.target.value)}
placeholder="내용을 입력해주세요"
/>
<Button type="submit">ToDo 생성</Button>
</Form>
{isLoading ? (
<div>로딩중입니다...</div>
) : (
<TodoList>
{todos?.map((todo) => (
<TodoItem key={todo.id}>
<Checkbox
type="checkbox"
checked={todo.checked}
onChange={() =>
updateTodo({ id: todo.id, checked: !todo.checked })
}
/>
<TextWrapper>
<Title>{todo.title}</Title>
<Content>{todo.content}</Content>
</TextWrapper>
<Button onClick={() => updateTodo({ id: todo.id })}>수정</Button>
<Button onClick={() => removeTodo({ id: todo.id })}>삭제</Button>
</TodoItem>
))}
</TodoList>
)}
</Wrapper>
);
}

export default App;

const Wrapper = styled.div`
max-width: 500px;
margin: 50px auto;
font-family: Arial, sans-serif;
`;

const Header = styled.h1`
text-align: center;
margin-bottom: 20px;
`;

const Form = styled.form`
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 20px;
`;

const Input = styled.input`
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
`;

const Button = styled.button`
padding: 10px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
cursor: pointer;

&:hover {
background-color: #0056b3;
}
`;

const TodoList = styled.div`
display: flex;
flex-direction: column;
gap: 10px;
`;

const TodoItem = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
`;

const Checkbox = styled.input`
margin-right: 10px;
`;

const TextWrapper = styled.div`
flex-grow: 1;
`;

const Title = styled.p`
font-weight: bold;
margin: 0;
`;

const Content = styled.p`
margin: 0;
`;
104 changes: 104 additions & 0 deletions new8-1/src/AppStyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import styled from "styled-components";

const container = styled.div`
padding: 20px;
max-width: 600px;
margin: 0 auto;
background-color: #f9f9f9;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
`;

const todoForm = styled.div`
display: flex;
gap: 10px;
margin-bottom: 20px;
flex-direction: column;
`;

const todoInput = styled.div`
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
`;

const todoButton = styled.div`
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;

&:hover {
background-color: #45a049;
}
`;

const todoList = styled.div`
display: flex;
flex-direction: column;
gap: 15px;
padding-top: 40px;
`;

const TodoItem = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: white;
`;

const Text = styled.div`
display: flex;
gap: 5px;
`;

const TodoEdit = styled.div`
display: flex;
gap: 5px;
`;

const EditInput = styled.input`
padding: 5px;
font-size: 16px;
`;

const ButtonBox = styled.div`
display: flex;
justify-content: flex-end; /* 오른쪽 정렬 */
flex-grow: 1; /* 부모 컨테이너 내에서 오른쪽으로 밀림 */
`;

const Button = styled.button`
background-color: #f44336;
color: white;
border: none;
border-radius: 7px;
cursor: pointer;
padding: 5px 10px;
margin-right: 5px;

&:hover {
background-color: #d32f2f;
}
`;

export {
container,
todoButton,
todoInput,
todoList,
todoForm,
TodoEdit,
Button,
ButtonBox,
EditInput,
Text,
TodoItem,
};
7 changes: 7 additions & 0 deletions new8-1/src/api/axiosInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import axios from "axios";

const axiosInstance = axios.create({
baseURL: "http://localhost:3000",
});

export default axiosInstance;
Loading