diff --git a/src/components/Screens/ErrorView.tsx b/src/components/Screens/ErrorView.tsx index e0377cd..67b763e 100644 --- a/src/components/Screens/ErrorView.tsx +++ b/src/components/Screens/ErrorView.tsx @@ -132,7 +132,11 @@ function getMessage(props: Props) { } } - fullMessage.message += `\n\nCode {${props.status}:${props.code}}`; + if (props.code !== undefined) { + fullMessage.message += `\n\nCode {${props.status}:${props.code}}`; + } else { + fullMessage.message += `\n\nCode {${props.status}}`; + } if (props.message != null) { fullMessage.message = props.message; } diff --git a/src/components/Screens/WebSectionList.tsx b/src/components/Screens/WebSectionList.tsx index 5fe7717..8879333 100644 --- a/src/components/Screens/WebSectionList.tsx +++ b/src/components/Screens/WebSectionList.tsx @@ -17,20 +17,16 @@ * along with Campus INSAT. If not, see . */ -import React, { useState } from 'react'; +import React from 'react'; import i18n from 'i18n-js'; -import { Snackbar } from 'react-native-paper'; import { RefreshControl, SectionListData, SectionListProps, StyleSheet, - View, } from 'react-native'; import ErrorView from './ErrorView'; -import { TAB_BAR_HEIGHT } from '../Tabbar/CustomTabBar'; import CollapsibleSectionList from '../Collapsible/CollapsibleSectionList'; -import GENERAL_STYLES from '../../constants/Styles'; import RequestScreen, { RequestScreenProps } from './RequestScreen'; import { CollapsibleComponentPropsType } from '../Collapsible/CollapsibleComponent'; import { REQUEST_CODES, REQUEST_STATUS } from '../../utils/Requests'; @@ -89,12 +85,6 @@ const styles = StyleSheet.create({ * To force the component to update, change the value of updateData. */ function WebSectionList(props: Props) { - const [snackbarVisible, setSnackbarVisible] = useState(false); - - const showSnackBar = () => setSnackbarVisible(true); - - const hideSnackBar = () => setSnackbarVisible(false); - const getItemLayout = ( height: number, _data: Array> | null, @@ -124,9 +114,6 @@ function WebSectionList(props: Props) { status, code ); - if (!data && !loading) { - showSnackBar(); - } return ( (props: Props) { button={{ icon: 'refresh', text: i18n.t('general.retry'), - onPress: refreshData, + onPress: () => refreshData(), }} /> ) @@ -175,32 +162,16 @@ function WebSectionList(props: Props) { }; return ( - - - request={props.request} - render={render} - showError={false} - showLoading={false} - autoRefreshTime={props.autoRefreshTime} - refreshOnFocus={props.refreshOnFocus} - cache={props.cache} - onCacheUpdate={props.onCacheUpdate} - /> - - {i18n.t('general.listUpdateFail')} - - + + request={props.request} + render={render} + showError={false} + showLoading={false} + autoRefreshTime={props.autoRefreshTime} + refreshOnFocus={props.refreshOnFocus} + cache={props.cache} + onCacheUpdate={props.onCacheUpdate} + /> ); } diff --git a/src/utils/customHooks.tsx b/src/utils/customHooks.tsx index 67d5b51..9ec3be9 100644 --- a/src/utils/customHooks.tsx +++ b/src/utils/customHooks.tsx @@ -78,12 +78,14 @@ export function useRequestLogic( } if (canRefresh) { if (!response.loading) { - setResponse((prevState) => ({ - ...prevState, + setResponse({ + ...response, loading: true, - })); + }); } const r = newRequest ? newRequest : request; + console.log(r); + r() .then((requestResponse: T) => { setResponse({ @@ -98,13 +100,13 @@ export function useRequestLogic( } }) .catch(() => { - setResponse((prevState) => ({ + setResponse({ loading: false, - lastRefreshDate: prevState.lastRefreshDate, + lastRefreshDate: response.lastRefreshDate, status: REQUEST_STATUS.CONNECTION_ERROR, - code: 0, - data: prevState.data, - })); + code: undefined, + data: response.data, + }); }); } };