diff --git a/src/locales/en.json b/src/locales/en.json index 084e038..d86ab16 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -564,7 +564,9 @@ "unmute": "Unmute sound" }, "viewer": { - "goToImage": "Go to image {{number}}" + "goToImage": "Go to image {{number}}", + "prevImage": "Previous photo", + "nextImage": "Next photo" }, "chats": { "fetchError": "Failed to load chats", diff --git a/src/locales/ru.json b/src/locales/ru.json index 5cb6e36..2c33805 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -564,7 +564,9 @@ "unmute": "Включить звук" }, "viewer": { - "goToImage": "Перейти к изображению {{number}}" + "goToImage": "Перейти к изображению {{number}}", + "prevImage": "Предыдущее фото", + "nextImage": "Следующее фото" }, "chats": { "fetchError": "Не удалось загрузить чаты", diff --git a/src/pages/PostOnFeed.jsx b/src/pages/PostOnFeed.jsx index a8a1136..65a0462 100644 --- a/src/pages/PostOnFeed.jsx +++ b/src/pages/PostOnFeed.jsx @@ -20,9 +20,12 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen const [showReward, setShowReward] = useState(false); const [descExpanded, setDescExpanded] = useState(false); const [descTruncated, setDescTruncated] = useState(false); + const [imgIndex, setImgIndex] = useState(0); const dateAnchorRef = useRef(null); const rewardAnchorRef = useRef(null); const descRef = useRef(null); + const imgTouchStartRef = useRef(null); + const imgSwipedRef = useRef(false); const { isAuthenticated } = useAuthContext(); const { contactSeller, error: contactError, clearError } = useContactSeller(ad); @@ -46,7 +49,45 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen contactSeller(); }; - const imageUrl = getImageUrl(ad.images?.[0]); + const images = Array.isArray(ad.images) ? ad.images : []; + const hasMultipleImages = images.length > 1; + // Карусель только для карточек ленты (не для компактного вида в детальной + // модалке, где фото показывается целиком и overflow не скрыт). + const carousel = hasMultipleImages && !compact; + + // Листание фото прямо в карточке: на телефоне — свайпом, на десктопе — + // стрелками и точками. Полноэкранный просмотр по-прежнему открывается по клику. + const goToImage = (target) => { + setImgIndex(Math.max(0, Math.min(images.length - 1, target))); + }; + + const handleImgTouchStart = (e) => { + if (!carousel) return; + imgTouchStartRef.current = { x: e.touches[0].clientX, y: e.touches[0].clientY }; + }; + + const handleImgTouchEnd = (e) => { + const start = imgTouchStartRef.current; + imgTouchStartRef.current = null; + if (!start || !carousel) return; + const dx = e.changedTouches[0].clientX - start.x; + const dy = e.changedTouches[0].clientY - start.y; + // Реагируем только на явно горизонтальный жест — вертикальный скролл ленты + // не должен переключать фото. + if (Math.abs(dx) > 40 && Math.abs(dx) > Math.abs(dy)) { + imgSwipedRef.current = true; + setImgIndex(i => Math.max(0, Math.min(images.length - 1, dx < 0 ? i + 1 : i - 1))); + window.setTimeout(() => { imgSwipedRef.current = false; }, 350); + } + }; + + const handleImgAreaClick = (e) => { + e.stopPropagation(); + // После свайпа браузер может дослать click — не открываем просмотр. + if (imgSwipedRef.current) return; + if (onImageClick) onImageClick(images, imgIndex, ad); + }; + const address = ad.address || ad.city || ad.district || ad.location; const createdAt = ad.createdAt ? new Date(ad.createdAt).toLocaleDateString("ru-RU") @@ -92,11 +133,34 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen -