From 36de0777aadb7a45febbe98adf841f2442026e53 Mon Sep 17 00:00:00 2001 From: zojgame Date: Thu, 28 Mar 2024 18:27:11 +0500 Subject: [PATCH] reviews starting --- src/app/page.tsx | 1 - src/components/Reviews.tsx | 502 +++++++++++++++++++++++++------------ 2 files changed, 345 insertions(+), 158 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 81f1e15..d1b7dc7 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -28,7 +28,6 @@ import YouTubeIcon from "@components/icons/YouTubeIcon"; import TelegramIcon from "@components/icons/TelegramIcon"; import { IProject } from "../types/IProject"; import { SortedProject } from "../types/SortedProject"; -import { ProjectYear } from "../types/ProjectYear"; import Winners from "@components/Winners"; import { getTime, getDate, getYear } from "date-fns"; import ProjectsSection from "@components/ProjectsSection"; diff --git a/src/components/Reviews.tsx b/src/components/Reviews.tsx index 171bea3..64bf2a3 100644 --- a/src/components/Reviews.tsx +++ b/src/components/Reviews.tsx @@ -1,10 +1,17 @@ -import { createRef, useEffect, useLayoutEffect, useRef, useState } from "react"; +// import { createRef, useEffect, useLayoutEffect, useRef, useState } from "react"; +// import { useSwipeable } from "react-swipeable"; +// import { motion } from "framer-motion"; +// import { Transition } from "react-transition-group"; +// import ArrowLeftIcon from "./icons/ArrowLeftIcon"; +// import ArrowRightIcon from "./icons/ArrowRightIcon"; +// import { Video } from "../types/Video"; +import { createRef, useEffect, useState } from "react"; +import { useInView } from "react-intersection-observer"; import { useSwipeable } from "react-swipeable"; -import { motion } from "framer-motion"; -import { Transition } from "react-transition-group"; +import { Video } from "../types/Video"; import ArrowLeftIcon from "./icons/ArrowLeftIcon"; import ArrowRightIcon from "./icons/ArrowRightIcon"; -import { Video } from "../types/Video"; +import { Transition } from "react-transition-group"; const VIDEOS: Video[] = [ { @@ -30,174 +37,355 @@ const VIDEOS: Video[] = [ }, ]; -const Reviews = () => { - const [isViewportEntered, setIsViewportEntered] = useState(false); +// const Reviews = () => { +// const [isViewportEntered, setIsViewportEntered] = useState(false); - function handleViewportEnter() { - if (isViewportEntered) return; - setIsViewportEntered(true); - } - const [cardWidth, setCardWidth] = useState(0); +// function handleViewportEnter() { +// if (isViewportEntered) return; +// setIsViewportEntered(true); +// } +// const [cardWidth, setCardWidth] = useState(0); +// const handlers = useSwipeable({ +// onSwipedLeft: handleOnRightMove, +// onSwipedRight: handleOnLeftMove, +// trackMouse: true, +// }); +// const [selectedVideo, setSelectedVideo] = useState(0); +// const [_document, setDocument] = useState(); + +// function handleOnLeftMove(): void { +// if (selectedVideo > 0) { +// setSelectedVideo((prev) => prev - 1); +// } +// } + +// function handleOnRightMove(): void { +// if (selectedVideo < 2) { +// setSelectedVideo((prev) => prev + 1); +// } +// } + +// useEffect(() => { +// setDocument(document); +// }, []); + +// useEffect(() => { +// if (!_document) return; + +// const clientWidth = _document.children[0].clientWidth; + +// if (clientWidth >= 1600) { +// setCardWidth(1000); +// } else if (clientWidth >= 1280) { +// setCardWidth(805); +// } else if (clientWidth >= 640) { +// setCardWidth(736); +// } else { +// setCardWidth(clientWidth - 16); +// } +// }, [_document]); + +// return ( +// +//
+//
+//
+//
+//

+//

+// Отзывы +//

+//

клиентов

+//

+//
+//
+//
+//

Егор Бобров

+//

+// Коммерческий директор авторского квартала «Машаров»{" "} +//

+//
+//
+//
+//

+// Эффективность инструмента была подтверждена буквально в первый +// день после его внедрения. Например, один из клиентов, посетив +// офис и увидев свою будущую квартиру с помощью интерактивной +// панели, сразу решил купить недвижимость в этом проекте, +// отказавшись от других вариантов +//

+//
+// {/* {VIDEOS.map((item, index) => ( +// +// {(state) => ( +//
+//

+// Эффективность инструмента была подтверждена буквально в +// первый день после его внедрения. Например, один из +// клиентов, посетив офис и увидев свою будущую квартиру с +// помощью интерактивной панели, сразу решил купить +// недвижимость в этом проекте, отказавшись от других +// вариантов +//

+//
+// )} +//
+// ))} */} +//
+//
+// +// +//
+//
+//
+//
+//
+//
+// {VIDEOS.map((video, index) => ( +//
+// img +//
+// ))} +//
+//
+//
+//
+//

+// {VIDEOS[selectedVideo].title} +//

+//

+// {VIDEOS[selectedVideo].desc} +//

+//
+//
+// {VIDEOS.map((video, index) => ( +//
+// ))} +//
+//
+//
+// +// ); +// }; +function Reviews() { + const [selectedVideoIndex, setSelectedVideoIndex] = useState(0); + const videoRefs = VIDEOS.map(() => createRef()); + const [videoWidth, setVideoWidth] = useState(0); + const [videoHeigth, setVideoHeigth] = useState(0); + const { ref, inView } = useInView(); + const [isEntered, setIsEntered] = useState(false); const handlers = useSwipeable({ - onSwipedLeft: handleOnRightMove, - onSwipedRight: handleOnLeftMove, + onSwipedLeft: next, + onSwipedRight: prev, trackMouse: true, }); - const [selectedVideo, setSelectedVideo] = useState(0); - const [_document, setDocument] = useState(); - function handleOnLeftMove(): void { - if (selectedVideo > 0) { - setSelectedVideo((prev) => prev - 1); - } - } - - function handleOnRightMove(): void { - if (selectedVideo < 2) { - setSelectedVideo((prev) => prev + 1); - } - } - - useEffect(() => { - setDocument(document); - }, []); - - useEffect(() => { - if (!_document) return; - - const clientWidth = _document.children[0].clientWidth; - - if (clientWidth >= 1600) { - setCardWidth(1000); - } else if (clientWidth >= 1280) { - setCardWidth(805); - } else if (clientWidth >= 640) { - setCardWidth(736); + function handleEnded() { + if (selectedVideoIndex === VIDEOS.length - 1) { + setSelectedVideoIndex(0); } else { - setCardWidth(clientWidth - 16); + setSelectedVideoIndex((prev) => prev + 1); } - }, [_document]); + } + + function prev() { + if (selectedVideoIndex === 0) return; + setSelectedVideoIndex((prev) => prev - 1); + } + + function next() { + if (selectedVideoIndex === VIDEOS.length - 1) return; + setSelectedVideoIndex((prev) => prev + 1); + } + + useEffect(() => { + if (!inView || isEntered) return; + + setIsEntered(true); + }, [inView]); return ( - -
-
-
-
-

-

- Отзывы -

-

клиентов

-

-
-
-
-

Егор Бобров

-

- Коммерческий директор авторского квартала «Машаров»{" "} -

-
-
-
-

- Эффективность инструмента была подтверждена буквально в первый - день после его внедрения. Например, один из клиентов, посетив - офис и увидев свою будущую квартиру с помощью интерактивной - панели, сразу решил купить недвижимость в этом проекте, - отказавшись от других вариантов -

-
- {/* {VIDEOS.map((item, index) => ( - - {(state) => ( -
-

- Эффективность инструмента была подтверждена буквально в - первый день после его внедрения. Например, один из - клиентов, посетив офис и увидев свою будущую квартиру с - помощью интерактивной панели, сразу решил купить - недвижимость в этом проекте, отказавшись от других - вариантов -

-
- )} -
- ))} */} -
-
- - -
-
-
-
-
-
- {VIDEOS.map((video, index) => ( -
- img -
- ))} -
-
-
-
-

- {VIDEOS[selectedVideo].title} -

-

- {VIDEOS[selectedVideo].desc} +

+
+

+

+ Отзывы

-

-
- {VIDEOS.map((video, index) => ( -
+

клиентов

+ +
+ {VIDEOS.map((item, index) => ( + + {(state) => ( +
+ {item.title ? ( +

+ {item.title} +

+ ) : ( + <> + )} +

+ {item.desc} +

+
+ )} +
))}
+
+ + +
+
+
+ {VIDEOS.map((video, index) => ( +
+ {video.title} + setTimeout(() => { + setVideoWidth(videoRefs[0].current!.clientWidth); + setVideoHeigth(videoRefs[0].current!.clientHeight); + }, 200) + } + /> + {/*
+ ))} +
+
+ {VIDEOS.map((item, index) => ( + + {(state) => ( +
+ {item.title ? ( +

+ {item.title} +

+ ) : ( + <> + )} +

+ {item.desc} +

+
+ )} +
+ ))} +
+
+ {VIDEOS.map((video, index) => ( +
+ ))}
- +
); -}; +} export default Reviews;