-
Notifications
You must be signed in to change notification settings - Fork 110
[Horizon] Learn screen redesign #3518
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
Changes from all commits
11268e3
acc019a
d0954a6
2800588
bfef1fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| query HorizonGetCourseById($courseId: ID!, $userId: ID!) { | ||
| legacyNode(_id: $courseId, type: Course) { | ||
| ... on Course { | ||
| id: _id | ||
| name | ||
| image_download_url: imageUrl | ||
| syllabus_body: syllabusBody | ||
| usersConnection(filter: {userIds: [$userId]}) { | ||
| nodes { | ||
| courseProgression { | ||
| requirements { | ||
| completionPercentage | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: Missing newline at end of file This file should end with a newline character per standard conventions. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package com.instructure.canvasapi2.managers.graphql.horizon | |
| import com.apollographql.apollo.ApolloClient | ||
| import com.apollographql.apollo.api.Optional | ||
| import com.instructure.canvasapi2.GetCoursesQuery | ||
| import com.instructure.canvasapi2.HorizonGetCourseByIdQuery | ||
| import com.instructure.canvasapi2.HorizonGetProgramCourseByIdQuery | ||
| import com.instructure.canvasapi2.QLClientConfig | ||
| import com.instructure.canvasapi2.enqueueQuery | ||
|
|
@@ -29,6 +30,8 @@ import java.util.Date | |
| interface HorizonGetCoursesManager { | ||
| suspend fun getCoursesWithProgress(userId: Long, forceNetwork: Boolean = false): DataResult<List<CourseWithProgress>> | ||
|
|
||
| suspend fun getCourseWithProgressById(courseId: Long, userId: Long, forceNetwork: Boolean = false): DataResult<CourseWithProgress> | ||
|
|
||
| suspend fun getEnrollments(userId: Long, forceNetwork: Boolean = false): DataResult<List<GetCoursesQuery.Enrollment>> | ||
|
|
||
| suspend fun getProgramCourses(courseId: Long, forceNetwork: Boolean = false): DataResult<CourseWithModuleItemDurations> | ||
|
|
@@ -50,14 +53,38 @@ class HorizonGetCoursesManagerImpl(private val apolloClient: ApolloClient): Hori | |
| } | ||
| } | ||
|
|
||
| override suspend fun getCourseWithProgressById(courseId: Long, userId: Long, forceNetwork: Boolean): DataResult<CourseWithProgress> { | ||
| return try { | ||
| val query = HorizonGetCourseByIdQuery(courseId.toString(), userId.toString()) | ||
| val result = apolloClient.enqueueQuery(query, forceNetwork).dataAssertNoErrors | ||
|
|
||
| val progress = result.legacyNode?.onCourse?.usersConnection?.nodes?.firstOrNull()?.courseProgression?.requirements?.completionPercentage ?: 0.0 | ||
| val courseId = result.legacyNode?.onCourse?.id?.toLongOrNull() ?: -1L | ||
| val courseName = result.legacyNode?.onCourse?.name ?: "" | ||
| val courseSyllabus = result.legacyNode?.onCourse?.syllabus_body ?: "" | ||
| val imageUrl = result.legacyNode?.onCourse?.image_download_url ?: "" | ||
| val course = CourseWithProgress(courseId, courseName, imageUrl, courseSyllabus, progress) | ||
|
|
||
| return DataResult.Success(course) | ||
| } catch (e: Exception) { | ||
| DataResult.Fail(Failure.Exception(e)) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential bug: Returning success with invalid data when course not found The current implementation uses Consider checking if the course data is valid and returning a failure result when not found: val course = result.legacyNode?.onCourse
if (course?.id == null) {
return DataResult.Fail()
}
val courseId = course.id.toLongOrNull() ?: return DataResult.Fail()
val courseName = course.name ?: ""
val courseImageUrl = course.courseImage?.url ?: ""
CourseWithProgress(
courseId = courseId,
courseName = courseName,
courseCode = course.courseCode ?: "",
courseImageUrl = courseImageUrl,
courseProgress = result.progress?.let {
CourseProgress(
requirementCount = it.requirementCount ?: 0,
requirementCompletedCount = it.requirementCompletedCount ?: 0,
nextRequirementUrl = it.nextRequirement?.htmlUrl ?: "",
completedAt = it.completedAt
)
}
) |
||
| } | ||
|
|
||
| private fun mapCourse(course: GetCoursesQuery.Course?): CourseWithProgress? { | ||
| val progress = course?.usersConnection?.nodes?.firstOrNull()?.courseProgression?.requirements?.completionPercentage ?: 0.0 | ||
| val courseId = course?.id?.toLong() | ||
| val courseName = course?.name | ||
| val courseSyllabus = course?.syllabus_body | ||
| val imageUrl = course?.image_download_url | ||
|
|
||
| return if (courseId != null && courseName != null) { | ||
| CourseWithProgress(courseId, courseName, courseSyllabus, progress) | ||
| CourseWithProgress( | ||
| courseId, | ||
| courseName, | ||
| imageUrl, | ||
| courseSyllabus, | ||
| progress) | ||
| } else { | ||
| null | ||
| } | ||
|
|
@@ -113,7 +140,8 @@ class HorizonGetCoursesManagerImpl(private val apolloClient: ApolloClient): Hori | |
| data class CourseWithProgress( | ||
| val courseId: Long, | ||
| val courseName: String, | ||
| val courseSyllabus: String? = null, | ||
| val courseImageUrl: String?, | ||
| val courseSyllabus: String?, | ||
| val progress: Double, | ||
| ) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Route handling for Horizon feature
This adds routing logic to direct users to
HorizonActivitywhen the career view flag is enabled.Please ensure:
ROUTE_HORIZON_CAREER_COURSE_ID, etc.) are properly validatedApiPrefs.canvasCareerViewchanges state while the app is running