Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
don't make this api call unless the params are available. fixed the r…
Browse files Browse the repository at this point in the history
…eason it was undefined
  • Loading branch information
hcientist committed Mar 15, 2024
1 parent 78d7329 commit 89cfbfe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
20 changes: 14 additions & 6 deletions pages/courses/[slug]/[piece]/[actCategory]/[partType]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
}
Expand Down
11 changes: 6 additions & 5 deletions pages/courses/[slug]/[piece]/[actCategory]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
}
Expand Down

0 comments on commit 89cfbfe

Please sign in to comment.