From 39026d9a32d4d80198dd3229e4f23a8a9fff57c7 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 12 Sep 2024 22:34:07 +0100 Subject: [PATCH] add dropdown leaderboard animation --- .../leaderboard/leaderboard-scores.tsx | 46 +++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/components/leaderboard/leaderboard-scores.tsx b/src/components/leaderboard/leaderboard-scores.tsx index 1f71c4e..780cfb3 100644 --- a/src/components/leaderboard/leaderboard-scores.tsx +++ b/src/components/leaderboard/leaderboard-scores.tsx @@ -5,8 +5,8 @@ import ScoreSaberLeaderboard from "@/common/data-fetcher/types/scoresaber/scores import ScoreSaberLeaderboardScoresPage from "@/common/data-fetcher/types/scoresaber/scoresaber-leaderboard-scores-page"; import useWindowDimensions from "@/hooks/use-window-dimensions"; import { useQuery } from "@tanstack/react-query"; -import { motion, useAnimation } from "framer-motion"; -import { useCallback, useEffect, useState } from "react"; +import { motion } from "framer-motion"; +import { useEffect, useState } from "react"; import Card from "../card"; import Pagination from "../input/pagination"; import LeaderboardScore from "./leaderboard-score"; @@ -17,7 +17,6 @@ type Props = { export default function LeaderboardScores({ leaderboard }: Props) { const { width } = useWindowDimensions(); - const controls = useAnimation(); const [currentPage, setCurrentPage] = useState(1); const [currentScores, setCurrentScores] = useState(); @@ -33,23 +32,12 @@ export default function LeaderboardScores({ leaderboard }: Props) { staleTime: 30 * 1000, // Cache data for 30 seconds }); - const handleAnimation = useCallback(() => { - controls.set({ x: -50, opacity: 0 }); - controls.start({ x: 0, opacity: 1, transition: { duration: 0.25 } }); - }, [controls]); - useEffect(() => { if (scores) { setCurrentScores(scores); } }, [scores]); - useEffect(() => { - if (scores) { - handleAnimation(); - } - }, [scores, handleAnimation]); - useEffect(() => { refetch(); }, [leaderboard, currentPage, refetch]); @@ -59,27 +47,27 @@ export default function LeaderboardScores({ leaderboard }: Props) { } return ( - -
- {isError &&

Oopsies! Something went wrong.

} - {currentScores.scores.length === 0 &&

No scores found. Invalid Page?

} -
+ + +
+ {isError &&

Oopsies! Something went wrong.

} + {currentScores.scores.length === 0 &&

No scores found. Invalid Page?

} +
-
{currentScores.scores.map((playerScore, index) => ( ))}
-
- -
+ +
+ ); }