Skip to content

Commit

Permalink
feat: Display an error message when opening unsupported offline cozy-app
Browse files Browse the repository at this point in the history
Cozy-apps can be opened offline only when they support this mode but
also when they have been opened at least one time to retrieve necessary
data to make them run offline

When those conditions are not met, we want to display an error message
to explain the user why the app cannot be opened

For now this message is in an Alert form, but later we may want to
improve the UI for this part
  • Loading branch information
Ldoppea committed Aug 26, 2024
1 parent f72e7e4 commit 0394cb5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/components/webviews/CozyProxyWebView.functions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Platform } from 'react-native'
import { Alert, Platform } from 'react-native'

import Minilog from 'cozy-minilog'

import { checkOauthClientsLimit } from '/app/domain/limits/checkOauthClientsLimit'
import { showOauthClientsLimitExceeded } from '/app/domain/limits/OauthClientsLimitService'
import { routes } from '/constants/routes'
import { IndexInjectionWebviewComponent } from '/components/webviews/webViewComponents/IndexInjectionWebviewComponent'
import { updateCozyAppBundleInBackground } from '/libs/cozyAppBundle/cozyAppBundle'
import { getCookie } from '/libs/httpserver/httpCookieManager'
Expand All @@ -18,7 +19,9 @@ export const initHtmlContent = async ({
href,
client,
dispatch,
setHtmlContentCreationDate
setHtmlContentCreationDate,
navigation,
t
}) => {
const cookieAlreadyExists = (await getCookie(client)) !== undefined
log.debug(`Check cookie already exists: ${cookieAlreadyExists}`)
Expand All @@ -34,6 +37,22 @@ export const initHtmlContent = async ({
const { html: htmlContent, source: htmlSource } =
await httpServerContext.getIndexHtmlForSlug(slug, client)

if (htmlSource === 'offline') {
log.debug(
`Stop loading HTML because cozy-app ${slug} is not available for offline mode`
)
Alert.alert(
t('errors.offline_unsupported_title'),
t('errors.offline_unsupported_message'),
undefined,
{
cancelable: true
}
)
navigation.navigate(routes.home)
return
}

if (
!cookieAlreadyExists &&
(await doesOauthClientsLimitPreventsLoading(client, slug, href))
Expand Down
11 changes: 8 additions & 3 deletions src/components/webviews/CozyProxyWebView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useFocusEffect } from '@react-navigation/native'
import { useFocusEffect, useNavigation } from '@react-navigation/native'
import React, { useCallback, useState, useEffect } from 'react'
import { AppState, KeyboardAvoidingView, Platform, View } from 'react-native'

Expand All @@ -9,6 +9,7 @@ import { RemountProgress } from '/app/view/Loading/RemountProgress'
import { initHtmlContent } from '/components/webviews/CozyProxyWebView.functions'
import { CozyWebView } from '/components/webviews/CozyWebView'
import { useHttpServerContext } from '/libs/httpserver/httpServerProvider'
import { useI18n } from '/locales/i18n'

import { styles } from '/components/webviews/CozyProxyWebView.styles'

Expand All @@ -23,6 +24,7 @@ export const CozyProxyWebView = ({
wrapperStyle,
...props
}) => {
const { t } = useI18n()
const client = useClient()
const httpServerContext = useHttpServerContext()
const [state, dispatch] = useState({
Expand All @@ -34,6 +36,7 @@ export const CozyProxyWebView = ({
const [htmlContentCreationDate, setHtmlContentCreationDate] = useState(
Date.now()
)
const navigation = useNavigation()

const reload = useCallback(() => {
log.debug('Reloading CozyProxyWebView')
Expand Down Expand Up @@ -73,7 +76,9 @@ export const CozyProxyWebView = ({
href,
client,
dispatch,
setHtmlContentCreationDate
setHtmlContentCreationDate,
navigation,
t
})
} else {
dispatch({
Expand All @@ -86,7 +91,7 @@ export const CozyProxyWebView = ({
}

void init()
}, [client, httpServerContext, slug, href])
}, [client, httpServerContext, navigation, slug, href])

useFocusEffect(
useCallback(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"badUnlockPassword": "The credentials you entered are incorrect, please try again.",
"badUnlockPin": "The PIN you entered is incorrect, please try again",
"contactUs": "A problem, a suggestion? Contact us at",
"offline_unsupported_title": "Unable to load",
"offline_unsupported_message": "This application is not available offline",
"unknown_error": "An unexpected error occurred, please try again.",
"reset": "Return to home",
"showDetails": "Show error details",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"badUnlockPassword": "Les identifiants que vous avez saisis sont incorrects, veuillez ré-essayer.",
"badUnlockPin": "Le code PIN que vous avez saisi est incorrect, veuillez ré-essayer",
"contactUs": "Un problème, une suggestion ? Contactez-nous à",
"offline_unsupported_title": "Chargement impossible",
"offline_unsupported_message": "Cette application n'est pas disponible hors connexion",
"unknown_error": "Une erreur inattendue s'est produite, veuillez ré-essayer.",
"reset": "Revenir à l'accueil",
"showDetails": "Voir les détails de l'erreur",
Expand Down

0 comments on commit 0394cb5

Please sign in to comment.