Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarinm committed Jul 6, 2022
1 parent 587b0ea commit 5f1d00b
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 142 deletions.
29 changes: 1 addition & 28 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,12 @@
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<meta name="description" content="Web site created using create-react-app"/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

126 changes: 103 additions & 23 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,105 @@
import logo from './logo.svg';
import './App.css';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
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 (
<>
<div>
<h1>Libros</h1>
</div>
<div>
<h2>Obtener Todos</h2>
<button
onClick={ () => searchBooks()}
>Buscar Todos los Libros</button>
<button
onClick = { () => setBooks([])}
>Limpiar</button>
{
books?.length > 0 ? (
<div>
{books.map((book)=> (
<Book book = {book}/>
))}
</div>
) : (
<></>
)
}
</div>
<div>
<h2>Obtener Libro por Id</h2>
<input
value = {searchId}
onChange = {(e)=> setSearchId(e.target.value)}
placeholder= "Ingrese el id del libro"
/>
<button
onClick = {() => searchBook(searchId)}
>Buscar</button>
{
searchedBook !== null ? (<Book book = {searchedBook}/>): (<></>)
}
</div>
<div>
<h2>Crear Un Libro</h2>
<BookForm />
</div>
<div>
<h2>Reportes</h2>
<h3>Libros por palabra clave</h3>
<input
value = {wordReport}
onChange = {(e)=> setWordReport(e.target.value)}
placeholder= "Ingrese la palabra clave que desea buscar"
/>
<br/>
<button
onClick = {() => downloadReport(wordReport)}
>Generar Reporte</button>


</div>
</>
)
}

export default App;
export default App;
8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/Book.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";

const Book = ({ book}) => {
return (
<div>
<h3>Title: {book.Title}</h3>
<h4>Author: {book.Author}, Year Published: {book.PublicationYear}</h4>
</div>
)
}

export default Book;
65 changes: 65 additions & 0 deletions src/BookForm.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<form onSubmit={handleSubmit}>
<label htmlFor = "title" >Titulo: </label>
<input type = "text" id = "title" name = "title" value = {form.title} onChange= {handleChange}></input>
<br/>
<br/>
<label htmlFor = "author" >Autor: </label>
<input type = "text" id = "author" name = "author" value = {form.author} onChange= {handleChange}></input>
<br/>
<br/>
<label htmlFor = "description" >Descripción: </label>
<input type = "text" id = "description" name = "description" value = {form.description} onChange= {handleChange}></input>
<br/>
<br/>
<label htmlFor = "subject" >Tema: </label>
<input type = "text" id = "subject" name = "subject" value = {form.subject} onChange= {handleChange}></input>
<br/>
<br/>
<label htmlFor = "year" >Año de Publicación: </label>
<input type = "text" id = "year" name = "year" value = {form.year} onChange= {handleChange}></input>
<br/>
<input type = "submit"></input>
</form>
)
}

export default BookForm;
13 changes: 0 additions & 13 deletions src/index.css

This file was deleted.

19 changes: 6 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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(
<React.StrictMode>
<App />
</React.StrictMode>
);
const container = document.getElementById('root');
const root = createRoot(container)
root.render(<App/>);

// 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();


1 change: 0 additions & 1 deletion src/logo.svg

This file was deleted.

13 changes: 0 additions & 13 deletions src/reportWebVitals.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/setupTests.js

This file was deleted.

0 comments on commit 5f1d00b

Please sign in to comment.