Skip to content

Commit

Permalink
More performance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
wyne committed Apr 13, 2024
1 parent d59d93f commit fb07195
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/components/Rounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ interface RoundScollOffset {
[key: number]: number;
}

const MemoizedRoundScoreColumn = React.memo(RoundScoreColumn);
const MemoizedTotalScoreColumn = React.memo(TotalScoreColumn);
const MemoizedPlayerNameColumn = React.memo(PlayerNameColumn);

const Rounds: React.FunctionComponent<Props> = ({ }) => {
const [roundScollOffset, setRoundScrollOffset] = useState<RoundScollOffset>({});

Expand Down Expand Up @@ -57,14 +61,14 @@ const Rounds: React.FunctionComponent<Props> = ({ }) => {

return (
<View style={[styles.scoreTableContainer]}>
<PlayerNameColumn />
<TotalScoreColumn />
<MemoizedPlayerNameColumn />
<MemoizedTotalScoreColumn />
<ScrollView horizontal={true}
contentContainerStyle={{ flexDirection: 'row' }}
ref={roundsScrollViewEl}>
{roundsIterator.map((item, round) => (
<View key={round} onLayout={e => onLayoutHandler(e, round)}>
<RoundScoreColumn
<MemoizedRoundScoreColumn
round={round}
key={round}
isCurrentRound={round == roundCurrent} />
Expand Down
6 changes: 2 additions & 4 deletions src/components/ScoreLog/RoundScoreColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ const RoundScoreColumn: React.FunctionComponent<Props> = ({ round, isCurrentRoun
const dispatch = useAppDispatch();

const currentGameId = useAppSelector(state => state.settings.currentGameId);
const currentGame = useAppSelector(selectCurrentGame);

if (typeof currentGame == 'undefined') return null;
const playerIds = useAppSelector(state => selectCurrentGame(state)?.playerIds) || [];

const onPressHandler = useCallback(async () => {
if (disabled || !currentGameId) return;
Expand Down Expand Up @@ -61,7 +59,7 @@ const RoundScoreColumn: React.FunctionComponent<Props> = ({ round, isCurrentRoun
}}>
{round + 1}
</Text>
{currentGame.playerIds.map((playerId, playerIndex) => (
{playerIds.map((playerId, playerIndex) => (
<RoundScoreCell playerId={playerId} round={round} key={playerId} playerIndex={playerIndex} />
))}
</View>
Expand Down

0 comments on commit fb07195

Please sign in to comment.