Remove annoying snackbar

This commit is contained in:
Arnaud Vergnet 2021-05-13 10:27:01 +02:00
parent c1dd69d0ed
commit e7cffde198
3 changed files with 27 additions and 50 deletions

View file

@ -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) { if (props.message != null) {
fullMessage.message = props.message; fullMessage.message = props.message;
} }

View file

@ -17,20 +17,16 @@
* along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
*/ */
import React, { useState } from 'react'; import React from 'react';
import i18n from 'i18n-js'; import i18n from 'i18n-js';
import { Snackbar } from 'react-native-paper';
import { import {
RefreshControl, RefreshControl,
SectionListData, SectionListData,
SectionListProps, SectionListProps,
StyleSheet, StyleSheet,
View,
} from 'react-native'; } from 'react-native';
import ErrorView from './ErrorView'; import ErrorView from './ErrorView';
import { TAB_BAR_HEIGHT } from '../Tabbar/CustomTabBar';
import CollapsibleSectionList from '../Collapsible/CollapsibleSectionList'; import CollapsibleSectionList from '../Collapsible/CollapsibleSectionList';
import GENERAL_STYLES from '../../constants/Styles';
import RequestScreen, { RequestScreenProps } from './RequestScreen'; import RequestScreen, { RequestScreenProps } from './RequestScreen';
import { CollapsibleComponentPropsType } from '../Collapsible/CollapsibleComponent'; import { CollapsibleComponentPropsType } from '../Collapsible/CollapsibleComponent';
import { REQUEST_CODES, REQUEST_STATUS } from '../../utils/Requests'; 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. * To force the component to update, change the value of updateData.
*/ */
function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) { function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
const [snackbarVisible, setSnackbarVisible] = useState(false);
const showSnackBar = () => setSnackbarVisible(true);
const hideSnackBar = () => setSnackbarVisible(false);
const getItemLayout = ( const getItemLayout = (
height: number, height: number,
_data: Array<SectionListData<ItemT>> | null, _data: Array<SectionListData<ItemT>> | null,
@ -124,9 +114,6 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
status, status,
code code
); );
if (!data && !loading) {
showSnackBar();
}
return ( return (
<CollapsibleSectionList <CollapsibleSectionList
{...props} {...props}
@ -162,7 +149,7 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
button={{ button={{
icon: 'refresh', icon: 'refresh',
text: i18n.t('general.retry'), text: i18n.t('general.retry'),
onPress: refreshData, onPress: () => refreshData(),
}} }}
/> />
) )
@ -175,32 +162,16 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
}; };
return ( return (
<View style={GENERAL_STYLES.flex}> <RequestScreen<RawData>
<RequestScreen<RawData> request={props.request}
request={props.request} render={render}
render={render} showError={false}
showError={false} showLoading={false}
showLoading={false} autoRefreshTime={props.autoRefreshTime}
autoRefreshTime={props.autoRefreshTime} refreshOnFocus={props.refreshOnFocus}
refreshOnFocus={props.refreshOnFocus} cache={props.cache}
cache={props.cache} onCacheUpdate={props.onCacheUpdate}
onCacheUpdate={props.onCacheUpdate} />
/>
<Snackbar
visible={snackbarVisible}
onDismiss={hideSnackBar}
action={{
label: 'OK',
onPress: hideSnackBar,
}}
duration={4000}
style={{
bottom: TAB_BAR_HEIGHT,
}}
>
{i18n.t('general.listUpdateFail')}
</Snackbar>
</View>
); );
} }

View file

@ -78,12 +78,14 @@ export function useRequestLogic<T>(
} }
if (canRefresh) { if (canRefresh) {
if (!response.loading) { if (!response.loading) {
setResponse((prevState) => ({ setResponse({
...prevState, ...response,
loading: true, loading: true,
})); });
} }
const r = newRequest ? newRequest : request; const r = newRequest ? newRequest : request;
console.log(r);
r() r()
.then((requestResponse: T) => { .then((requestResponse: T) => {
setResponse({ setResponse({
@ -98,13 +100,13 @@ export function useRequestLogic<T>(
} }
}) })
.catch(() => { .catch(() => {
setResponse((prevState) => ({ setResponse({
loading: false, loading: false,
lastRefreshDate: prevState.lastRefreshDate, lastRefreshDate: response.lastRefreshDate,
status: REQUEST_STATUS.CONNECTION_ERROR, status: REQUEST_STATUS.CONNECTION_ERROR,
code: 0, code: undefined,
data: prevState.data, data: response.data,
})); });
}); });
} }
}; };