Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution to issue #497 #506

Merged
merged 5 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions web/src/components/VolumeZones/VolumeZones.jsx
Original file line number Diff line number Diff line change
@@ -1,34 +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 }) => {
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 = [];
for (const group of usedGroups) {
for (const group of groups) {
groupVolumeSliders.push(
<Card className="group-vol-card" key={group.id}>
<GroupVolumeSlider
Expand All @@ -41,23 +21,29 @@ const VolumeZones = ({ sourceId }) => {
}

const zoneVolumeSliders = [];
zonesLeft.forEach((zone) => {
zones.forEach((zone) => {
zoneVolumeSliders.push(
<Card className="zone-vol-card" key={zone.id}>
<ZoneVolumeSlider zoneId={zone.id} />
</Card>
);
});

return (
<div className="volume-sliders-container">
{groupVolumeSliders}
{zoneVolumeSliders}
</div>
);
if(open){
return (
<div className="volume-sliders-container">
{groupVolumeSliders}
{zoneVolumeSliders}
</div>
);
}
};
VolumeZones.propTypes = {
sourceId: PropTypes.any.isRequired,
open: PropTypes.bool.isRequired,
zones: PropTypes.array.isRequired,
groups: PropTypes.array.isRequired,
groupsLeft: PropTypes.array.isRequired,
};

export default VolumeZones;
29 changes: 25 additions & 4 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 @@ -31,7 +34,25 @@ const Player = () => {
<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 All @@ -47,7 +68,7 @@ const Player = () => {
<MediaControl selectedSource={selectedSourceId} />
</div>

<Card className="player-volume-slider">
{!alone && <Card className="player-volume-slider">
<CardVolumeSlider sourceId={selectedSourceId} />
<IconButton onClick={() => setExpanded(!expanded)}>
{expanded ? (
Expand All @@ -62,8 +83,8 @@ const Player = () => {
/>
)}
</IconButton>
</Card>
{expanded && <VolumeZones sourceId={selectedSourceId} />}
</Card>}
<VolumeZones open={(expanded || alone)} sourceId={selectedSourceId} zones={zonesLeft} groups={usedGroups} groupsLeft={groupsLeft} />
</div>
);
};
Expand Down
1 change: 0 additions & 1 deletion web/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import path from "path"
import process from 'node:process';

// set this to dev server url; this permits one to develop on localhost while
// proxying API requests to an AmpliPi running elsewhere.
const amplipiurl = process.env.AMPLIPI_URL || "http://127.0.0.1";
Expand Down