non je veux que quand je sélectionne une ville sur le Tableau D'annonce il y est uniquement les annonces de la ville en question - Follow Up Deployment
Browse files- index.html +45 -23
index.html
CHANGED
|
@@ -79,7 +79,7 @@
|
|
| 79 |
register: async (name, email, password, city) => {
|
| 80 |
return { success: true, user: { id: 2, name, email, city } };
|
| 81 |
},
|
| 82 |
-
getAds: async (
|
| 83 |
return [
|
| 84 |
{
|
| 85 |
id: 1,
|
|
@@ -119,7 +119,7 @@
|
|
| 119 |
comments: [],
|
| 120 |
color: "blue"
|
| 121 |
}
|
| 122 |
-
]
|
| 123 |
},
|
| 124 |
createAd: async (adData) => {
|
| 125 |
return {
|
|
@@ -148,16 +148,16 @@
|
|
| 148 |
const [showLogin, setShowLogin] = useState(false);
|
| 149 |
const [showRegister, setShowRegister] = useState(false);
|
| 150 |
const [showAdForm, setShowAdForm] = useState(false);
|
| 151 |
-
const [cities] = useState(["Maurepas", "Elancourt", "Trappes", "Montigny", "Guyancourt"]);
|
| 152 |
|
| 153 |
useEffect(() => {
|
| 154 |
-
// Simulate loading
|
| 155 |
const loadAds = async () => {
|
| 156 |
-
const data = await mockApi.getAds(
|
| 157 |
setAds(data);
|
| 158 |
};
|
| 159 |
loadAds();
|
| 160 |
-
}, [
|
| 161 |
|
| 162 |
const handleLogin = async (email, password) => {
|
| 163 |
const result = await mockApi.login(email, password);
|
|
@@ -176,15 +176,21 @@
|
|
| 176 |
}
|
| 177 |
};
|
| 178 |
|
| 179 |
-
const handleCreateAd = async (title, description, phone, color, price, photo) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
const result = await mockApi.createAd({
|
| 181 |
title,
|
| 182 |
description,
|
| 183 |
phone,
|
| 184 |
-
city:
|
| 185 |
author: user.name,
|
| 186 |
color,
|
| 187 |
-
price: price
|
| 188 |
photo: photo ? URL.createObjectURL(photo) : null
|
| 189 |
});
|
| 190 |
if (result.success) {
|
|
@@ -269,18 +275,21 @@
|
|
| 269 |
{/* Main content */}
|
| 270 |
<main className="cork-board">
|
| 271 |
<div className="container mx-auto px-4 pt-4 pb-8">
|
| 272 |
-
<
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
| 284 |
</div>
|
| 285 |
</div>
|
| 286 |
</main>
|
|
@@ -313,6 +322,8 @@
|
|
| 313 |
<AdFormModal
|
| 314 |
onClose={() => setShowAdForm(false)}
|
| 315 |
onCreateAd={handleCreateAd}
|
|
|
|
|
|
|
| 316 |
/>
|
| 317 |
)}
|
| 318 |
</div>
|
|
@@ -580,10 +591,11 @@
|
|
| 580 |
);
|
| 581 |
};
|
| 582 |
|
| 583 |
-
const AdFormModal = ({ onClose, onCreateAd }) => {
|
| 584 |
const [title, setTitle] = useState("");
|
| 585 |
const [description, setDescription] = useState("");
|
| 586 |
const [phone, setPhone] = useState("");
|
|
|
|
| 587 |
const [color, setColor] = useState("yellow");
|
| 588 |
const [price, setPrice] = useState(null);
|
| 589 |
const [photo, setPhoto] = useState(null);
|
|
@@ -632,6 +644,16 @@
|
|
| 632 |
/>
|
| 633 |
</div>
|
| 634 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 635 |
<div>
|
| 636 |
<label className="block text-sm font-medium text-gray-700 mb-1">Photo</label>
|
| 637 |
<input
|
|
@@ -719,7 +741,7 @@
|
|
| 719 |
|
| 720 |
<div className="flex justify-end pt-4">
|
| 721 |
<button
|
| 722 |
-
onClick={() => onCreateAd(title, description, phone, color, price, photo)}
|
| 723 |
className="bg-amber-600 text-white px-4 py-2 rounded-md hover:bg-amber-500"
|
| 724 |
>
|
| 725 |
Publier
|
|
|
|
| 79 |
register: async (name, email, password, city) => {
|
| 80 |
return { success: true, user: { id: 2, name, email, city } };
|
| 81 |
},
|
| 82 |
+
getAds: async () => {
|
| 83 |
return [
|
| 84 |
{
|
| 85 |
id: 1,
|
|
|
|
| 119 |
comments: [],
|
| 120 |
color: "blue"
|
| 121 |
}
|
| 122 |
+
];
|
| 123 |
},
|
| 124 |
createAd: async (adData) => {
|
| 125 |
return {
|
|
|
|
| 148 |
const [showLogin, setShowLogin] = useState(false);
|
| 149 |
const [showRegister, setShowRegister] = useState(false);
|
| 150 |
const [showAdForm, setShowAdForm] = useState(false);
|
| 151 |
+
const [cities, setCities] = useState(["Maurepas", "Elancourt", "Trappes", "Montigny", "Guyancourt"]);
|
| 152 |
|
| 153 |
useEffect(() => {
|
| 154 |
+
// Simulate loading all ads
|
| 155 |
const loadAds = async () => {
|
| 156 |
+
const data = await mockApi.getAds();
|
| 157 |
setAds(data);
|
| 158 |
};
|
| 159 |
loadAds();
|
| 160 |
+
}, []);
|
| 161 |
|
| 162 |
const handleLogin = async (email, password) => {
|
| 163 |
const result = await mockApi.login(email, password);
|
|
|
|
| 176 |
}
|
| 177 |
};
|
| 178 |
|
| 179 |
+
const handleCreateAd = async (title, description, phone, city, color, price, photo) => {
|
| 180 |
+
// Ajouter la nouvelle ville si elle n'existe pas déjà
|
| 181 |
+
const newCity = city.trim();
|
| 182 |
+
if (newCity && !cities.includes(newCity)) {
|
| 183 |
+
setCities([...cities, newCity]);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
const result = await mockApi.createAd({
|
| 187 |
title,
|
| 188 |
description,
|
| 189 |
phone,
|
| 190 |
+
city: newCity,
|
| 191 |
author: user.name,
|
| 192 |
color,
|
| 193 |
+
price: price === "" ? null : Number(price),
|
| 194 |
photo: photo ? URL.createObjectURL(photo) : null
|
| 195 |
});
|
| 196 |
if (result.success) {
|
|
|
|
| 275 |
{/* Main content */}
|
| 276 |
<main className="cork-board">
|
| 277 |
<div className="container mx-auto px-4 pt-4 pb-8">
|
| 278 |
+
<div className="mb-8">
|
| 279 |
+
<h2 className="text-xl font-semibold mb-4 text-amber-900">Annonces - {selectedCity}</h2>
|
| 280 |
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
| 281 |
+
{ads
|
| 282 |
+
.filter(ad => ad.city === selectedCity)
|
| 283 |
+
.map(ad => (
|
| 284 |
+
<PostIt
|
| 285 |
+
key={ad.id}
|
| 286 |
+
ad={ad}
|
| 287 |
+
onLike={handleLike}
|
| 288 |
+
onAddComment={handleAddComment}
|
| 289 |
+
isLoggedIn={!!user}
|
| 290 |
+
/>
|
| 291 |
+
))}
|
| 292 |
+
</div>
|
| 293 |
</div>
|
| 294 |
</div>
|
| 295 |
</main>
|
|
|
|
| 322 |
<AdFormModal
|
| 323 |
onClose={() => setShowAdForm(false)}
|
| 324 |
onCreateAd={handleCreateAd}
|
| 325 |
+
cities={cities}
|
| 326 |
+
selectedCity={selectedCity}
|
| 327 |
/>
|
| 328 |
)}
|
| 329 |
</div>
|
|
|
|
| 591 |
);
|
| 592 |
};
|
| 593 |
|
| 594 |
+
const AdFormModal = ({ onClose, onCreateAd, cities, selectedCity }) => {
|
| 595 |
const [title, setTitle] = useState("");
|
| 596 |
const [description, setDescription] = useState("");
|
| 597 |
const [phone, setPhone] = useState("");
|
| 598 |
+
const [city, setCity] = useState("");
|
| 599 |
const [color, setColor] = useState("yellow");
|
| 600 |
const [price, setPrice] = useState(null);
|
| 601 |
const [photo, setPhoto] = useState(null);
|
|
|
|
| 644 |
/>
|
| 645 |
</div>
|
| 646 |
|
| 647 |
+
<div>
|
| 648 |
+
<label className="block text-sm font-medium text-gray-700 mb-1">Ville</label>
|
| 649 |
+
<input
|
| 650 |
+
type="text"
|
| 651 |
+
value={city}
|
| 652 |
+
onChange={(e) => setCity(e.target.value)}
|
| 653 |
+
className="w-full px-3 py-2 border rounded-md"
|
| 654 |
+
/>
|
| 655 |
+
</div>
|
| 656 |
+
|
| 657 |
<div>
|
| 658 |
<label className="block text-sm font-medium text-gray-700 mb-1">Photo</label>
|
| 659 |
<input
|
|
|
|
| 741 |
|
| 742 |
<div className="flex justify-end pt-4">
|
| 743 |
<button
|
| 744 |
+
onClick={() => onCreateAd(title, description, phone, city, color, price, photo)}
|
| 745 |
className="bg-amber-600 text-white px-4 py-2 rounded-md hover:bg-amber-500"
|
| 746 |
>
|
| 747 |
Publier
|