diff --git a/actions.js b/actions.js index 20517c1..81702c6 100644 --- a/actions.js +++ b/actions.js @@ -678,6 +678,10 @@ export function gotSingleStudentAssignment(assignment) { } export function fetchSingleStudentAssignment({ slug, assignmentId }) { + if (!assignmentId) { + console.error('assignmentId is required'); + return; + } return (dispatch, getState) => { const { currentUser: { token }, diff --git a/pages/courses/[slug]/[piece]/[actCategory]/[partType]/index.js b/pages/courses/[slug]/[piece]/[actCategory]/[partType]/index.js index 44b4280..0a8e28a 100644 --- a/pages/courses/[slug]/[piece]/[actCategory]/[partType]/index.js +++ b/pages/courses/[slug]/[piece]/[actCategory]/[partType]/index.js @@ -39,15 +39,23 @@ export default function PerformMelody() { ); useEffect(() => { if (loadedActivities) { + let comparablePartType = partType; + if (comparablePartType.startsWith('Melody')) { + comparablePartType = comparablePartType.substring(0, 'Melody'.length) + } else if (comparablePartType.startsWith('Bassline')) { + comparablePartType = comparablePartType.substring(0, 'Bassline'.length) + } + const assignmentId = activities[slug].filter( + (assn) => + { + return assn.piece_slug === piece && + assn.part_type === comparablePartType && + assn.activity_type_category === actCategory} + )?.[0]?.id dispatch( fetchSingleStudentAssignment({ slug, - assignmentId: activities[slug].filter( - (assn) => - assn.piece_slug === piece && - assn.part_type === partType && - assn.activity_type_category === actCategory - )?.[0]?.id, + assignmentId, }) ); } diff --git a/pages/courses/[slug]/[piece]/[actCategory]/index.js b/pages/courses/[slug]/[piece]/[actCategory]/index.js index 4355060..e1aa1d6 100644 --- a/pages/courses/[slug]/[piece]/[actCategory]/index.js +++ b/pages/courses/[slug]/[piece]/[actCategory]/index.js @@ -31,14 +31,15 @@ export default function PerformMelody() { ); useEffect(() => { if (loadedActivities) { + const assignmentId = activities[slug].filter( + (assn) => + assn.piece_slug === piece && + (assn.activity_type_category === actCategory || assn.activity_type_category.split(' ')[0] === actCategory) + )?.[0]?.id; dispatch( fetchSingleStudentAssignment({ slug, - assignmentId: activities[slug].filter( - (assn) => - assn.piece_slug === piece && - assn.activity_type_category === actCategory - )?.[0]?.id, + assignmentId, }) ); }