From f30a373120c8d1f0741b8dacb341a6630f3536da Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 1 Oct 2024 14:46:44 +0100 Subject: [PATCH] optimize mini ranking to only update when they are visible --- src/components/player/player-data.tsx | 10 +++++++--- src/components/ranking/mini.tsx | 19 ++++++++++++++++++- src/hooks/use-is-visible.ts | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/hooks/use-is-visible.ts diff --git a/src/components/player/player-data.tsx b/src/components/player/player-data.tsx index 374f488..de25bba 100644 --- a/src/components/player/player-data.tsx +++ b/src/components/player/player-data.tsx @@ -12,6 +12,8 @@ import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player"; import Card from "@/components/card"; import PlayerBadges from "@/components/player/player-badges"; import { useIsMobile } from "@/hooks/use-is-mobile"; +import { useIsVisible } from "@/hooks/use-is-visible"; +import { useRef } from "react"; type Props = { initialPlayerData: ScoreSaberPlayer; @@ -29,6 +31,8 @@ export default function PlayerData({ page, }: Props) { const isMobile = useIsMobile(); + const miniRankingsRef = useRef(); + const isMiniRankingsVisible = useIsVisible(miniRankingsRef); let player = initalPlayerData; const { data, isLoading, isError } = useQuery({ @@ -60,9 +64,9 @@ export default function PlayerData({ /> {!isMobile && ( -