Skip to content

Commit

Permalink
chore: Limit the number of CTAs on the Primary Card (#34)
Browse files Browse the repository at this point in the history
Displays a dynamic list of primary course buttons, managing up to
four views: Due, Future, Upgrade, and Resume. Views are shown in
priority order: Due, Future, Upgrade, and Resume.

If all four views are available, the Future view is removed to ensure
a maximum of three buttons are displayed. Any unavailable views are
omitted from the list, maintaining the defined priority.

Fixes: LEARNER-10139
  • Loading branch information
HamzaIsrar12 authored Aug 19, 2024
1 parent e58517f commit 648640f
Showing 1 changed file with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,21 +665,11 @@ private fun PrimaryCourseButtons(
onIAPAction: (IAPAction, EnrolledCourse?, IAPException?) -> Unit = { _, _, _ -> },
) {
val context = LocalContext.current
val viewsList = mutableListOf<@Composable () -> Unit>()

val pastAssignments = primaryCourse.courseAssignments?.pastAssignments
Column(modifier = modifier) {
var titleModifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.padding(top = 8.dp, bottom = 16.dp)
if (adjustHeight) {
titleModifier = titleModifier.weight(1f)
}
PrimaryCourseTitle(
modifier = titleModifier,
primaryCourse = primaryCourse,
)
Divider()
if (!pastAssignments.isNullOrEmpty()) {
if (!pastAssignments.isNullOrEmpty()) {
viewsList.add {
val nearestAssignment = pastAssignments.maxBy { it.date }
val title = if (pastAssignments.size == 1) nearestAssignment.title else null
AssignmentItem(
Expand All @@ -699,11 +689,13 @@ private fun PrimaryCourseButtons(
)
)
}
val futureAssignments = primaryCourse.courseAssignments?.futureAssignments
if (!futureAssignments.isNullOrEmpty()) {
}

val futureAssignments = primaryCourse.courseAssignments?.futureAssignments
if (!futureAssignments.isNullOrEmpty()) {
viewsList.add {
val nearestAssignment = futureAssignments.minBy { it.date }
val title = if (futureAssignments.size == 1) nearestAssignment.title else null
Divider()
AssignmentItem(
modifier = Modifier.clickable {
if (futureAssignments.size == 1) {
Expand All @@ -721,7 +713,10 @@ private fun PrimaryCourseButtons(
)
)
}
if (primaryCourse.isUpgradeable && isIAPEnabled) {
}

if (primaryCourse.isUpgradeable && isIAPEnabled) {
viewsList.add {
UpgradeToAccessView(
type = UpgradeToAccessViewType.GALLERY,
iconPadding = PaddingValues(end = 12.dp),
Expand All @@ -734,6 +729,9 @@ private fun PrimaryCourseButtons(
)
}
}
}

viewsList.add {
ResumeButton(
primaryCourse = primaryCourse,
onClick = {
Expand All @@ -748,6 +746,30 @@ private fun PrimaryCourseButtons(
}
)
}

// Remove Future Assignments if all buttons are available to show a maximum of three buttons.
if (viewsList.size == 4) {
viewsList.removeAt(1)
}

Column(modifier = modifier) {
var titleModifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.padding(top = 8.dp, bottom = 16.dp)
if (adjustHeight) {
titleModifier = titleModifier.weight(1f)
}

PrimaryCourseTitle(
modifier = titleModifier,
primaryCourse = primaryCourse,
)
viewsList.forEach { view ->
Divider()
view()
}
}
}

@Composable
Expand Down

0 comments on commit 648640f

Please sign in to comment.