Primer prototipo
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import MapView from "./components/MapView.jsx";
|
||||
import Sidebar from "./components/Sidebar.jsx";
|
||||
import SubmitForm from "./components/SubmitForm.jsx";
|
||||
import { getApproved, submit } from "./services/businessRepository.js";
|
||||
|
||||
export default function App() {
|
||||
const [businesses, setBusinesses] = useState([]);
|
||||
const [selectedId, setSelectedId] = useState(null);
|
||||
const [formOpen, setFormOpen] = useState(false);
|
||||
const [pickedLocation, setPickedLocation] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
setBusinesses(getApproved());
|
||||
}, []);
|
||||
|
||||
const selected = businesses.find((b) => b.id === selectedId) || null;
|
||||
|
||||
function handleSubmit(data) {
|
||||
submit(data);
|
||||
setFormOpen(false);
|
||||
setPickedLocation(null);
|
||||
alert("¡Gracias! Tu propuesta queda pendiente de revisión.");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<Sidebar
|
||||
business={selected}
|
||||
onContribute={() => setFormOpen(true)}
|
||||
onClose={() => setSelectedId(null)}
|
||||
/>
|
||||
<MapView
|
||||
businesses={businesses}
|
||||
selectedId={selectedId}
|
||||
onSelect={setSelectedId}
|
||||
pickingLocation={formOpen}
|
||||
onPickLocation={setPickedLocation}
|
||||
pickedLocation={pickedLocation}
|
||||
/>
|
||||
{formOpen && (
|
||||
<SubmitForm
|
||||
pickedLocation={pickedLocation}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => {
|
||||
setFormOpen(false);
|
||||
setPickedLocation(null);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user