|
1 |
| -import React, { useContext } from 'react'; |
| 1 | +import React, { useContext } from "react"; |
2 | 2 |
|
3 |
| -import hasIn from 'lodash/hasIn'; |
4 |
| -import { useSelector } from 'react-redux'; |
| 3 | +import hasIn from "lodash/hasIn"; |
| 4 | +import { useSelector } from "react-redux"; |
5 | 5 |
|
6 |
| -import RoomContext from '../../components/RoomContext'; |
7 |
| -import { roomMachineStates, replayerMachineStates } from '../../machines/game'; |
8 |
| -import { roomStateSelector } from '../../machines/selectors'; |
9 |
| -import * as selectors from '../../selectors'; |
10 |
| -import useMachineStateSelector from '../../utils/useMachineStateSelector'; |
11 |
| -import BackToTaskBuilderButton from '../builder/BackToTaskBuilderButton'; |
| 6 | +import RoomContext from "../../components/RoomContext"; |
| 7 | +import { roomMachineStates, replayerMachineStates } from "../../machines/game"; |
| 8 | +import { roomStateSelector } from "../../machines/selectors"; |
| 9 | +import * as selectors from "../../selectors"; |
| 10 | +import useMachineStateSelector from "../../utils/useMachineStateSelector"; |
| 11 | +import BackToTaskBuilderButton from "../builder/BackToTaskBuilderButton"; |
12 | 12 |
|
13 |
| -import ActionsAfterGame from './ActionsAfterGame'; |
14 |
| -import ApprovePlaybookButtons from './ApprovePlaybookButtons'; |
15 |
| -import BackToEventButton from './BackToEventButton'; |
16 |
| -import BackToHomeButton from './BackToHomeButton'; |
17 |
| -import BackToTournamentButton from './BackToTournamentButton'; |
18 |
| -import GameResult from './GameResult'; |
19 |
| -import GoToNextGame from './GoToNextGame'; |
20 |
| -import ReplayerControlButton from './ReplayerControlButton'; |
21 |
| -import VideoConferenceButton from './VideoConferenceButton'; |
| 13 | +import ActionsAfterGame from "./ActionsAfterGame"; |
| 14 | +import ApprovePlaybookButtons from "./ApprovePlaybookButtons"; |
| 15 | +import BackToEventButton from "./BackToEventButton"; |
| 16 | +import BackToHomeButton from "./BackToHomeButton"; |
| 17 | +import BackToTournamentButton from "./BackToTournamentButton"; |
| 18 | +import GameResult from "./GameResult"; |
| 19 | +import GoToNextGame from "./GoToNextGame"; |
| 20 | +import ReplayerControlButton from "./ReplayerControlButton"; |
| 21 | +import VideoConferenceButton from "./VideoConferenceButton"; |
22 | 22 |
|
23 | 23 | function Notifications() {
|
24 | 24 | const { mainService } = useContext(RoomContext);
|
25 |
| - const roomMachineState = useMachineStateSelector(mainService, roomStateSelector); |
| 25 | + const roomMachineState = useMachineStateSelector( |
| 26 | + mainService, |
| 27 | + roomStateSelector, |
| 28 | + ); |
26 | 29 |
|
27 | 30 | const { tournamentId } = useSelector(selectors.gameStatusSelector);
|
28 | 31 | const currentUserId = useSelector(selectors.currentUserIdSelector);
|
29 | 32 | const players = useSelector(selectors.gamePlayersSelector);
|
30 |
| - const playbookSolutionType = useSelector(state => state.playbook.solutionType); |
31 |
| - const tournamentsInfo = useSelector(state => state.game.tournamentsInfo); |
| 33 | + const playbookSolutionType = useSelector( |
| 34 | + (state) => state.playbook.solutionType, |
| 35 | + ); |
| 36 | + const tournamentsInfo = useSelector((state) => state.game.tournamentsInfo); |
32 | 37 | const tournament = useSelector(selectors.tournamentSelector);
|
33 | 38 | const isAdmin = useSelector(selectors.currentUserIsAdminSelector);
|
34 | 39 | const isCurrentUserPlayer = hasIn(players, currentUserId);
|
35 | 40 | const isTournamentGame = !!tournamentId;
|
36 | 41 | const isEventTournament = !!tournament?.eventId;
|
37 |
| - const isActiveTournament = !!tournamentsInfo && tournamentsInfo.state === 'active'; |
| 42 | + const isActiveTournament = |
| 43 | + !!tournamentsInfo && tournamentsInfo.state === "active"; |
38 | 44 |
|
39 | 45 | return (
|
40 | 46 | <>
|
41 |
| - {roomMachineState.matches({ room: roomMachineStates.testing }) && <BackToTaskBuilderButton />} |
42 |
| - {(isAdmin |
43 |
| - && !roomMachineState.matches({ replayer: replayerMachineStates.off }) |
44 |
| - && !roomMachineState.matches({ room: roomMachineStates.testing }) |
45 |
| - ) && <VideoConferenceButton />} |
| 47 | + {roomMachineState.matches({ room: roomMachineStates.testing }) && ( |
| 48 | + <BackToTaskBuilderButton /> |
| 49 | + )} |
| 50 | + {isAdmin && |
| 51 | + !roomMachineState.matches({ replayer: replayerMachineStates.off }) && |
| 52 | + !roomMachineState.matches({ room: roomMachineStates.testing })} |
46 | 53 | <ReplayerControlButton />
|
47 |
| - {(isCurrentUserPlayer && roomMachineState.matches({ room: roomMachineStates.gameOver })) |
48 |
| - && ( |
| 54 | + {isCurrentUserPlayer && |
| 55 | + roomMachineState.matches({ room: roomMachineStates.gameOver }) && ( |
49 | 56 | <>
|
50 | 57 | <GameResult />
|
51 | 58 | <ActionsAfterGame />
|
52 | 59 | </>
|
53 | 60 | )}
|
54 |
| - {(isAdmin && !roomMachineState.matches({ replayer: replayerMachineStates.off })) && ( |
55 |
| - <> |
56 |
| - <ApprovePlaybookButtons playbookSolutionType={playbookSolutionType} /> |
57 |
| - </> |
| 61 | + {isAdmin && |
| 62 | + !roomMachineState.matches({ replayer: replayerMachineStates.off }) && ( |
| 63 | + <> |
| 64 | + <ApprovePlaybookButtons |
| 65 | + playbookSolutionType={playbookSolutionType} |
| 66 | + /> |
| 67 | + </> |
| 68 | + )} |
| 69 | + {isTournamentGame && isActiveTournament && ( |
| 70 | + <GoToNextGame |
| 71 | + tournamentsInfo={tournamentsInfo} |
| 72 | + currentUserId={currentUserId} |
| 73 | + /> |
58 | 74 | )}
|
59 |
| - {isTournamentGame && isActiveTournament |
60 |
| - && <GoToNextGame tournamentsInfo={tournamentsInfo} currentUserId={currentUserId} />} |
61 | 75 | {isTournamentGame && !isEventTournament && <BackToTournamentButton />}
|
62 |
| - {isTournamentGame && isEventTournament && <BackToEventButton eventId={tournament?.eventId} />} |
63 |
| - {!isTournamentGame && !roomMachineState.matches({ room: roomMachineStates.testing }) |
64 |
| - && <BackToHomeButton />} |
| 76 | + {isTournamentGame && isEventTournament && ( |
| 77 | + <BackToEventButton eventId={tournament?.eventId} /> |
| 78 | + )} |
| 79 | + {!isTournamentGame && |
| 80 | + !roomMachineState.matches({ room: roomMachineStates.testing }) && ( |
| 81 | + <BackToHomeButton /> |
| 82 | + )} |
65 | 83 | </>
|
66 | 84 | );
|
67 | 85 | }
|
|
0 commit comments