Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cma2819 committed Dec 28, 2023
1 parent 813c322 commit b4b5727
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions src/browser/graphics/components/nameplate/sync-display.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import gsap from "gsap";
import {ReactNode, createContext, useEffect, useState} from "react";
import {useReplicant} from "../../../use-replicant";
import {Commentator} from "../../../../nodecg/replicants";

type DisplayLabel = "name" | "twitter" | "twitch" | "nico";

Expand All @@ -10,33 +11,16 @@ export const SyncDisplayProvider = ({children}: {children: ReactNode}) => {
const [display, setDisplay] = useState<DisplayLabel>("name");

const currentRun = useReplicant("current-run");

const participantSocials = [
...(currentRun?.runners.map((runner) =>
[
runner.twitter ? "twitter" : null,
runner.twitch ? "twitch" : null,
runner.nico ? "nico" : null,
].filter((v): v is DisplayLabel => v !== null),
) ?? []),
...(currentRun?.commentators.map((commentator) =>
[
commentator?.twitter ? "twitter" : null,
commentator?.twitch ? "twitch" : null,
commentator?.nico ? "nico" : null,
].filter((v): v is DisplayLabel => v !== null),
const participants = [
...(currentRun?.runners ?? []),
...(currentRun?.commentators.filter(
(c): c is NonNullable<Commentator> => c !== null,
) ?? []),
];

const displayTwitter = participantSocials.some((socials) =>
socials.includes("twitter"),
);
const displayTwitch = participantSocials.some((socials) =>
socials.includes("twitch"),
);
const displayNico = participantSocials.some((socials) =>
socials.includes("nico"),
);
const displayTwitter = participants.some((p) => Boolean(p.twitter));
const displayTwitch = participants.some((p) => Boolean(p.twitch));
const displayNico = participants.some((p) => Boolean(p.nico));

useEffect(() => {
const tl = gsap.timeline({repeat: -1});
Expand Down

0 comments on commit b4b5727

Please sign in to comment.