added carousel image on post on mainFeed
This commit is contained in:
@@ -14,7 +14,7 @@ import RewardPopup from "../components/feed/RewardPopup";
|
||||
import Toast from "../components/Toast";
|
||||
import {useTranslation} from 'react-i18next';
|
||||
|
||||
export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen, isOwner, authorLabel, allowEditClosed, onImageClick, onLocationClick, onAuthRequired, compact }) {
|
||||
export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen, isOwner, authorLabel, allowEditClosed, onLocationClick, onAuthRequired, compact }) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [showCalendar, setShowCalendar] = useState(false);
|
||||
const [showReward, setShowReward] = useState(false);
|
||||
@@ -25,7 +25,6 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
|
||||
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);
|
||||
|
||||
@@ -50,15 +49,17 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
|
||||
};
|
||||
|
||||
const images = Array.isArray(ad.images) ? ad.images : [];
|
||||
const hasMultipleImages = images.length > 1;
|
||||
// Карусель только для карточек ленты (не для компактного вида в детальной
|
||||
// модалке, где фото показывается целиком и overflow не скрыт).
|
||||
const carousel = hasMultipleImages && !compact;
|
||||
// Карусель включается для любого объявления с несколькими фото: листать
|
||||
// можно и в ленте, и в детальной модалке. Полноэкранного просмотрщика нет.
|
||||
const carousel = images.length > 1;
|
||||
|
||||
// Листание фото прямо в карточке: на телефоне — свайпом, на десктопе —
|
||||
// стрелками и точками. Полноэкранный просмотр по-прежнему открывается по клику.
|
||||
// стрелками и точками. Листание зациклено: с последнего кадра переходим на
|
||||
// первый и наоборот.
|
||||
const goToImage = (target) => {
|
||||
setImgIndex(Math.max(0, Math.min(images.length - 1, target)));
|
||||
const len = images.length;
|
||||
if (!len) return;
|
||||
setImgIndex(((target % len) + len) % len);
|
||||
};
|
||||
|
||||
const handleImgTouchStart = (e) => {
|
||||
@@ -75,19 +76,12 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
|
||||
// Реагируем только на явно горизонтальный жест — вертикальный скролл ленты
|
||||
// не должен переключать фото.
|
||||
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 len = images.length;
|
||||
const step = dx < 0 ? 1 : -1;
|
||||
setImgIndex(i => (i + step + len) % len);
|
||||
}
|
||||
};
|
||||
|
||||
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")
|
||||
@@ -135,7 +129,6 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
|
||||
|
||||
<div
|
||||
className={`f-card-img${carousel ? " f-card-img-multi" : ""}`}
|
||||
onClick={handleImgAreaClick}
|
||||
onTouchStart={handleImgTouchStart}
|
||||
onTouchEnd={handleImgTouchEnd}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user