From fafda314af7d8997c2f3372d85ab85c34f5e37ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Garreau?= Date: Fri, 12 May 2023 21:11:05 +0200 Subject: [PATCH] fix(client): firefox 102 not polyfied --- client/src/hooks/usePlayer.tsx | 6 +++--- .../pages/ScoreBoard/components/TeamsScoreBoard.tsx | 7 ++++--- client/src/services/polyfill.ts | 12 ++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 client/src/services/polyfill.ts diff --git a/client/src/hooks/usePlayer.tsx b/client/src/hooks/usePlayer.tsx index 63c38db..8c112c0 100644 --- a/client/src/hooks/usePlayer.tsx +++ b/client/src/hooks/usePlayer.tsx @@ -3,6 +3,7 @@ import { useAuth } from './useAuthentication' import { useGame } from './useGame' import { useSocket } from './useSocket' import { Message } from 'models/Message' +import { findByLastIndex } from 'services/polyfill' export type PlayerContext = { myScore: number @@ -58,9 +59,8 @@ function useProvidePlayer (): PlayerContext { .filter(cs => !!cs.achievements.find(a => a.username === user.username)) .reduce((agg, a) => agg + a.score, 0) - // @ts-ignore - const lastScorerIndex = teamsScore.findLastIndex( - // @ts-ignore + const lastScorerIndex = findByLastIndex( + teamsScore, s => s.score > 0 && s.rank > 3, ) const beforeLastScorer = diff --git a/client/src/pages/ScoreBoard/components/TeamsScoreBoard.tsx b/client/src/pages/ScoreBoard/components/TeamsScoreBoard.tsx index 7cd5b26..37fae9b 100644 --- a/client/src/pages/ScoreBoard/components/TeamsScoreBoard.tsx +++ b/client/src/pages/ScoreBoard/components/TeamsScoreBoard.tsx @@ -14,6 +14,7 @@ import { } from 'framer-motion' import { ChallengeScore, TeamScore } from 'models/GameScore' import { useMemo, useState } from 'react' +import { findByLastIndex } from 'services/polyfill' import { cleanStyledSystemOnly } from 'styles' export type TeamsScoreBoardProps = { @@ -26,9 +27,9 @@ export function TeamsScoreBoard ({ }: TeamsScoreBoardProps) { const y = useMotionValue(0) const dragControls = useDragControls() - // @ts-ignore - const lastScorerIndex = teamsScore.findLastIndex( - // @ts-ignore + + const lastScorerIndex = findByLastIndex( + teamsScore, s => s.score > 0 && s.rank > 3, ) const beforeLastScorer = diff --git a/client/src/services/polyfill.ts b/client/src/services/polyfill.ts new file mode 100644 index 0000000..f9dc377 --- /dev/null +++ b/client/src/services/polyfill.ts @@ -0,0 +1,12 @@ +export function findByLastIndex ( + list: T[], + callback: (item: T, index: number, list: T[]) => boolean, +): number { + for (let i = list.length - 1; i >= 0; i--) { + if (callback(list[i], i, list)) { + return i + } + } + + return -1 +}