Skip to content

Commit

Permalink
Initial update of audience display
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-flynn committed Apr 8, 2024
1 parent 40f4acb commit 1a74b49
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 21 deletions.
9 changes: 8 additions & 1 deletion front-end/src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ const HeadReferee = lazy(() =>
import('./apps/referee').then((m) => ({ default: m.HeadReferee }))
);

const AudienceDisplay = lazy(() => import('./apps/AudienceDisplay'));
// Audience Display Routes
const AudienceDisplay = lazy(() =>
import('./apps/audience-display').then((m) => ({
default: m.AudienceDisplay
}))
);

// Unised Routes
// const AccountManager = lazy(() => import('./apps/AccountManager'));
// const RefereeApp = lazy(() => import('./apps/Referee/Referee'));
// const ScoreKeeper = lazy(() => import('./apps/Referee/ScoreKeeper'));
Expand Down
32 changes: 12 additions & 20 deletions front-end/src/apps/AudienceDisplay/AudienceDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { clientFetcher } from '@toa-lib/client';
import {
Displays,
getSeasonKeyFromEventKey,
isMatch,
Match,
MatchKey,
MatchSocketEvent
} from '@toa-lib/models';
import { useParams, useSearchParams } from 'react-router-dom';
Expand All @@ -14,18 +10,14 @@ import { useSocket } from 'src/api/use-socket';
import MatchStateListener from 'src/components/sync-effects/MatchStateListener/MatchStateListener';
import PrestartListener from 'src/components/sync-effects/PrestartListener/PrestartListener';
import ChromaLayout from 'src/layouts/ChromaLayout';
import {
displayChromaKeyAtom,
displayIdAtom,
matchResultAtom
} from 'src/stores/NewRecoil';

import Rankings from './displays/fgc_2023/Rankings/Rankings';
import { displayChromaKeyAtom, displayIdAtom } from 'src/stores/NewRecoil';
import { useHiddenMotionlessCursor } from 'src/hooks/use-hidden-motionless-cursor';
import './AudienceDisplay.less';
import { updateSocketClient } from 'src/api/use-socket-data';
import RankingsPlayoffs from './displays/fgc_2023/RankingsPlayoffs/RankingsPlayoff';
import AudienceDisplayProvider from './displays/AudienceDisplayProvider';
import './AudienceDisplay.less';

import Rankings from './displays/fgc_2023/Rankings/Rankings';

// Seasons
import FRC2023 from './displays/frc_2023';
Expand Down Expand Up @@ -96,14 +88,14 @@ const AudienceDisplay: FC = () => {
setDisplay(id);
};

const onCommit = useRecoilCallback(({ set }) => async (key: MatchKey) => {
const match: Match<any> = await clientFetcher(
`match/all/${key.eventKey}/${key.tournamentKey}/${key.id}`,
'GET',
undefined,
isMatch
);
set(matchResultAtom, match);
const onCommit = useRecoilCallback(() => async () => {
// const match: Match<any> = await clientFetcher(
// `match/all/${key.eventKey}/${key.tournamentKey}/${key.id}`,
// 'GET',
// undefined,
// isMatch
// );
// set(matchResultAtom, match);
});

return (
Expand Down
34 changes: 34 additions & 0 deletions front-end/src/apps/audience-display/audience-display.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FC, Suspense } from 'react';
import { useRecoilValue } from 'recoil';
import { SyncDisplayToRecoil } from 'src/components/sync-effects/sync-display-to-recoi';
import { SyncMatchStateToRecoil } from 'src/components/sync-effects/sync-match-state-to-recoil';
import { SyncOnPrestart } from 'src/components/sync-effects/sync-on-prestart';
import ChromaLayout from 'src/layouts/ChromaLayout';
import { currentEventKeyAtom, displayIdAtom } from 'src/stores/NewRecoil';
import Displays from './displays';

export const AudienceDisplay: FC = () => {
const eventKey = useRecoilValue(currentEventKeyAtom);
const displayId = useRecoilValue(displayIdAtom);
return (
<Suspense
fallback={
<div
style={{
position: 'absolute',
height: '100vh',
width: '100vw',
backgroundColor: 'rgba(0,0,0,0)'
}}
/>
}
>
<ChromaLayout>
<SyncMatchStateToRecoil />
<SyncOnPrestart />
<SyncDisplayToRecoil />
<Displays id={displayId} eventKey={eventKey} />
</ChromaLayout>
</Suspense>
);
};
13 changes: 13 additions & 0 deletions front-end/src/apps/audience-display/displays/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { FC } from 'react';

interface Props {
id: number;
eventKey: string | null | undefined;
mode?: string;
}

const Displays: FC<Props> = () => {
return null;
};

export default Displays;
3 changes: 3 additions & 0 deletions front-end/src/apps/audience-display/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { AudienceDisplay } from './audience-display';

export { AudienceDisplay };
23 changes: 23 additions & 0 deletions front-end/src/components/sync-effects/sync-display-to-recoi.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FC, useEffect } from 'react';
import { useSetRecoilState } from 'recoil';
import { useSocket } from 'src/api/use-socket';
import { displayIdAtom } from 'src/stores/NewRecoil';

export const SyncDisplayToRecoil: FC = () => {
const setDisplay = useSetRecoilState(displayIdAtom);
const [socket, connected] = useSocket();

useEffect(() => {
if (connected) {
socket?.on('DISPLAY', setDisplay);
}
}, [connected]);

useEffect(() => {
return () => {
socket?.removeListener('DISPLAY', setDisplay);
};
}, []);

return null;
};

0 comments on commit 1a74b49

Please sign in to comment.