diff --git a/public/index.html b/public/index.html index aa069f2..c6ded9c 100644 --- a/public/index.html +++ b/public/index.html @@ -5,39 +5,12 @@ - + - - React App -
- diff --git a/src/App.css b/src/App.css deleted file mode 100644 index 74b5e05..0000000 --- a/src/App.css +++ /dev/null @@ -1,38 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/src/App.js b/src/App.js index 3784575..373172a 100644 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,105 @@ -import logo from './logo.svg'; -import './App.css'; - -function App() { - return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
-
- ); +import React, { useState } from "react"; +import Book from './Book' +import BookForm from './BookForm' + + +const API_URL = 'https://shark.ontrack.global'; +//const API_URL = 'http://localhost:8080'; + +const App = ()=> { + + const [books, setBooks] = useState([]); + const [searchedBook, setSearchedBook] = useState(null); + const [searchId, setSearchId] = useState(""); + const [wordReport, setWordReport] = useState(""); + + const searchBooks = async () =>{ + const response = await fetch(`${API_URL}/book/get`,{ + method: 'GET', // *GET, POST, PUT, DELETE, etc. + }) + const data = await response.json(); + setBooks(data) + } + + const searchBook = async (bookId) =>{{ + const response = await fetch(`${API_URL}/book/get/${bookId}`,{ + method: 'GET', // *GET, POST, PUT, DELETE, etc. + }) + const data = await response.json(); + setSearchedBook(data[0]) + }} + + const downloadReport = async(word) => { + const response = await fetch(`${API_URL}/book/report/${word}`,{ + method: 'GET', + }) + const data = await (await response.text()).slice(17); + console.log(data) + window.open(`${API_URL}/book/report/download/${data}`) + //const response2 = await fetch(`${API_URL}/book/report/download/${data}`) + + } + + return ( + <> +
+

Libros

+
+
+

Obtener Todos

+ + + { + books?.length > 0 ? ( +
+ {books.map((book)=> ( + + ))} +
+ ) : ( + <> + ) + } +
+
+

Obtener Libro por Id

+ setSearchId(e.target.value)} + placeholder= "Ingrese el id del libro" + /> + + { + searchedBook !== null ? (): (<>) + } +
+
+

Crear Un Libro

+ +
+
+

Reportes

+

Libros por palabra clave

+ setWordReport(e.target.value)} + placeholder= "Ingrese la palabra clave que desea buscar" + /> +
+ + + +
+ + ) } -export default App; +export default App; \ No newline at end of file diff --git a/src/App.test.js b/src/App.test.js deleted file mode 100644 index 1f03afe..0000000 --- a/src/App.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/src/Book.jsx b/src/Book.jsx new file mode 100644 index 0000000..0b1ac87 --- /dev/null +++ b/src/Book.jsx @@ -0,0 +1,12 @@ +import React from "react"; + +const Book = ({ book}) => { + return ( +
+

Title: {book.Title}

+

Author: {book.Author}, Year Published: {book.PublicationYear}

+
+ ) +} + +export default Book; \ No newline at end of file diff --git a/src/BookForm.jsx b/src/BookForm.jsx new file mode 100644 index 0000000..27c2436 --- /dev/null +++ b/src/BookForm.jsx @@ -0,0 +1,65 @@ +import React from "react"; +import { useState } from "react"; + +const BookForm = () => { + const API_URL = 'https://shark.ontrack.global'; + const [form, setForm] = useState({author: '', title:'', description: '', subject: '', year: ''}); + + const handleChange = (e) =>{ + setForm({ + ...form, + [e.target.name] : e.target.value, + }); + } + + const handleSubmit = (e) =>{ + e.preventDefault() + if (form.title.length > 0 && form.author.length > 0 && form.description.length > 0 && form.subject.length > 0 && form.year.length > 0 && !isNaN(form.year)){ + createBook(form) + setForm({author: '', title:'', description: '', subject: '', year: ''}) + } + } + + const createBook = async (book) => { + const requestOptions = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(book) + }; + console.log(book) + console.log(requestOptions.body) + const response = await fetch(`${API_URL}/book/create`,requestOptions) + const data = await response.text(); + console.log(data) + } + + + return ( +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ ) +} + +export default BookForm; \ No newline at end of file diff --git a/src/index.css b/src/index.css deleted file mode 100644 index ec2585e..0000000 --- a/src/index.css +++ /dev/null @@ -1,13 +0,0 @@ -body { - margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', - sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; -} diff --git a/src/index.js b/src/index.js index d563c0f..26cc2cf 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,10 @@ import React from 'react'; -import ReactDOM from 'react-dom/client'; -import './index.css'; +import { createRoot } from 'react-dom/client'; import App from './App'; -import reportWebVitals from './reportWebVitals'; -const root = ReactDOM.createRoot(document.getElementById('root')); -root.render( - - - -); +const container = document.getElementById('root'); +const root = createRoot(container) +root.render(); -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); + + \ No newline at end of file diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 9dfc1c0..0000000 --- a/src/logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/reportWebVitals.js b/src/reportWebVitals.js deleted file mode 100644 index 5253d3a..0000000 --- a/src/reportWebVitals.js +++ /dev/null @@ -1,13 +0,0 @@ -const reportWebVitals = onPerfEntry => { - if (onPerfEntry && onPerfEntry instanceof Function) { - import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { - getCLS(onPerfEntry); - getFID(onPerfEntry); - getFCP(onPerfEntry); - getLCP(onPerfEntry); - getTTFB(onPerfEntry); - }); - } -}; - -export default reportWebVitals; diff --git a/src/setupTests.js b/src/setupTests.js deleted file mode 100644 index 8f2609b..0000000 --- a/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom';