diff --git a/frontend/src/pages/GameDetails.tsx b/frontend/src/pages/GameDetails.tsx index f5c67ce..ff80aa8 100644 --- a/frontend/src/pages/GameDetails.tsx +++ b/frontend/src/pages/GameDetails.tsx @@ -1,5 +1,5 @@ import { useEffect, useMemo, useRef, useState } from "react"; -import { Image, Stack } from "react-bootstrap"; +import { Alert, Image, Stack } from "react-bootstrap"; import { useParams } from "react-router-dom"; import { gql } from "@apollo/client"; import { useMutation, useQuery } from "@apollo/client/react"; @@ -117,6 +117,8 @@ export default function GameDetails() { const isMobile = useIsMobile(); const userId = useMemo(() => getUserId(), []); const imageSize: number = isMobile ? 150 : 220; + const [alertingUser, setAlertingUser] = useState(false); + const alertTimeout = useRef | null>(null); const { data, loading, error } = useQuery(GET_GAME, { variables: { id }, @@ -127,6 +129,12 @@ export default function GameDetails() { }); const [rateGame] = useMutation(RATE_GAME); + useEffect(() => { + return () => { + if (alertTimeout.current) clearTimeout(alertTimeout.current); + }; + }, []); + const game = data?.game; const savedScore = myReviewData?.myReviews.find((review) => review.gameId === id)?.score ?? @@ -186,12 +194,27 @@ export default function GameDetails() { function handleRate(score: number) { if (!id) return; setOverride({ id, score }); + setAlertingUser(true); + if (alertTimeout.current) clearTimeout(alertTimeout.current); + alertTimeout.current = setTimeout(() => setAlertingUser(false), 3000); } return ( <>
+ {alertingUser && ( + + Your rating is locally stored and will be updated next time you are here. + + )}
{loading && !data &&

Loading…

} {!loading && (error || !game) && (