From fcb5a42fd9442ab0cf84d1f3331a25d018163acc Mon Sep 17 00:00:00 2001 From: kyzinatra Date: Mon, 11 Nov 2024 23:50:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BF=D1=83=D1=88=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 13 ++- frontend/Dockerfile | 15 +++ frontend/endpoints | 11 -- frontend/src/components/author/index.tsx | 2 - frontend/src/components/book/index.tsx | 27 ++++- .../src/components/create/author/index.tsx | 33 ++++-- frontend/src/components/home/index.tsx | 21 +++- frontend/src/components/user/index.tsx | 104 +++--------------- 8 files changed, 111 insertions(+), 115 deletions(-) create mode 100644 frontend/Dockerfile delete mode 100644 frontend/endpoints diff --git a/docker-compose.yml b/docker-compose.yml index 6d80c5a..5757c02 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,16 @@ services: condition: service_healthy networks: - database - + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + ports: + - "5173:5173" + volumes: + - .:/app + - /app/node_modules + command: npm run dev db: container_name: database hostname: mongodb @@ -41,4 +50,4 @@ volumes: mongo-data: networks: - database: \ No newline at end of file + database: diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..f5a167f --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,15 @@ +FROM node:20 + +WORKDIR /app + +COPY package.json . + +COPY package-lock.json . + +RUN npm install + +COPY . . + +EXPOSE 5173 + +CMD ["npm", "run", "dev"] diff --git a/frontend/endpoints b/frontend/endpoints deleted file mode 100644 index a0a68fb..0000000 --- a/frontend/endpoints +++ /dev/null @@ -1,11 +0,0 @@ -GET /books -GET /authors -GET /users -GET /user/[login] -GET /book/[name] - -POST /auth -login -password - - diff --git a/frontend/src/components/author/index.tsx b/frontend/src/components/author/index.tsx index 998496e..0eac8b8 100644 --- a/frontend/src/components/author/index.tsx +++ b/frontend/src/components/author/index.tsx @@ -28,8 +28,6 @@ export const Author = () => { .then(setAuthor); }, []); - console.log(author, books); - const [user, setUser] = useState(); useEffect(() => { diff --git a/frontend/src/components/book/index.tsx b/frontend/src/components/book/index.tsx index 0ba2a1d..190d646 100644 --- a/frontend/src/components/book/index.tsx +++ b/frontend/src/components/book/index.tsx @@ -27,6 +27,31 @@ export const Book = () => { .then(setUser); }, []); + function handle() { + if (book?.status) { + fetch("http://localhost:8081/return_book/" + book?._id, { + method: "POST", + }).then(() => { + fetch("http://localhost:8081/books/" + l.pathname.split("/").at(-1)) + .then((r) => r.json()) + .then(setBook); + }); + } else { + fetch("http://localhost:8081/take_book/" + book?._id, { + method: "POST", + headers: { + "Content-Type": "application/json;charset=utf-8", + }, + body: JSON.stringify({ + login: user?.login, + }), + }).then(() => { + fetch("http://localhost:8081/books/" + l.pathname.split("/").at(-1)) + .then((r) => r.json()) + .then(setBook); + }); + } + } return ( @@ -78,7 +103,7 @@ export const Book = () => { Описание {book?.description || "Нет описания"} - + ); }; diff --git a/frontend/src/components/create/author/index.tsx b/frontend/src/components/create/author/index.tsx index a182462..197dfc6 100644 --- a/frontend/src/components/create/author/index.tsx +++ b/frontend/src/components/create/author/index.tsx @@ -1,7 +1,11 @@ -import { Button, Flex, Input } from "@chakra-ui/react"; +import { Box, Button, Flex, Group, IconButton, Input } from "@chakra-ui/react"; import { FormEvent, useState } from "react"; import { useNavigate } from "react-router"; import { getCookie } from "../../../utils"; +import { Link } from "react-router-dom"; +import { CiExport } from "react-icons/ci"; +import { FaHome, FaDownload } from "react-icons/fa"; +import { TbLogs } from "react-icons/tb"; export const CreateAuthor = () => { const [name, setName] = useState(""); @@ -29,15 +33,22 @@ export const CreateAuthor = () => { }); } return ( - -
- - setName(e.target.value)} /> - setdescription(e.target.value)} /> - setlink(e.target.value)} /> - - -
-
+ + + +
+ + setName(e.target.value)} /> + setdescription(e.target.value)} + /> + setlink(e.target.value)} /> + + +
+
+
); }; diff --git a/frontend/src/components/home/index.tsx b/frontend/src/components/home/index.tsx index 91ed5fd..a1b9820 100644 --- a/frontend/src/components/home/index.tsx +++ b/frontend/src/components/home/index.tsx @@ -61,9 +61,28 @@ export const Home = () => { - {user?.login} + {user?.login ? ( + + {user?.login} + + ) : ( + + Войти + + )} + + + + + + + Книги, изданные автором diff --git a/frontend/src/components/user/index.tsx b/frontend/src/components/user/index.tsx index 7342fb9..8a9edbe 100644 --- a/frontend/src/components/user/index.tsx +++ b/frontend/src/components/user/index.tsx @@ -15,6 +15,15 @@ export const User = () => { .then((r) => r.json()) .then(setUser); }, []); + + const [avtiv, setavtiv] = useState(); + + useEffect(() => { + fetch("http://localhost:8081/activities") + .then((r) => r.json()) + .then(setavtiv); + }, []); + console.log(avtiv); return ( @@ -56,55 +65,6 @@ export const User = () => { - - Взятые книги - - - - - - - Название - Автор - Жанр - Дата взятия - - - - - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 1 - - - - - История действий @@ -115,47 +75,17 @@ export const User = () => { Название Автор - Жанр - Дата взятия - Дата возврата - - 1 - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 1 - - - - - 1 - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 1 - - - + {avtiv?.map((el: any) => { + return ( + + {el.description} + {el.user_id} + + ); + })}