Skip to content

Commit

Permalink
[DELETE] toolbar and buttoms components
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanner Enrique De La Hoz Barraza committed Apr 30, 2023
1 parent e91ffc5 commit 0b249c5
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 72 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.4.0",
"axios": "^1.4.0",
"bootstrap": "^5.2.3",
"react": "^18.2.0",
"react-bootstrap": "^2.7.4",
Expand Down
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Routes, Route, BrowserRouter} from "react-router-dom";

import Navbar from "./components/Navbar/Navbar";
import Home from "./components/Home/Home";
import Editorial from "./components/Editorial/Editorial";
import Footer from "./components/Footer/Footer";

function App() {
Expand All @@ -11,6 +12,7 @@ function App() {
<Navbar />
<Routes>
<Route path="/" element={<Home />}></Route>
<Route path="/editorial" element={<Editorial />}></Route>
</Routes>
<Footer />
</div>
Expand Down
31 changes: 31 additions & 0 deletions src/components/API/EditorialAPI.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {useState, useEffect} from "react";

export function getEditorials() {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
setLoading(true);
fetch(`http://localhost:4444/api/v1/book-reserve/editorials`)
.then((response) => response.json())
.then((data) => setData(data))
.catch((error) => setError(error.message))
.finally(() => setLoading(false));
}, []);
return {data, loading, error};
}

export function getEditorialById(editorialId) {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
setLoading(true);
fetch(`http://localhost:4444/api/v1/book-reserve/editorials/${editorialId}`)
.then((response) => response.json())
.then((data) => setData(data))
.catch((error) => setError(error.message))
.finally(() => setLoading(false));
}, []);
return {data, loading, error};
}
9 changes: 0 additions & 9 deletions src/components/Button/ButtonToAdd.jsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/Button/ButtonToDelete.jsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/Button/ButtonToUpdate.jsx

This file was deleted.

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

import Error from "../Handle/Error";
import Loading from "../Handle/Loading";
import {getEditorials} from "../API/EditorialAPI";

export default function Editorial() {
const {data, loading, error} = getEditorials();
return (
<>
{/* start-toolbar */}
<div className="row">
<div className="col-12 mb-4 text-center">
<button className="btn btn-dark">
<i className="fa-solid fa-circle-plus"></i> Añadir
</button>
</div>
</div>
{/* end-toolbar */}
{/* start-content */}
<div className="row">
{error && <Error message={error} />}
{loading && <Loading />}
{data?.map((result, index) => (
<div className="col-md-4 mb-4" key={result.editorial_id}>
<div className="card">
{/* <img src={result.image} className="card-img-top" alt={result.editorial_name} /> */}
<div className="card-body">
<h5 className="card-title">{result.editorial_name}</h5>
<p className="card-text">{result.editorial_description}</p>
<button className="btn btn-warning">
<i className="fa-solid fa-edit"></i>
</button>
&nbsp;
<button className="btn btn-danger">
<i className="fa-solid fa-trash"></i>
</button>
</div>
</div>
</div>
))}
</div>
{/* end-content */}
</>
);
}
33 changes: 19 additions & 14 deletions src/components/Home/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React, {useState} from "react";

import Toolbar from "../Toolbar/Toolbar";
import ButtonToUpdate from "../Button/ButtonToUpdate";
import ButtonToDelete from "../Button/ButtonToDelete";
import React from "react";
import {useFetch} from "../../useFetch";

import Error from "../Handle/Error";
import Loading from "../Handle/Loading";

import {useFetch} from "../../useFetch";
import MyVerticallyCenteredModal from "../Modal/Modal";

export default function Home() {
const {data, loading, error} = useFetch("https://rickandmortyapi.com/api/character");
const [modalIsOpen, setModalIsOpen] = useState(false);
return (
<>
<Toolbar />
{/* start-toolbar */}
<div className="row">
<div className="col-12 mb-4 text-center">
<button className="btn btn-dark">
<i className="fa-solid fa-circle-plus"></i> Añadir
</button>
</div>
</div>
{/* end-toolbar */}
{/* start-content */}
<div className="row">
{error && <Error message={error} />}
{loading && <Loading />}
Expand All @@ -28,16 +30,19 @@ export default function Home() {
<p className="card-text">
{character.status}, {character.species}, {character.gender}
</p>
<ButtonToUpdate />
<button className="btn btn-warning">
<i className="fa-solid fa-edit"></i>
</button>
&nbsp;
<ButtonToDelete />
<button className="btn btn-danger">
<i className="fa-solid fa-trash"></i>
</button>
</div>
</div>
</div>
))}
</div>

<MyVerticallyCenteredModal show={modalIsOpen} onHide={() => setModalIsOpen(false)} />
{/* end-content */}
</>
);
}
39 changes: 23 additions & 16 deletions src/components/Modal/Modal.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import Button from "react-bootstrap/Button";
import Modal from "react-bootstrap/Modal";
import React from "react";

export default function MyVerticallyCenteredModal(props) {
export default function Modal({id, title, textbtn, body, submit}) {
return (
<Modal {...props} size="lg" aria-labelledby="contained-modal-title-vcenter" centered>
<Modal.Header closeButton>
<Modal.Title id="contained-modal-title-vcenter">Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body>
<h4>Centered Modal</h4>
<p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary">Cerrar</Button>
<Button variant="primary">Guardar</Button>
</Modal.Footer>
</Modal>
<div className="modal fade" id={id}>
<div className="modal-dialog modal-dialog-centered">
<div className="modal-content">
<div className="modal-header">
<h4 className="modal-title">{title}</h4>
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form onSubmit={submit}>
<div className="modal-body">{body}</div>
<div className="modal-footer">
<button type="button" className="btn secondary btn-sm px-4" data-bs-dismiss="modal">
Cerrar
</button>
<button type="submit" className="btn primary btn-sm px-4">
{textbtn}
</button>
</div>
</form>
</div>
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion src/components/Navbar/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function Navbar() {
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">
<a className="nav-link" href="/editorial">
Editorial
</a>
</li>
Expand Down
14 changes: 0 additions & 14 deletions src/components/Toolbar/Toolbar.jsx

This file was deleted.

0 comments on commit 0b249c5

Please sign in to comment.