Skip to content

Commit 21624cc

Browse files
committed
use sample for instrument when available
1 parent 50ba66a commit 21624cc

File tree

1 file changed

+15
-1
lines changed
  • pages/courses/[slug]/[piece]/[actCategory]/[partType]

1 file changed

+15
-1
lines changed

pages/courses/[slug]/[piece]/[actCategory]/[partType]/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default function PerformMelody() {
2323
const { slug, piece, actCategory, partType } = router.query;
2424
const dispatch = useDispatch();
2525
const [parsedScore, setParsedScore] = useState();
26+
const [preferredSample, setPreferredSample] = useState();
2627

2728
const userInfo = useSelector((state) => state.currentUser);
2829
useEffect(() => {
@@ -67,6 +68,19 @@ export default function PerformMelody() {
6768
if (score) {
6869
setParsedScore(JSON.parse(score));
6970
}
71+
72+
// if there's an instrument_sample for the student's instrument, use that,
73+
// otherwise use the sample from the part
74+
const myInstrumentId = assignment?.instrument?.id ?? userInfo.instrument;
75+
const instrumentSample = assignment?.part?.instrument_samples?.find(
76+
(instrument) => instrument.instrument === myInstrumentId,
77+
);
78+
if (instrumentSample) {
79+
setPreferredSample(instrumentSample.sample_audio);
80+
} else {
81+
setPreferredSample(assignment?.part?.sample_audio);
82+
}
83+
console.log('preferredSample', preferredSample);
7084
}, [assignment]);
7185

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

0 commit comments

Comments
 (0)