Fix: Reemplazo y Limpieza de Archivos Img de Avisos.
This commit is contained in:
@@ -38,6 +38,7 @@ export default function FormularioAviso({
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [photos, setPhotos] = useState<PhotoSource[]>([]);
|
||||
const [deletedPhotoIds, setDeletedPhotoIds] = useState<number[]>([]);
|
||||
const navigate = useNavigate();
|
||||
|
||||
// Estados Maestros
|
||||
@@ -490,6 +491,16 @@ export default function FormularioAviso({
|
||||
|
||||
if (adId) {
|
||||
await AdsV2Service.update(adId, adPayload);
|
||||
|
||||
// 1. Eliminar fotos que el usuario quitó
|
||||
if (deletedPhotoIds.length > 0) {
|
||||
for (const photoId of deletedPhotoIds) {
|
||||
await AdsV2Service.deletePhoto(photoId);
|
||||
}
|
||||
setDeletedPhotoIds([]); // Limpiar después de borrar
|
||||
}
|
||||
|
||||
// 2. Subir fotos nuevas
|
||||
if (newPhotos.length > 0) {
|
||||
await AdsV2Service.uploadPhotos(adId, newPhotos);
|
||||
}
|
||||
@@ -1251,9 +1262,13 @@ export default function FormularioAviso({
|
||||
<div className="absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center backdrop-blur-[2px]">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
setPhotos(photos.filter((_, i) => i !== idx))
|
||||
}
|
||||
onClick={() => {
|
||||
const photoToDelete = photos[idx];
|
||||
if (!(photoToDelete instanceof File) && photoToDelete.id) {
|
||||
setDeletedPhotoIds((prev) => [...prev, photoToDelete.id]);
|
||||
}
|
||||
setPhotos(photos.filter((_, i) => i !== idx));
|
||||
}}
|
||||
className="w-10 h-10 bg-red-500/20 hover:bg-red-500 text-red-200 hover:text-white rounded-full flex items-center justify-center transition-all border border-red-500/50"
|
||||
title="Eliminar foto"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user