Skip to content

Commit

Permalink
useMotionValue and useWindowSize making miracles.
Browse files Browse the repository at this point in the history
  • Loading branch information
LutherTS committed Sep 11, 2024
1 parent fc1f154 commit 49ac757
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
15 changes: 11 additions & 4 deletions app/(pages)/carousel-part-cleaned/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
// @ts-ignore
import useKeypress from "react-use-keypress";
import clsx from "clsx";
import useWindowSize from "@buildinams/use-window-size";

let fullAspectRatio = 3 / 2;
let collapsedAspectRatio = 1 / 3;
Expand All @@ -29,14 +30,14 @@ export default function Carousel({ images }: { images: string[] }) {
const { push } = useRouter(); // push instead replace to go back and forth in the browser's history
const searchParams = useSearchParams();

const currentPage = Number(searchParams.get(PAGE)) || 0;
const currentPage = Number(searchParams.get(PAGE)) || 0; // default O

const currentNoDistraction =
searchParams.get(NODISTRACTIONS) === "true"
? "true"
: searchParams.get(NODISTRACTIONS) === "false"
? "false"
: "false";
: "false"; // default false

const currentObjectFit =
searchParams.get(OBJECTFIT) === "contain"
Expand All @@ -45,7 +46,7 @@ export default function Carousel({ images }: { images: string[] }) {
? "scroll"
: searchParams.get(OBJECTFIT) === "cover"
? "cover"
: "cover";
: "cover"; // default cover

let index = currentPage;
let noDistracting: "false" | "true" = currentNoDistraction;
Expand Down Expand Up @@ -152,9 +153,15 @@ export default function Carousel({ images }: { images: string[] }) {
});

let height = useMotionValue(0);
const { width } = useWindowSize();
useEffect(() => {
height.set(document.getElementById(`${IMAGEID + index}`)!.clientHeight);
}, [height, index, objectFitting]);
}, [index, objectFitting, width]);

/* NEXT UP WOULD BE:
- a images folder selector based on the folders in public
- making images work in the dependency array or otherwise when a different folder is selected
*/

return (
<div className="flex max-h-screen items-center overflow-y-hidden bg-black">
Expand Down
4 changes: 2 additions & 2 deletions app/(pages)/carousel-part-cleaned/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from "node:fs";
// import * as fs from "node:fs";
import { Suspense } from "react";

import Carousel from "./carousel";
Expand All @@ -18,7 +18,7 @@ let images: string[];
// ]);
// imagesForSorting.sort((a, b) => a[1] - b[1]);
// images = imagesForSorting.map((e) => e[0]);
// console.log(images);
// // console.log(images);

/* Replacing the copypasted multiple images. */
const imagesDynamized = (x: number) => {
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@buildinams/use-window-size": "^0.0.1",
"@uidotdev/usehooks": "^2.4.1",
"clsx": "^2.1.1",
"date-fns": "^3.6.0",
Expand Down

0 comments on commit 49ac757

Please sign in to comment.