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>
33 changes: 33 additions & 0 deletions new8-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"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",
"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.
92 changes: 92 additions & 0 deletions new8-1/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* .todo-app {
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);
flex-direction: column;
}

.todo-form {
display: flex;
gap: 10px;
margin-bottom: 20px;
flex-direction: column;
}

.todo-input {
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
}

.todo-button {
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

.todo-button:hover {
background-color: #45a049;
}

.todo-list {
display: flex;
flex-direction: column;
gap: 15px;
}

.todo-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: white;
}

.todo-text {
display: flex;
gap: 5px;
}

.todo-edit {
display: flex;
gap: 5px;
}

.edit-input {
padding: 5px;
font-size: 16px;
}

.botton-box {
display: flex;
justify-content: flex-end; /* 오른쪽 정렬 */
flex-grow: 1; /* 부모 컨테이너 내에서 오른쪽으로 밀림 */
}

.delete-button,
.edit-button,
.update-button {
background-color: #f44336;
color: white;
border: none;
border-radius: 7px;
cursor: pointer;
padding: 5px 10px;
margin-right: 5px;
}

.delete-button:hover,
.edit-button:hover,
.update-button:hover {
background-color: #d32f2f;
} */
136 changes: 136 additions & 0 deletions new8-1/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { useState } from "react";
import "./App.css";
import { useMutation, useQuery } from "@tanstack/react-query";
import { getTodoList, postTodo, deleteTodo, patchTodo } from "./api/todo";
import styled from "styled-components";
import { queryClient } from "./main";

function App() {
const [title, setTitle] = useState("");
const [content, setContent] = useState("");
const [search, setSearch] = useState("");
const [checked, setChecked] = useState(false);

const { data: todos, isPending } = useQuery({
queryFn: () => getTodoList({ title: search }),
queryKey: ["todos", search],
});

const { mutate: postTodoMutation } = useMutation({
mutationFn: postTodo,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ["todos"],
});
},
onError: (error) => {
console.log(error);
},
});

const { mutate: patchTodoMutation } = useMutation({
mutationFn: patchTodo,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ["todos"],
});
},
onError: (error) => {
console.log(error);
},
});

const { mutate: deleteTodoMutation } = useMutation({
mutationFn: deleteTodo,
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ["todos"],
});
},
});

const handleSubmit = (e) => {
e.preventDefault();
console.log("제목:", title, "내용:", content);
postTodoMutation({ title, content });
};

return (
<>
<h1>투두 검색</h1>
<Input value={search} onChange={(e) => setSearch(e.target.value)} />
<Form onSubmit={handleSubmit}>
<Input
name="title"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="제목을 입력하세요"
/>
<Input
name="content"
value={content}
onChange={(e) => setContent(e.target.value)}
placeholder="내용을 입력하세요"
/>
<Button onClick={handleSubmit}>할 일 등록</Button>
</Form>
{isPending ? (
<div>로딩중입니다.</div>
) : (
<Container>
{todos[0]?.map((todo) => {
return (
<TodoContainer key={todo.id}>
<input
type="checkbox"
defaultChecked={todo.checked}
onChange={(e) =>
patchTodoMutation({ id: todo.id, checked: !todo.checked })
}
/>
<div>
<p>{todo.title}</p>
<p>{todo.content}</p>
</div>
<Button onClick={() => deleteTodoMutation({ id: todo.id })}>
삭제하기
</Button>
</TodoContainer>
);
})}
</Container>
)}
</>
);
}

export default App;

const Form = styled.div`
display: flex;
flex-direction: column;
gap: 20px;
`;

const Input = styled.input`
padding: 10px;
border: 1px solid purple;
border-radius: 20px;
`;

const Button = styled.button`
border-radius: 10px;
border: none;
padding: 20px;
`;

const Container = styled.div`
display: flex;
flex-direction: column;
gap: 20px;
`;

const TodoContainer = styled.div`
display: flex;
gap: 20px;
`;
Loading