Remove annoying snackbar

This commit is contained in:
Arnaud Vergnet 2021-05-13 10:27:01 +02:00
vanhempi c1dd69d0ed
commit e7cffde198
3 muutettua tiedostoa jossa 27 lisäystä ja 50 poistoa

Näytä tiedosto

@ -132,7 +132,11 @@ function getMessage(props: Props) {
}
}
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;
}

Näytä tiedosto

@ -17,20 +17,16 @@
* 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 { 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<ItemT, RawData>(props: Props<ItemT, RawData>) {
const [snackbarVisible, setSnackbarVisible] = useState(false);
const showSnackBar = () => setSnackbarVisible(true);
const hideSnackBar = () => setSnackbarVisible(false);
const getItemLayout = (
height: number,
_data: Array<SectionListData<ItemT>> | null,
@ -124,9 +114,6 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
status,
code
);
if (!data && !loading) {
showSnackBar();
}
return (
<CollapsibleSectionList
{...props}
@ -162,7 +149,7 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
button={{
icon: 'refresh',
text: i18n.t('general.retry'),
onPress: refreshData,
onPress: () => refreshData(),
}}
/>
)
@ -175,7 +162,6 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
};
return (
<View style={GENERAL_STYLES.flex}>
<RequestScreen<RawData>
request={props.request}
render={render}
@ -186,21 +172,6 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
cache={props.cache}
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>
);
}

Näytä tiedosto

@ -78,12 +78,14 @@ export function useRequestLogic<T>(
}
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<T>(
}
})
.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,
});
});
}
};