-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #762 from rage/progress-update-fix
Progress update fix
- Loading branch information
Showing
3 changed files
with
116 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
packages/moocfi-quizzes/src/contexes/courseProgressProviderContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React, { createContext, useContext, useReducer } from "react" | ||
|
||
import { ProviderBaseInterface } from "./courseStatusProviderContext" | ||
import { PointsByGroup } from "../modelTypes" | ||
|
||
export interface ProgressResponse { | ||
user_course_progressess: UserCourseProgress | ||
completions: Completion[] | ||
} | ||
|
||
export interface CourseResponse { | ||
exercises: Omit<Exercise, "exercise_completions">[] | ||
} | ||
|
||
export interface UserCourseProgress { | ||
max_points: number | ||
n_points: number | ||
progress: PointsByGroup[] | ||
course: Course | ||
} | ||
|
||
export interface Completion { | ||
id: string | ||
} | ||
|
||
export interface Course { | ||
points_needed: number | ||
exercises: Exercise[] | ||
} | ||
|
||
export type Exercise = { | ||
id: string | ||
quizzes_id: string | ||
name: string | ||
part: number | ||
section: number | ||
max_points: number | ||
exercise_completions: ExerciseCompletion[] | ||
} | ||
|
||
export type ExerciseCompletion = { | ||
exercise_id: string | ||
exercise_quizzes_id: string | ||
part: number | ||
section: number | ||
n_points: number | ||
completed: boolean | ||
exercise_completion_required_actions: RequiredActionObject[] | ||
} | ||
|
||
export interface ExerciseCompletionsBySection { | ||
part: number | ||
section: number | ||
exercises_total: number | ||
exercises_completed: number | ||
required_actions: RequiredAction[] | ||
} | ||
|
||
export interface RequiredActionObject { | ||
value: RequiredAction | ||
} | ||
|
||
export enum RequiredAction { | ||
REJECTED = "REJECTED", | ||
GIVE_PEER_REVIEW = "GIVE_PEER_REVIEW", | ||
PENDING_PEER_REVIEW = "PENDING_PEER_REVIEW", | ||
} | ||
|
||
export interface ProgressData { | ||
completed: boolean | ||
points_to_pass: number | ||
n_points: number | ||
max_points: number | ||
exercise_completions: number | ||
total_exercises: number | ||
required_actions: RequiredAction[] | ||
progress: PointsByGroup[] | ||
exercises: Exercise[] | ||
answers: ExerciseCompletion[] | ||
exercise_completions_by_section: ExerciseCompletionsBySection[] | ||
} | ||
|
||
export interface CourseProgressProviderInterface extends ProviderBaseInterface { | ||
error?: boolean | ||
loading?: boolean | ||
courseProgressData?: ProgressData | ||
courseId?: string | ||
accessToken?: string | ||
} | ||
|
||
interface CourseProgressProviderContextInterface { | ||
progress: CourseProgressProviderInterface | ||
fetchProgressData: () => Promise<void> | ||
} | ||
|
||
export const CourseProgressProviderContext = createContext< | ||
CourseProgressProviderContextInterface | ||
>({ progress: {}, fetchProgressData: () => Promise.resolve() }) |
Oops, something went wrong.