фиксы в фотогаллереи, слайдере, подгрузка кастомных страниц

This commit is contained in:
xomimishka committed 2025-06-04 15:48:08 +03:00
1 parent 35eb333475
commit 65bd5b9e83
7 files changed
+252 -285

No files matched your search

+9
View File
@@ -8089,6 +8089,15 @@
"react": "^16.3.0 || ^17.0.0 || ^18.0.0" "react": "^16.3.0 || ^17.0.0 || ^18.0.0"
} }
}, },
"node_modules/react-swipeable": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/react-swipeable/-/react-swipeable-7.0.2.tgz",
"integrity": "sha512-v1Qx1l+aC2fdxKa9aKJiaU/ZxmJ5o98RMoFwUqAAzVWUcxgfHFXDDruCKXhw6zIYXm6V64JiHgP9f6mlME5l8w==",
"license": "MIT",
"peerDependencies": {
"react": "^16.8.3 || ^17 || ^18 || ^19.0.0 || ^19.0.0-rc"
}
},
"node_modules/react-transition-group": { "node_modules/react-transition-group": {
"version": "4.4.5", "version": "4.4.5",
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz",
@@ -12,7 +12,7 @@
font-size: 36px; font-size: 36px;
font-weight: 600; font-weight: 600;
line-height: 44px; line-height: 44px;
margin-top: 0; margin-top: 64px;
margin-bottom: 16px; margin-bottom: 16px;
@include mediaMax($tablet-max-width) { @include mediaMax($tablet-max-width) {
+11 -7
View File
@@ -5,17 +5,21 @@ import "./PhotoGallery.style.scss";
import HWaC1 from "@/shared/assets/images/hard_work_and_creativity/HWaC1.jpg"; import HWaC1 from "@/shared/assets/images/hard_work_and_creativity/HWaC1.jpg";
import HWaC2 from "@/shared/assets/images/hard_work_and_creativity/HWaC2.jpg"; import HWaC2 from "@/shared/assets/images/hard_work_and_creativity/HWaC2.jpg";
const PhotoGallery = () => { interface PhotoGalleryProps {
const { data: mediaData, isLoading, isError } = useMedia(); images?: string[];
const [visibleCount] = useState(10); }
const filteredMedia = mediaData?.filter((el) => el.category === "gallery") || []; const PhotoGallery = ({ images }: PhotoGalleryProps) => {
const { data: mediaData, isLoading, isError } = useMedia();
const [visibleCount, setVisibleCount] = useState(10);
const galleryImages = mediaData?.filter((el) => el.category === "photogallery");
if (isLoading) { if (isLoading) {
return <SkeletonGallery />; return <SkeletonGallery />;
} }
if (isError || !filteredMedia || filteredMedia.length === 0) { if (isError || !galleryImages || galleryImages.length === 0) {
return <center>Ошибка при загрузке медиа</center>; return <center>Ошибка при загрузке медиа</center>;
} }
@@ -43,7 +47,7 @@ const PhotoGallery = () => {
<h1 className="title">Фотогалерея</h1> <h1 className="title">Фотогалерея</h1>
<div className="images"> <div className="images">
{filteredMedia.slice(0, visibleCount).map((media) => ( {galleryImages.slice(0, visibleCount).map((media) => (
<div key={media.id} className="image-container"> <div key={media.id} className="image-container">
<img <img
src={media.src} src={media.src}
@@ -54,7 +58,7 @@ const PhotoGallery = () => {
))} ))}
</div> </div>
{visibleCount < filteredMedia.length && ( {visibleCount < galleryImages.length && (
<div className="btn" onClick={() => setVisibleCount(visibleCount + 10)}> <div className="btn" onClick={() => setVisibleCount(visibleCount + 10)}>
Загрузить ещё Загрузить ещё
</div> </div>
+111 -189
View File
@@ -3,7 +3,9 @@
margin: 0 auto; margin: 0 auto;
position: relative; position: relative;
padding: 10px 0; padding: 10px 0;
user-select: none; // Запрещаем выделение всего содержимого слайдера will-change: transform;
backface-visibility: hidden;
transform-style: preserve-3d;
&.has-pagination { &.has-pagination {
.swiper { .swiper {
@@ -11,238 +13,158 @@
} }
} }
.slider-item { .swiper-slide {
padding-top: 10px;
padding-bottom: 10px;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
will-change: transform;
transform: translateZ(0);
backface-visibility: hidden;
perspective: 1000px;
.slide-image { .slide-image {
width: 100%; width: 100%;
height: auto;
height: 350px; height: 350px;
object-fit: cover; object-fit: cover;
object-position: center center; object-position: center;
border-radius: 8px; border-radius: 8px;
pointer-events: none; pointer-events: none;
user-select: none; // Дополнительная защита от выделения изображений transform: translateZ(0);
backface-visibility: hidden;
} }
} }
.swiper-wrapper:has(.swiper-slide.single) { .swiper-wrapper:has(.swiper-slide.single) {
justify-content: center; justify-content: center;
.slider-item.single { .swiper-slide.single {
display: flex;
justify-content: center;
align-items: center;
.slide-image { .slide-image {
width: auto; width: auto;
height: 100%; height: 100%;
object-position: center center; border-radius: 0;
pointer-events: none;
user-select: none; // Запрещаем выделение и для одиночных изображений
border-radius: 0px;
} }
} }
} }
} }
/* стрелки */
/* Кастомные стрелки */
.custom-navigation { .custom-navigation {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
position: absolute; position: absolute;
top: 50%; top: 50%;
width: 100%;
transform: translateY(-50%); transform: translateY(-50%);
background: rgba(0, 0, 0, 0.7); z-index: 10;
color: white; pointer-events: none;
border: none;
width: 40px; &>* {
height: 40px; pointer-events: all;
}
}
.custom-prev,
.custom-next {
width: 60px;
height: 60px;
background-color: white;
border-radius: 50%; border-radius: 50%;
cursor: pointer;
font-size: 18px;
display: flex; display: flex;
align-items: center;
justify-content: center; justify-content: center;
z-index: 2; align-items: center;
transition: all 0.2s ease; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
cursor: pointer;
font-size: 24px;
border: none;
transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
box-shadow 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
transform: translateZ(0);
backface-visibility: hidden;
&:hover { &:hover {
background: rgba(0, 0, 0, 0.9); transform: scale(1.05);
transform: translateY(-50%) scale(1.1); box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
} }
&[disabled] { &:active {
display: none; transform: scale(0.95);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
} }
}
.alice-carousel__wrapper {
width: 185%;
height: auto;
left: -240px;
user-select: none;
}
.alice-carousel__prev-btn {
left: 10px;
&::before {
content: "←";
}
}
.alice-carousel__next-btn {
right: 10px;
&::before {
content: "→";
}
}
// Стили для Alice Carousel (добавить в конец файла)
.slider {
// Ваши существующие стили остаются без изменений
// Стили для Alice Carousel
.alice-carousel {
&__wrapper {
position: relative;
}
&__stage {
padding: 0;
}
&__stage-item {
padding: 0 10px;
}
// Используем ваши оригинальные стили для кнопок навигации
&__prev-btn,
&__next-btn {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 60px;
height: 60px;
background-color: white;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
cursor: pointer;
font-size: 24px;
border: none;
z-index: 10;
}
&__prev-btn {
left: -70px;
&::before {
content: "‹";
}
@media (max-width: 768px) {
left: 0px;
}
}
&__next-btn {
right: -70px;
&::before {
content: "›";
}
@media (max-width: 768px) {
right: 0px;
}
}
// Стили для точек навигации
&__dots {
display: flex;
justify-content: center;
gap: 8px;
margin-top: 15px;
&-item {
width: 10px;
height: 10px;
border-radius: 50%;
background: rgba(0, 0, 0, 0.3);
cursor: pointer;
transition: all 0.2s ease;
border: none;
&.__active {
background: #007bff;
transform: scale(1.2);
}
&:hover {
background: rgba(0, 0, 0, 0.6);
}
}
}
// Скрываем точки когда они отключены
&.__disabled-dots .alice-carousel__dots {
display: none;
}
// Скрываем кнопки когда они отключены
&.__disabled-buttons {
.alice-carousel__prev-btn,
.alice-carousel__next-btn {
display: none;
}
}
}
}
.slider-item {
display: flex;
justify-content: center;
align-items: center;
}
.slide-image {
width: 100%;
height: 300px;
object-fit: cover;
border-radius: 4px;
@media (max-width: 768px) { @media (max-width: 768px) {
height: 250px; width: 45px;
height: 45px;
} }
} }
// Responsive стили .custom-prev {
@media (max-width: 768px) { margin-left: -80px;
.slider {
.alice-carousel__stage-item {
padding: 0 5px;
}
.alice-carousel__prev-btn, @media (max-width: 768px) {
.alice-carousel__next-btn { margin-left: 5px;
width: 35px;
height: 35px;
font-size: 16px;
}
.alice-carousel__prev-btn {
left: 5px;
}
.alice-carousel__next-btn {
right: 5px;
}
} }
} }
.custom-next {
margin-right: -80px;
@media (max-width: 768px) {
margin-right: 5px;
}
}
.slider.news {
.swiper-slide {
opacity: 0.5;
transition: opacity 0.6s cubic-bezier(0.22, 0.61, 0.36, 1),
transform 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
height: 65vh;
min-height: 300px;
transform-origin: center center;
.slide-image {
height: 500px;
transition: transform 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}
@media (max-width: 768px) {
opacity: 1;
transition: none;
height: 48vh;
min-height: 250px;
.slide-image {
height: 350px;
}
}
}
.swiper-slide-active {
opacity: 1;
.slide-image {
transform: scale(1.02);
}
}
&.no-animation .swiper-slide {
transition: none !important;
.slide-image {
transform: none !important;
}
}
.swiper-slide-prev,
.swiper-slide-next {
opacity: 0.7;
transform: scale(0.95);
@media (max-width: 768px) {
opacity: 1;
transform: none;
}
}
}
+111 -84
View File
@@ -1,102 +1,129 @@
import { useState } from "react"; import { useEffect, useState, useRef } from "react";
import AliceCarousel from "react-alice-carousel"; import { Swiper, SwiperSlide } from "swiper/react";
import "react-alice-carousel/lib/alice-carousel.css"; import { Navigation } from "swiper/modules";
import { useMedia } from "@/modules/media/hooks/useMedia"; import { useMedia } from "@/modules/media/hooks/useMedia";
import { MediaItem } from "@/modules/media/api/get";
import { SkeletonSlider } from "@/shared/Components/SkeletonSlider/SkeletonSlider"; import { SkeletonSlider } from "@/shared/Components/SkeletonSlider/SkeletonSlider";
import "./Slider.styles.scss"; import { MediaItem } from "@/modules/media/api/get";
import { SliderContext, SliderProps } from "@/widgets/Slider/context";
function Slider({ import "swiper/css";
import "swiper/css/navigation";
import "./Slider.styles.scss";
import arrow from "@/shared/assets/images/arrow.svg";
interface SliderProps {
autoPlay?: boolean;
autoPlayTime?: number;
images?: string[];
category: string;
customPerSlide?: number;
variant?: "default" | "news";
}
const Slider = ({
autoPlay = false, autoPlay = false,
autoPlayTime = 3000, autoPlayTime = 3000,
images, images,
category = "gallery", category,
customPerSlide = 6, customPerSlide = 0,
}: SliderProps) { variant = "default",
}: SliderProps) => {
const { data: mediaData, isLoading, isError } = useMedia(); const { data: mediaData, isLoading, isError } = useMedia();
const [slideNumber, setSlideNumber] = useState(0); const [mediaList, setMediaList] = useState<MediaItem[]>([]);
const [itemsPerSlide, setItemsPerSlide] = useState(2);
const [enableButtons, setEnableButtons] = useState(false);
const filteredMedia: MediaItem[] = images const swiperRef = useRef<any>(null);
? images.map((src, id) => ({ id, src, category: "", name: "" }))
: mediaData?.filter((m) => m.category === category) || [];
const getSlidesPerView = (width: number = window.innerWidth) => { useEffect(() => {
if (customPerSlide > 0) return customPerSlide; const mapped =
if (width < 768) return 1; images?.map((src, id) => ({ id, src, category: "", name: "" })) ||
if (width < 1024) return 2; mediaData?.filter((m) => m.category === category) ||
if (width < 1920) return 10; [];
return 10; setMediaList(mapped);
}; }, [images, mediaData, category]);
const currentSlidesPerView = getSlidesPerView();
const shouldShowNavigation = filteredMedia.length > currentSlidesPerView; useEffect(() => {
const shouldShowDots = filteredMedia.length > currentSlidesPerView; const updateLayout = () => {
const isMobile = window.innerWidth <= 768;
const slideCount = mediaList.length;
const responsive = { setItemsPerSlide(
0: { items: 1 }, slideCount === 1
400: { items: 2 }, ? 1
600: { items: 3 }, : variant === "news"
800: { items: 3 }, ? isMobile
1000: { items: 4 }, ? 1
1200: { items: 4 }, : 1.4
1400: { items: 5 }, : isMobile
1600: { items: 7 }, ? 1
}; : customPerSlide || 2
);
setEnableButtons(isMobile ? slideCount > 1 : slideCount > (customPerSlide || 2));
};
console.log("responsive object:", responsive); updateLayout();
const items = filteredMedia.map((media) => ( window.addEventListener("resize", updateLayout);
<div key={media.id} className="slider-item"> return () => window.removeEventListener("resize", updateLayout);
<img }, [mediaList, variant, customPerSlide]);
src={media.src}
alt={`slide-${media.id}`}
className="slide-image"
loading="lazy"
/>
</div>
));
const handleSlideChanged = (event: { item: number }) => {
setSlideNumber(event.item);
};
const goToSlide = (index: number) => {
setSlideNumber(index);
};
if (isLoading) return <SkeletonSlider />; if (isLoading) return <SkeletonSlider />;
if (isError) return <center>Ошибка при загрузке медиа</center>; if (isError) return <center>Ошибка при загрузке медиа</center>;
if (filteredMedia.length === 0)
return <div>Нет изображений для отображения</div>; const sliderClass =
variant === "news" && mediaList.length <= 2 ? "no-animation" : "";
return ( return (
<SliderContext.Provider <div className={`slider ${variant} ${sliderClass}`}>
value={{ {enableButtons && (
slideNumber, <div className="custom-navigation">
mediaList: filteredMedia, <button
goToSlide, className="custom-prev"
slidesCount: filteredMedia.length, onClick={() => swiperRef.current?.slidePrev()}
}} >
> <img src={arrow} alt="prev" />
<div className="slider"> </button>
<AliceCarousel <button
items={items} className="custom-next"
responsive={responsive} onClick={() => swiperRef.current?.slideNext()}
controlsStrategy="alternate" >
autoPlay={autoPlay && shouldShowNavigation} <img src={arrow} alt="next" style={{ transform: "rotate(180deg)" }} />
autoPlayInterval={autoPlayTime} </button>
infinite={shouldShowNavigation} </div>
disableDotsControls={!shouldShowDots} )}
disableButtonsControls={!shouldShowNavigation}
activeIndex={slideNumber}
onSlideChanged={handleSlideChanged}
mouseTracking={shouldShowNavigation}
touchTracking={shouldShowNavigation}
keyboardNavigation={shouldShowNavigation}
/>
</div>
</SliderContext.Provider>
);
}
export default Slider; <Swiper
modules={[Navigation]}
spaceBetween={variant === "news" ? 20 : 30}
slidesPerView={itemsPerSlide}
centeredSlides={variant === "news" && mediaList.length > 1}
slidesPerGroup={1}
loop={enableButtons}
autoplay={
autoPlay
? { delay: autoPlayTime, disableOnInteraction: false }
: false
}
onSwiper={(swiper) => (swiperRef.current = swiper)}
>
{mediaList.map((media, index) => (
<SwiperSlide
key={media.id}
className={`swiper-slide ${
mediaList.length === 1 ? "single" : ""
}`}
>
<img
src={media.src}
alt={`slide-${index}`}
className="slide-image"
loading="lazy"
/>
</SwiperSlide>
))}
</Swiper>
</div>
);
};
export default Slider;
+1 -1
View File
@@ -23,7 +23,7 @@ export default function WpPost({
const categories = post.categories ?? []; const categories = post.categories ?? [];
const title = post.title; const title = post.title;
const customComponent = getCustomProject(title); const customComponent = getCustomProject(categories);
const isSpecialTitle = title === "Программно-аппаратный комплекс для мониторинга управления мусорных контейнеров"; const isSpecialTitle = title === "Программно-аппаратный комплекс для мониторинга управления мусорных контейнеров";
+8 -3
View File
@@ -6,7 +6,12 @@ const customProjects: Record<string, ReactNode> = {
labboard: <LabBoard />, labboard: <LabBoard />,
}; };
export const getCustomProject = (title: string): ReactNode | null => { export const getCustomProject = (categories: string[]): ReactNode | null => {
// const normalizedKey = title.toLowerCase().replace(/\s+/g, "").replace(/[^a-z0-9]/g, ""); for (const category of categories) {
return customProjects[title] || null; const key = category;
if (customProjects[key]) {
return customProjects[key];
}
}
return null;
}; };