added carousel image on post on mainFeed

This commit is contained in:
SlimusMinus
2026-10-09 01:21:14 +03:00
parent 55c71e664d
commit b924483231
12 changed files with 29 additions and 205 deletions

View File

@@ -7,7 +7,6 @@ import Sidebar from "../components/Sidebar";
import BottomNav from "../components/nav/BottomNav";
import RightSidebar from "../components/RightSidebar";
import CreateUpdatePostLegacy from "./CreateUpdatePost";
import ImageViewer from "../components/ImageViewer";
import CityFilterLegacy from "../components/CityFilter";
import { ProfileModal } from "../components/profile";
import AuthModal from "../components/AuthModal";
@@ -240,10 +239,6 @@ export default function MainFeed() {
activeNav === "home" && selectedCities.length === 0 && feed.hasMore && !feed.loading && !feed.loadingMore
);
const handleImageClick = useCallback((images: string[], index: number, ad: Record<string, unknown>) => {
if (images?.length) modals.open("viewer", { images, index, ad });
}, [modals]);
const handleCreatePost = useCallback(() => {
if (!isAuthenticated) modals.open("auth");
else modals.open("create");
@@ -491,7 +486,6 @@ export default function MainFeed() {
onDelete={actions.handleDelete}
onMarkFound={actions.handleMarkFound}
onReopen={actions.handleReopen}
onImageClick={handleImageClick}
onLocationClick={handleLocationClick}
onAuthRequired={() => modals.open("auth")}
t={t}
@@ -552,22 +546,10 @@ export default function MainFeed() {
{modals.isOpen("rules") && <RulesModal onClose={modals.close} />}
{modals.isOpen("viewer") && (
<ImageViewer
images={modals.modal.payload.images}
initialIndex={modals.modal.payload.index}
onClose={modals.close}
postData={modals.modal.payload.ad}
/>
)}
{modals.isOpen("postDetail") && (
<PostDetailModal
postId={modals.modal.payload.postId}
onClose={modals.close}
onImageClick={(images: string[], index: number, ad: Record<string, unknown>) => {
modals.open("viewer", { images, index, ad });
}}
onLocationClick={(ad: Record<string, unknown>) => {
modals.close();
void handleLocationClick(ad);

View File

@@ -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}
>