From 280e4c970cc540cac77e4dab2f4270a85bfbddb0 Mon Sep 17 00:00:00 2001 From: Kostya Bats Date: Wed, 19 Jul 2023 14:32:09 +0300 Subject: [PATCH] admin: achievement and status switches in teamview --- .../admin/src/components/TeamTable.js | 1 + src/frontend/admin/src/components/TeamView.js | 322 ++++++++++-------- .../admin/src/services/teamViewWidget.js | 4 + 3 files changed, 187 insertions(+), 140 deletions(-) diff --git a/src/frontend/admin/src/components/TeamTable.js b/src/frontend/admin/src/components/TeamTable.js index 083e267cf..311af6095 100644 --- a/src/frontend/admin/src/components/TeamTable.js +++ b/src/frontend/admin/src/components/TeamTable.js @@ -164,6 +164,7 @@ TeamViewSettingsPanel.propTypes = { isSomethingSelected: PropTypes.bool, canShow: PropTypes.bool, // todo: make req isPossibleToHide: PropTypes.bool, + showHideButton: PropTypes.bool, canHide: PropTypes.bool, // todo: make req onShowTeam: PropTypes.func.isRequired, onHideTeam: PropTypes.func, diff --git a/src/frontend/admin/src/components/TeamView.js b/src/frontend/admin/src/components/TeamView.js index a94e2bba2..0820eab54 100644 --- a/src/frontend/admin/src/components/TeamView.js +++ b/src/frontend/admin/src/components/TeamView.js @@ -12,13 +12,16 @@ import { Tooltip, Switch, TextField, - styled, InputAdornment, FormLabel, + FormControl, + FormControlLabel, + ThemeProvider, + createTheme, } from "@mui/material"; import { useSnackbar } from "notistack"; import { errorHandlerWithSnackbar } from "../errors"; -import { useTeamViewService } from "../services/teamViewWidget"; +import { TeamViewService, useTeamViewService } from "../services/teamViewWidget"; import SingleTeamViewIcon from "@mui/icons-material/WebAsset"; import PVPTeamViewIcon from "@mui/icons-material/Splitscreen"; import SplitTeamViewIcon from "@mui/icons-material/GridView"; @@ -80,23 +83,44 @@ const useTeamsList = (rawTeams, status) => { return { teams: filteredTeams, selectedTeamId, setSelectedTeamId, searchValue, setSearchValue }; }; -const TEAMVIEW_INSTANCES = [ - { id: null, title: "single", icon: null }, - { id: "PVP_TOP", title: "PVP", icon: }, - { id: "PVP_BOTTOM", title: "PVP", icon: }, - { id: "TOP_LEFT", title: "SplitScreen", icon: }, - { id: "TOP_RIGHT", title: "SplitScreen", icon: }, - { id: "BOTTOM_LEFT", title: "SplitScreen", icon: }, - { id: "BOTTOM_RIGHT", title: "SplitScreen", icon: }, -]; +const teamViewTheme = createTheme({ + components: { + MuiPaper: { + styleOverrides: { + root: ({ theme }) => ({ + padding: theme.spacing(2), + marginBottom: theme.spacing(1), + }), + }, + }, + MuiButton: { + defaultProps: { + size: "small", + }, + }, + MuiButtonGroup: { + defaultProps: { + size: "small", + }, + }, + MuiButtonBase: { + styleOverrides: { + root: { + margin: "0 !important", + }, + }, + }, + }, +}); const VariantSelect = ({ variant, setVariant }) => { return ( setVariant(v)} + onChange={(_, v) => v && setVariant(v)} > Single PVP @@ -105,30 +129,31 @@ const VariantSelect = ({ variant, setVariant }) => { ); }; -const InstanceStatusCard = styled(Paper)(({ theme }) => ({ - padding: theme.spacing(2), - marginBottom: theme.spacing(1), -})); +VariantSelect.propTypes = { + variant: PropTypes.oneOf(["single", "pvp", "splitScreen"]).isRequired, + setVariant: PropTypes.func.isRequired, +}; -const InstanceStatus = ({ instanceId, Icon, status, teams, canShow, isSelected, onShow, onHide }) => { +const InstanceStatus = ({ instanceId, Icon, status, teams, selectedInstance, onShow, onHide }) => { const iStatus = status[instanceId]; const shownTeam = useMemo( () => teams.find(t => t.id === iStatus?.settings?.teamId), [teams, status]); + const isShowButtonDisabled = !(selectedInstance === instanceId || selectedInstance === undefined); return ( - + {Icon && } - Team: {shownTeam?.name ?? "Auto"} Media: {iStatus?.settings?.mediaTypes?.join(", ")} - + ); }; @@ -137,8 +162,7 @@ InstanceStatus.propTypes = { Icon: PropTypes.elementType.isRequired, status: PropTypes.object.isRequired, teams: PropTypes.arrayOf(TEAM_FIELD_STRUCTURE).isRequired, - canShow: PropTypes.func.isRequired, - isSelected: PropTypes.func.isRequired, + selectedInstance: PropTypes.string, onShow: PropTypes.func.isRequired, onHide: PropTypes.func.isRequired, }; @@ -185,8 +209,7 @@ InstancesManager.propTypes = { Icon: PropTypes.node, status: PropTypes.object.isRequired, teams: PropTypes.arrayOf(TEAM_FIELD_STRUCTURE).isRequired, - canShow: PropTypes.func.isRequired, - isSelected: PropTypes.func.isRequired, + selectedInstance: PropTypes.string, onShow: PropTypes.func.isRequired, onHide: PropTypes.func.isRequired, }; @@ -195,12 +218,15 @@ const TeamViewInstanceStatus = ({ instanceName, status, teams }) => { const shownTeam = useMemo( () => teams.find(t => t.id === status.settings.teamId), [teams, status]); - return ( - Instance {instanceName ?? "SINGLE"} {status.shown && "shown"} - Team: {shownTeam?.name ?? "Auto"} - Media: {status.settings.mediaTypes?.join(", ")} - ); + return ( + + Instance {instanceName ?? "SINGLE"} {status.shown && "shown"} + Team: {shownTeam?.name ?? "Auto"} + Media: {status.settings.mediaTypes?.join(", ")} + + ); }; + TeamViewInstanceStatus.propTypes = { instanceName: PropTypes.any, status: PropTypes.shape({ @@ -210,16 +236,19 @@ TeamViewInstanceStatus.propTypes = { mediaTypes: PropTypes.arrayOf(PropTypes.string.isRequired), }).isRequired, }).isRequired, - teams: PropTypes.arrayOf(TEAM_FIELD_STRUCTURE), + teams: PropTypes.arrayOf(TEAM_FIELD_STRUCTURE).isRequired, }; const MultipleModeSwitch = ({ currentService, setIsMultipleMode }) => { return ( + + Mulitple mode + setIsMultipleMode(newV)} /> - - - } - + + + + + + )} + } ); }; +TeamViewManager.propTypes = { + singleService: PropTypes.instanceOf(TeamViewService).isRequired, + pvpService: PropTypes.instanceOf(TeamViewService).isRequired, + splitService: PropTypes.instanceOf(TeamViewService).isRequired, +}; + + function TeamView() { const { enqueueSnackbar, } = useSnackbar(); - const service = useTeamViewService("singe", errorHandlerWithSnackbar(enqueueSnackbar)); + const service = useTeamViewService("single", errorHandlerWithSnackbar(enqueueSnackbar)); const pvpService = useTeamViewService("pvp", errorHandlerWithSnackbar(enqueueSnackbar)); const splitService = useTeamViewService("splitScreen", errorHandlerWithSnackbar(enqueueSnackbar)); return ( - + + + ); } diff --git a/src/frontend/admin/src/services/teamViewWidget.js b/src/frontend/admin/src/services/teamViewWidget.js index 2d64c91c7..4fc82a79c 100644 --- a/src/frontend/admin/src/services/teamViewWidget.js +++ b/src/frontend/admin/src/services/teamViewWidget.js @@ -16,6 +16,7 @@ export class TeamViewService extends AbstractWidgetService { constructor(variant, errorHandler, listenWS = true) { const [instances, apiPath] = getTeamViewVariantParams(variant); super("/" + apiPath, errorHandler, listenWS); + this.variant = variant; this.instances = instances; } @@ -28,6 +29,9 @@ export class TeamViewService extends AbstractWidgetService { } loadElements() { + if (this.variant === "single") { + return this.apiGet("").then(r => ({ [null]: r })).catch(this.errorHandler("Failed to load status")); + } return this.apiGet("").catch(this.errorHandler("Failed to load status")); }