Add tests for ReactionAudioRenderer

This commit is contained in:
Half-Shot
2024-11-05 19:01:57 +00:00
parent b1246f90bf
commit d3cecccdab
7 changed files with 170 additions and 32 deletions

View File

@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
Please see LICENSE in the repository root for full details.
*/
import { ReactNode } from "react";
import { ReactNode, useMemo } from "react";
import { useReactions } from "../useReactions";
import { playReactionsSound, useSetting } from "../settings/settings";
@@ -14,9 +14,20 @@ export function ReactionsAudioRenderer(): ReactNode {
const { reactions } = useReactions();
const [shouldPlay] = useSetting(playReactionsSound);
const expectedReactions = shouldPlay
? [...new Set([...Object.values(reactions)])]
: [];
const expectedReactions = useMemo(() => {
if (!shouldPlay) {
return [];
}
const reactionsToPlayNames = new Set();
return Object.values(reactions).filter((r) => {
if (reactionsToPlayNames.has(r.name)) {
return false;
}
reactionsToPlayNames.add(r.name);
return true;
});
}, [shouldPlay, reactions]);
return (
<>
{expectedReactions.map(