Skip to content

Commit

Permalink
feat(client): shuffle background mesh on page change
Browse files Browse the repository at this point in the history
  • Loading branch information
benji6 committed Jan 18, 2024
1 parent d92723b commit a5c551e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import Nav from "./Nav";
import useNotes from "./hooks/useNotes";
import { Link, Outlet } from "react-router-dom";
import { useState } from "react";
import { useShuffleBackgroundMesh } from "./hooks/useShuffleBackgroundMesh";

export default function Layout() {
useShuffleBackgroundMesh();
useUser();
useNotes();
const [isNavOpen, setIsNavOpen] = useState(false);
Expand Down
16 changes: 16 additions & 0 deletions client/src/components/hooks/useShuffleBackgroundMesh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useEffect, useRef } from "react";
import { shuffleBackgroundMesh } from "eri";
import { useLocation } from "react-router-dom";

export function useShuffleBackgroundMesh() {
const { pathname } = useLocation();
const lastPathnameRef = useRef<string | undefined>();
useEffect(() => {
if (
lastPathnameRef.current !== undefined &&
lastPathnameRef.current !== pathname
)
shuffleBackgroundMesh();
lastPathnameRef.current = pathname;
}, [pathname]);
}

0 comments on commit a5c551e

Please sign in to comment.