Skip to content

Commit

Permalink
Fix as per Jonah's request:
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMicroNova committed Sep 1, 2023
1 parent e4b7409 commit ab4802d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
36 changes: 6 additions & 30 deletions web/src/components/VolumeZones/VolumeZones.jsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
import React from "react";
import "./VolumesZones.scss";
import { useStatusStore } from "@/App.jsx";
import { getSourceZones } from "@/pages/Home/Home";
import ZoneVolumeSlider from "../ZoneVolumeSlider/ZoneVolumeSlider";
import GroupVolumeSlider from "../GroupVolumeSlider/GroupVolumeSlider";
import Card from "../Card/Card";

import { getFittestRep } from "@/utils/GroupZoneFiltering";

import PropTypes from "prop-types";

const VolumeZones = ({ sourceId, open, setAlone }) => {
const zones = getSourceZones(
sourceId,
useStatusStore((s) => s.status.zones)
);
const groups = getSourceZones(
sourceId,
useStatusStore((s) => s.status.groups)
);

// compute the best representation of the zones and groups
const { zones: zonesLeft, groups: usedGroups } = getFittestRep(zones, groups);

const groupsLeft = groups.filter(
(g) => !usedGroups.map((ug) => ug.id).includes(g.id)
);

const VolumeZones = ({ sourceId, open, zones, groups, groupsLeft }) => {
const groupVolumeSliders = [];
// This is a bootleg XOR statement, only works if there is exactly one zone or exactly one group, no more than that and not both
if(((usedGroups.length == 1) || (zonesLeft.length == 1)) && !((usedGroups.length > 0) && (zonesLeft.length > 0))){
setAlone(true);
} else {
setAlone(false);
}
for (const group of usedGroups) {
for (const group of groups) {
groupVolumeSliders.push(
<Card className="group-vol-card" key={group.id}>
<GroupVolumeSlider
Expand All @@ -47,7 +21,7 @@ const VolumeZones = ({ sourceId, open, setAlone }) => {
}

const zoneVolumeSliders = [];
zonesLeft.forEach((zone) => {
zones.forEach((zone) => {
zoneVolumeSliders.push(
<Card className="zone-vol-card" key={zone.id}>
<ZoneVolumeSlider zoneId={zone.id} />
Expand All @@ -67,7 +41,9 @@ const VolumeZones = ({ sourceId, open, setAlone }) => {
VolumeZones.propTypes = {
sourceId: PropTypes.any.isRequired,
open: PropTypes.bool.isRequired,
setAlone: PropTypes.func.isRequired,
zones: PropTypes.array.isRequired,
groups: PropTypes.array.isRequired,
groupsLeft: PropTypes.array.isRequired,
};

export default VolumeZones;
26 changes: 23 additions & 3 deletions web/src/pages/Player/Player.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { useState } from "react";
import VolumeZones from "@/components/VolumeZones/VolumeZones";
import Card from "@/components/Card/Card";
import { getSourceInputType } from "@/utils/getSourceInputType";
import { getSourceZones } from "@/pages/Home/Home";

import { getFittestRep } from "@/utils/GroupZoneFiltering";

const Player = () => {
const selectedSourceId = usePersistentStore((s) => s.selectedSource);
Expand All @@ -24,15 +27,32 @@ const Player = () => {
);
const sourceIsInactive = getSourceInputType(selectedSource) === "none";
const [expanded, setExpanded] = useState(false);
const [alone, setAlone] = useState(false);

if (sourceIsInactive) {
return (
<div className="player-outer">
<div className="player-stopped-message">No Player Selected!</div>
</div>
);
}
};

const zones = getSourceZones(
selectedSourceId,
useStatusStore((s) => s.status.zones)
);
const groups = getSourceZones(
selectedSourceId,
useStatusStore((s) => s.status.groups)
);

// compute the best representation of the zones and groups
const { zones: zonesLeft, groups: usedGroups } = getFittestRep(zones, groups);

const groupsLeft = groups.filter(
(g) => !usedGroups.map((ug) => ug.id).includes(g.id)
);
// This is a bootleg XOR statement, only works if there is exactly one zone or exactly one group, no more than that and not both
const alone = ((usedGroups.length == 1) || (zonesLeft.length == 1)) && !((usedGroups.length > 0) && (zonesLeft.length > 0));

return (
<div className="player-outer">
Expand Down Expand Up @@ -64,7 +84,7 @@ const Player = () => {
)}
</IconButton>
</Card>}
<VolumeZones open={(expanded || alone)} setAlone={setAlone} sourceId={selectedSourceId} />
<VolumeZones open={(expanded || alone)} sourceId={selectedSourceId} zones={zonesLeft} groups={usedGroups} groupsLeft={groupsLeft} />
</div>
);
};
Expand Down

0 comments on commit ab4802d

Please sign in to comment.