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

feat: App Level Webview/No Internet Error Handling #357

Conversation

farhan-arshad-dev
Copy link
Contributor

Description

  • Not Internet Error Handling with reload CTA
  • Unknown error while loading the web page with reload CTA.

fixes: LEARNER-10046

Unknown error on web-page load No Internet Connection (Reuse)
Screenshot_20240704_113753 Screenshot_20240705_120819

Copy link
Contributor

@omerhabib26 omerhabib26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor code changes and improvements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the file name
core_ic_unknown_error.xml

) {
ErrorScreen(
modifier = modifier,
title = stringResource(id = R.string.core_no_internet_connection),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can create an EnumClass for these types.


enum class ErrorType(
    val iconResId: Int = 0,
    val titleResId: Int = 0,
    val descriptionResId: Int = 0,
    val actionResId: Int = 0,
) {
    CONNECTION_ERROR(
        iconResId = R.drawable.core_no_internet_connection,
        titleResId = R.string.core_no_internet_connection,
        descriptionResId = R.string.core_no_internet_connection_description,
        actionResId = R.string.core_reload,
    ),
    UNKNOWN_ERROR(
        iconResId = R.drawable.core_unkown,
        titleResId = R.string.core_try_again,
        descriptionResId = R.string.core_something_went_wrong_description,
        actionResId = R.string.core_reload,
    ),
}

@@ -88,6 +90,10 @@ class HtmlUnitFragment : Fragment() {
mutableStateOf(true)
}

var isError by remember {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move this in ViewModel

hasInternetConnection = viewModel.isOnline
}
if (!hasInternetConnection) {
ConnectionErrorView(
modifier = Modifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move the modifier inside CommonCompose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorHandling not working on MyPrograms.

- Not Internet Error Handling with reload CTA
- Unknown error while load webpage with reload CTA.

fixes: LEARNER-10046
Copy link
Contributor

@omerhabib26 omerhabib26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor code improvements.


@Composable
fun ErrorScreen(
title: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can simply pass errorType here and set the properties accordingly.

fun ErrorScreen(
    errorType: ErrorType,
    onReloadClick: () -> Unit
) 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we introduce this function as common compose, IMO it's better not to couple it with some constant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, WebViewUIState is more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it relates to whether the web view loaded the URL or not, IMO WebViewState is more appropriate.


import org.openedx.core.presentation.global.ErrorType

sealed class HtmlUnitUIState {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use WebViewUIState here as well ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is coupled with the UI screen, better to place separately.

@@ -20,6 +21,9 @@ class HtmlUnitViewModel(
private val notifier: CourseNotifier
) : BaseViewModel() {

private val _uiState = MutableStateFlow<HtmlUnitUIState>(HtmlUnitUIState.Loading)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use WebViewUIState here?

}
if (uiState is HtmlUnitUIState.Error) {
val errorType = (uiState as HtmlUnitUIState.Error).errorType
ErrorScreen(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ErrorType

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

import org.openedx.discovery.domain.model.Course

sealed class DiscoveryUIState {
data class Courses(val courses: List<Course>) : DiscoveryUIState()
data object Loading : DiscoveryUIState()
data object Loaded : DiscoveryUIState()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of adding new objects in DiscoveryUIState, we can use WebviewUIState

) : CourseInfoUIState()
}

enum class CourseInfoUIAction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can define a generalised WebView State. here and other occurrences

enum class WebPageState{
    WEB_PAGE_LOADED,
    WEB_PAGE_ERROR,
    RELOAD_WEB_PAGE
}

onDiscoveryUIAction(DiscoveryUIAction.WEB_PAGE_ERROR)
}
if (uiState is DiscoveryUIState.Error) {
ErrorScreen(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can simply call ConnectionErrorView()

}

if (uiState is ProgramUIState.Error) {
ErrorScreen(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can simply pass errorType.

onCourseInfoUIAction(CourseInfoUIAction.WEB_PAGE_ERROR)
}
if (webViewState is WebViewState.Error) {
ErrorScreen(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor

@omerhabib26 omerhabib26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connectivity error not handled on view all courses,
else only 2 minor nits,

@@ -1,5 +1,6 @@
package org.openedx.discovery.presentation

import org.openedx.core.presentation.global.ErrorType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove unused import.

@@ -417,6 +417,8 @@ internal fun DiscoveryScreen(
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused code, can be removed

Copy link
Contributor

@omerhabib26 omerhabib26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@farhan-arshad-dev
Copy link
Contributor Author

We're closing this PR and moving these changes to our own fork, as they are critical for us. After our release, we hope to find a way to contribute to these changes back, thanks!

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

Successfully merging this pull request may close these issues.

2 participants