diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cad671d..a1c6600 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,9 @@ "customizations": { "vscode": { "extensions": [ - "bradlc.vscode-tailwindcss" + "bradlc.vscode-tailwindcss", + "GitHub.copilot", + "esbenp.prettier-vscode" ] } } diff --git a/next.config.mjs b/next.config.mjs index 61964ea..6a9fe68 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -13,9 +13,9 @@ const config = { * * @see https://github.com/vercel/next.js/issues/41980 */ - i18n: { - locales: ["en"], - defaultLocale: "en", + output: 'export', + images: { + unoptimized: true, }, }; diff --git a/src/components/Flipbook.tsx b/src/components/Flipbook.tsx index 42df56a..7306753 100644 --- a/src/components/Flipbook.tsx +++ b/src/components/Flipbook.tsx @@ -1,12 +1,12 @@ -import { ChevronLeftIcon, ChevronRightIcon } from '@radix-ui/react-icons'; -import React, { useRef, useCallback } from 'react'; -import HTMLFlipBook from 'react-pageflip'; +import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons"; +import React, { useRef, useCallback } from "react"; +import HTMLFlipBook from "react-pageflip"; interface FlipbookProps { children: React.ReactNode[]; width: number; height: number; - className?: React.ComponentProps<'div'>['className']; + className?: React.ComponentProps<"div">["className"]; } interface PageFlip { @@ -21,53 +21,64 @@ export default function Flipbook(props: FlipbookProps) { const flipbook = useRef<{ pageFlip(): PageFlip } | null>(null); // Function to flip pages - const flipPage = useCallback((direction: 'next' | 'prev') => { - const flipbookCurrent = flipbook.current; - if (flipbookCurrent) { - const pageFlipObj = flipbookCurrent.pageFlip(); - const currentPageIndex = pageFlipObj.getCurrentPageIndex(); - const pageCount = pageFlipObj.getPageCount(); + const flipPage = useCallback( + (direction: "next" | "prev") => { + const flipbookCurrent = flipbook.current; + if (flipbookCurrent) { + const pageFlipObj = flipbookCurrent.pageFlip(); + const currentPageIndex = pageFlipObj.getCurrentPageIndex(); + const pageCount = pageFlipObj.getPageCount(); - if (direction === 'next') { - if (currentPageIndex + 2 === pageCount) { - pageFlipObj.flip(0); - } else { - pageFlipObj.flipNext(); - } - } else if (direction === 'prev') { - if (currentPageIndex === 0) { - pageFlipObj.flip(pageCount - 1); - } else { - pageFlipObj.flipPrev(); // Add this method to handle the previous page flip + if (direction === "next") { + if (currentPageIndex + 2 === pageCount) { + pageFlipObj.flip(0); + } else { + pageFlipObj.flipNext(); + } + } else if (direction === "prev") { + if (currentPageIndex === 0) { + pageFlipObj.flip(pageCount - 1); + } else { + pageFlipObj.flipPrev(); // Add this method to handle the previous page flip + } } } - } - }, [flipbook]); + }, + [flipbook], + ); // Handler for the next button const nextButtonClick = useCallback(() => { - flipPage('next'); + flipPage("next"); }, [flipPage]); // Handler for the previous button const prevButtonClick = useCallback(() => { - flipPage('prev'); + flipPage("prev"); }, [flipPage]); return ( -
-
); diff --git a/src/components/Slider.tsx b/src/components/Slider.tsx deleted file mode 100644 index 369c7fd..0000000 --- a/src/components/Slider.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons"; -import { useKeenSlider } from "keen-slider/react"; -import { useState, type MouseEvent } from "react"; - -interface SliderProps { - className?: React.ComponentProps<'div'>['className']; - children?: React.ReactNode; -} - -export default function Slider({ className, children }: SliderProps) { - const [currentSlide, setCurrentSlide] = useState(0); - const [loaded, setLoaded] = useState(false); - const [sliderRef, instanceRef] = useKeenSlider({ - initial: 0, - slideChanged(slider) { - setCurrentSlide(slider.track.details.rel); - }, - created() { - setLoaded(true); - }, - }); - - const goPrev = (e: MouseEvent) => { - e.stopPropagation(); - if (currentSlide !== 0) { - instanceRef.current?.prev(); - } - }; - - const goNext = (e: MouseEvent) => { - e.stopPropagation(); - if (instanceRef.current && currentSlide !== instanceRef.current.track.details.slides.length - 1) { - instanceRef.current.next(); - } - }; - - return ( -
-
-
- {children} -
- {loaded && instanceRef.current && ( - <> - - - - )} -
- {loaded && instanceRef.current && ( -
- {Array.from({ length: instanceRef.current.track.details.slides.length }, (_, idx) => ( - - ))} -
- )} -
- ); -} - -interface ArrowProps { - disabled: boolean; - left?: boolean; - onClick: (e: MouseEvent) => void; -} - -function Arrow({ disabled, left, onClick }: ArrowProps) { - const Icon = left ? ChevronLeftIcon : ChevronRightIcon; - const position = left ? '-left-10' : 'left-auto -right-10'; - - return ( - - ); -} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 6cca106..1649412 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,8 +1,18 @@ +import React, { useRef, useState, useEffect } from 'react'; import Head from "next/head"; import Image from "next/image"; import Flipbook from "~/components/Flipbook"; export default function Home() { + const mainRef = useRef(null); + const [mainWidth, setMainWidth] = useState(350); // default value + + useEffect(() => { + if (mainRef.current) { + setMainWidth(mainRef.current.offsetWidth/2.3); + } + }, []); + return ( <> @@ -10,22 +20,22 @@ export default function Home() { -
- -
- - {Array.from(Array(24), (_, i) => ( -
- pdf page -
- ))} -
- + {Array.from(Array(24), (_, i) => ( +
+ pdf page +
+ ))} +
+
);