Skip to content

Commit

Permalink
use sample for instrument when available
Browse files Browse the repository at this point in the history
  • Loading branch information
hcientist committed Oct 27, 2024
1 parent 50ba66a commit 21624cc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pages/courses/[slug]/[piece]/[actCategory]/[partType]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function PerformMelody() {
const { slug, piece, actCategory, partType } = router.query;
const dispatch = useDispatch();
const [parsedScore, setParsedScore] = useState();
const [preferredSample, setPreferredSample] = useState();

const userInfo = useSelector((state) => state.currentUser);
useEffect(() => {
Expand Down Expand Up @@ -67,6 +68,19 @@ export default function PerformMelody() {
if (score) {
setParsedScore(JSON.parse(score));
}

// if there's an instrument_sample for the student's instrument, use that,
// otherwise use the sample from the part
const myInstrumentId = assignment?.instrument?.id ?? userInfo.instrument;
const instrumentSample = assignment?.part?.instrument_samples?.find(
(instrument) => instrument.instrument === myInstrumentId,
);
if (instrumentSample) {
setPreferredSample(instrumentSample.sample_audio);
} else {
setPreferredSample(assignment?.part?.sample_audio);
}
console.log('preferredSample', preferredSample);
}, [assignment]);

// TODO: maybe I should let studentAssignment render anyway but then handle missing things at a lower level
Expand Down Expand Up @@ -95,7 +109,7 @@ export default function PerformMelody() {
<dd>
{
// eslint-disable-next-line jsx-a11y/media-has-caption
<audio controls src={assignment.part.sample_audio} />
<audio controls src={preferredSample} />
}
</dd>
</dl>
Expand Down

0 comments on commit 21624cc

Please sign in to comment.