diff --git a/src/components/CreateUpdatePost.jsx b/src/components/CreateUpdatePost.jsx index c6edcf7..44527cf 100644 --- a/src/components/CreateUpdatePost.jsx +++ b/src/components/CreateUpdatePost.jsx @@ -26,7 +26,7 @@ export default function CreateUpdatePost({ onClose, onSuccess, initialData }) { const [form, setForm] = useState( isEdit ? { - type: initialData.type || "loss", + type: (initialData.type || "loss").toLowerCase(), title: initialData.title || "", description: initialData.description || "", category: initialData.category || "", @@ -100,7 +100,7 @@ export default function CreateUpdatePost({ onClose, onSuccess, initialData }) { } const data = new FormData(); - data.append("type", form.type); + data.append("type", form.type.toUpperCase()); // "loss" → "LOSS", "found" → "FOUND" для enum на бэкенде data.append("title", form.title.trim()); data.append("description", form.description.trim()); data.append("category", form.category); diff --git a/src/components/MainFeed.jsx b/src/components/MainFeed.jsx index 91b29ea..36b8495 100644 --- a/src/components/MainFeed.jsx +++ b/src/components/MainFeed.jsx @@ -38,7 +38,13 @@ export default function MainFeed() { if (!res.ok) throw new Error(`Ошибка ${res.status}`); const data = await res.json(); // API может вернуть массив напрямую или объект { items: [] } - setAds(Array.isArray(data) ? data : (data.items ?? [])); + const ads = Array.isArray(data) ? data : (data.items ?? []); + // Нормализуем type: enum LOSS/FOUND → "loss"/"found" + const normalizedAds = ads.map(ad => ({ + ...ad, + type: ad.type ? ad.type.toLowerCase() : "loss" + })); + setAds(normalizedAds); } catch (err) { setError(err.message || "Не удалось загрузить объявления"); } finally { @@ -66,6 +72,17 @@ export default function MainFeed() { const handleNewAd = useCallback(() => loadFeed(), [loadFeed]); const handleEditSave = useCallback(() => loadFeed(), [loadFeed]); + // Фильтруем объявления в зависимости от выбранной вкладки + const filteredAds = activeNav === "Главная" + ? ads + : ads.filter(ad => + activeNav === "Вещи" + ? ["Вещь", "Другое"].includes(ad.category) + : activeNav === "Питомцы" + ? ad.category === "Питомец" + : false + ); + /** * Рендерит содержимое ленты в зависимости от текущего состояния: * — спиннер во время загрузки @@ -93,7 +110,7 @@ export default function MainFeed() { ); } - if (!ads.length) { + if (!filteredAds.length) { return (
🔍
@@ -104,7 +121,7 @@ export default function MainFeed() {
); } - return ads.map(ad => ( + return filteredAds.map(ad => (