añadido que elimine coords
This commit is contained in:
@@ -5,14 +5,31 @@ import ShareIcon from "./ShareIcon";
|
||||
import RemoveIcon from "./RemoveIcon";
|
||||
import StaticModal from "./StaticModal";
|
||||
|
||||
function Modall({ show, CloseModal, Coord, Coords, EliminarCoord, tipo }) {
|
||||
if (show === true && Coord !== null) {
|
||||
return (
|
||||
<StaticModal
|
||||
CloseModal={CloseModal}
|
||||
Coord={Coord}
|
||||
EliminarCoord={() => {
|
||||
const nuevasCoords = Coords.filter((c) => c !== Coord);
|
||||
localStorage.setItem(tipo, JSON.stringify(nuevasCoords));
|
||||
EliminarCoord(nuevasCoords);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function Keeper({ tipo }) {
|
||||
const [coords, setCoords] = useState(
|
||||
JSON.parse(localStorage.getItem(tipo) || "[]"),
|
||||
);
|
||||
const collapseRef = useRef(null);
|
||||
const [showModal, setModal] = useState(false);
|
||||
|
||||
console.log(coords);
|
||||
//const [showShareToast, setShowShareToast] = useState(false);
|
||||
const [selCoord, setCoord] = useState(null);
|
||||
useEffect(() => {
|
||||
const storedCoords = JSON.parse(localStorage.getItem(tipo) || "[]");
|
||||
|
||||
@@ -30,7 +47,8 @@ export default function Keeper({ tipo }) {
|
||||
//wip
|
||||
};
|
||||
|
||||
const Remover = () => {
|
||||
const Remover = (coord) => {
|
||||
setCoord(coord);
|
||||
setModal(true);
|
||||
};
|
||||
const collapseAccordion = () => {
|
||||
@@ -43,7 +61,14 @@ export default function Keeper({ tipo }) {
|
||||
};
|
||||
return (
|
||||
<>
|
||||
{showModal && <StaticModal />}
|
||||
<Modall
|
||||
show={showModal}
|
||||
CloseModal={() => setModal(false)}
|
||||
Coord={selCoord}
|
||||
Coords={coords}
|
||||
EliminarCoord={setCoords}
|
||||
tipo={tipo}
|
||||
/>
|
||||
<div className="accordion" id="accordionNuevaCoord">
|
||||
<div className="accordion-item">
|
||||
<h2 className="accordion-header" id="headingNuevaCoord">
|
||||
@@ -100,7 +125,7 @@ export default function Keeper({ tipo }) {
|
||||
coords.map((x) => (
|
||||
<tr>
|
||||
<td>
|
||||
<b>#{x.num}:</b>
|
||||
<b>{x.num}</b>
|
||||
</td>
|
||||
|
||||
<td>{x.x}</td>
|
||||
@@ -121,7 +146,7 @@ export default function Keeper({ tipo }) {
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm btn-outline-danger ms-2"
|
||||
onClick={() => Remover()}
|
||||
onClick={() => Remover(x)}
|
||||
>
|
||||
<RemoveIcon />
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user