Skip to content

Commit

Permalink
fix(client): firefox 102 not polyfied
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagarian committed May 12, 2023
1 parent dc19a2b commit fafda31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 3 additions & 3 deletions client/src/hooks/usePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
7 changes: 4 additions & 3 deletions client/src/pages/ScoreBoard/components/TeamsScoreBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 =
Expand Down
12 changes: 12 additions & 0 deletions client/src/services/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function findByLastIndex<T> (
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
}

0 comments on commit fafda31

Please sign in to comment.