Skip to content

Commit

Permalink
feat(proxiwash): suggest opening website on error
Browse files Browse the repository at this point in the history
  • Loading branch information
ignyx committed Dec 17, 2024
1 parent 6808af2 commit 5f67bda
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"numAvailablePlural": "available",
"errors": {
"title": "Proxiwash message",
"button": "More info"
"button": "More info",
"openSite": "In the meantime, open the website by tapping the button in the top-right corner."
},
"washinsa": {
"title": "INSA laundromat",
Expand Down
3 changes: 2 additions & 1 deletion locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"numAvailablePlural": "disponibles",
"errors": {
"title": "Message laverie",
"button": "En savoir plus"
"button": "En savoir plus",
"openSite": "En attendant, ouvre le site avec le bouton en haute à droite"
},
"washinsa": {
"title": "Laverie INSA",
Expand Down
45 changes: 28 additions & 17 deletions src/components/Screens/WebSectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
SectionListProps,
StyleSheet,
} from 'react-native';
import ErrorView from './ErrorView';
import ErrorView, { ErrorProps } from './ErrorView';
import CollapsibleSectionList from '../Collapsible/CollapsibleSectionList';
import RequestScreen, { RequestScreenProps } from './RequestScreen';
import { CollapsibleComponentPropsType } from '../Collapsible/CollapsibleComponent';
Expand Down Expand Up @@ -92,6 +92,17 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
};
};

const renderEmptyList = props.renderError
? props.renderError
: (errorProps: ErrorProps) => (
<ErrorView
status={errorProps.status}
code={errorProps.code}
message={errorProps.message}
button={errorProps.button}
/>
);

const render = (
data: RawData | undefined,
loading: boolean,
Expand Down Expand Up @@ -138,22 +149,21 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
: null
}
ListEmptyComponent={
loading ? undefined : (
<ErrorView
status={status}
code={code}
message={message}
button={
code !== API_RESPONSE_CODE.BAD_TOKEN
? {
icon: 'refresh',
text: i18n.t('general.retry'),
onPress: () => refreshData(),
}
: undefined
}
/>
)
loading
? undefined
: renderEmptyList({
status,
code,
message,
button:
code !== API_RESPONSE_CODE.BAD_TOKEN
? {
icon: 'refresh',
text: i18n.t('general.retry'),
onPress: () => refreshData(),
}
: undefined,
})
}
getItemLayout={
itemHeight ? (d, i) => getItemLayout(itemHeight, d, i) : undefined
Expand All @@ -172,6 +182,7 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
<RequestScreen<RawData>
request={props.request}
render={render}
renderError={props.renderError}
showError={false}
showLoading={false}
autoRefreshTime={props.autoRefreshTime}
Expand Down
17 changes: 17 additions & 0 deletions src/screens/Proxiwash/ProxiwashScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
import { useProxiwashPreferences } from '../../context/preferencesContext';
import { useSubsequentEffect } from '../../utils/customHooks';
import { MainRoutes } from '../../navigation/MainNavigator';
import ErrorView, { ErrorProps } from '../../components/Screens/ErrorView';

const REFRESH_TIME = 1000 * 10; // Refresh every 10 seconds
const LIST_ITEM_HEIGHT = 64;
Expand Down Expand Up @@ -462,6 +463,21 @@ function ProxiwashScreen() {
}
};

const renderError = (props: ErrorProps) => {
let message = props.message ? props.message : i18n.t('errors.unknown');
message += '\n' + i18n.t('screens.proxiwash.errors.openSite');

return (
<ErrorView
status={props.status}
code={props.code}
message={message}
loading={props.loading}
button={props.button}
/>
);
};

let data: LaundromatType;
switch (selectedWash) {
case 'tripodeB':
Expand All @@ -480,6 +496,7 @@ function ProxiwashScreen() {
}
createDataset={createDataset}
renderItem={getRenderItem}
renderError={renderError}
renderSectionHeader={getRenderSectionHeader}
autoRefreshTime={REFRESH_TIME}
refreshOnFocus={true}
Expand Down

0 comments on commit 5f67bda

Please sign in to comment.