Skip to content

Commit

Permalink
🐛 fix issue with offset being static
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-manning committed Sep 7, 2023
1 parent 3c6ad81 commit 47739a5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/Browse.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useRef } from "react";
import { useEffect, useRef, useState } from "react";
import "./Browse.css";
import Section from "./Section";
import useFixedStyles from "../hooks/use-scroll-data";
import Button from "./Button";

const UWU_OPTIONS = 49;
const OFFSET = Math.round(Math.random() * UWU_OPTIONS);

interface UwuType {
width: number; // Percentage of screen width
Expand Down Expand Up @@ -85,8 +84,15 @@ const uwus: UwuType[] = [

const Browse = () => {
const containerRef = useRef<HTMLDivElement>(null);
const [offset, setOffset] = useState(null);
const { fixedStyles, percentScrolled } = useFixedStyles(containerRef);

useEffect(() => {
setOffset(Math.round(Math.random() * UWU_OPTIONS));
}, []);

if (!offset) return null;

return (
<Section id="browse">
<div className="browse" ref={containerRef}>
Expand All @@ -111,7 +117,7 @@ const Browse = () => {
zIndex,
};
const image = `/assets/browse/${
((index + OFFSET) % UWU_OPTIONS) + 1
((index + offset) % UWU_OPTIONS) + 1
}.jpg`;
return (
<div
Expand Down

0 comments on commit 47739a5

Please sign in to comment.