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

Refactor h5pProgress. Move to h5p src/react/context/h5p.tsx #254

Open
qunabu opened this issue Apr 17, 2023 · 0 comments
Open

Refactor h5pProgress. Move to h5p src/react/context/h5p.tsx #254

qunabu opened this issue Apr 17, 2023 · 0 comments
Assignees

Comments

@qunabu
Copy link
Contributor

qunabu commented Apr 17, 2023

};
}
return prItem;
}) || [
{
topic_id: topicId,
status: API.CourseProgressItemElementStatus.COMPLETE,
},
]
);
}
}
return token
? postSendh5pProgress.bind(null, apiUrl)(
topicId,
statementId,
statement,
token
)
: null;
},
[token, progress, courseProgressDetails]
);
const topicPing = useCallback(
(topicId: number) => {
return token
? putTopicPing
.bind(null, apiUrl)(topicId, token)
.catch((err) => err)
: Promise.reject("noToken");
},
[token]
);
const progressMap = useMemo(() => {
const defaultMap: {
coursesProcProgress: Record<number, number>;
finishedTopics: number[];
} = {
coursesProcProgress: {},
finishedTopics: [],
};
if (progress.value) {
progress.value.reduce((acc, course) => {
acc.coursesProcProgress[
typeof course.course.id === "number" ? course.course.id : 0
] =
course.progress.reduce((sum, item) => sum + item.status, 0) /
course.progress.length;
acc.finishedTopics = acc.finishedTopics.concat(
course.progress
.filter(
(item) =>
item.status === API.CourseProgressItemElementStatus.COMPLETE
)
.map((item) => item.topic_id)
);
return acc;
}, defaultMap);
}
return defaultMap;
}, [progress]);
const topicIsFinished = useCallback(
(topicId: number) => {
if (progressMap && progressMap.finishedTopics.includes(topicId)) {
return true;
}
// fetch by
return false;
},
[progressMap]
);
const courseProgress = useCallback(
(courseId: number) =>
progressMap && progressMap.coursesProcProgress[courseId]
? progressMap.coursesProcProgress[courseId]
: 0,
[progressMap]
);
// TODO: this should be refactored, since lessons are not flat structure any more
const getNextPrevTopic = useCallback(
(topicId: number, next: boolean = true) => {

@Haxikowy Haxikowy removed their assignment May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants