Compare commits

...

5 commits

Author SHA1 Message Date
Arnaud Vergnet
2c3f89816b Add button to change laundromat 2020-09-21 17:39:36 +02:00
Arnaud Vergnet
538d4d2187 Wait a few milliseconds before refreshing list 2020-09-21 17:34:51 +02:00
Arnaud Vergnet
b654a928a2 Reflect laundromat change when opening proxiwash screen 2020-09-21 17:32:15 +02:00
Arnaud Vergnet
b27864858b Move constant data in constants file 2020-09-21 17:15:58 +02:00
Arnaud Vergnet
61647ce6ec Fix flow errors and remove unused functions 2020-09-21 17:14:03 +02:00
4 changed files with 53 additions and 61 deletions

View file

@ -99,7 +99,9 @@ class WebSectionList<T> extends React.PureComponent<PropsType<T>, StateType> {
*/
onScreenFocus = () => {
const {props} = this;
if (props.refreshOnFocus && this.lastRefresh) this.onRefresh();
if (props.refreshOnFocus && this.lastRefresh) {
setTimeout(this.onRefresh, 200);
}
if (props.autoRefreshTime > 0)
this.refreshInterval = setInterval(this.onRefresh, props.autoRefreshTime);
};

View file

@ -17,4 +17,26 @@ export default {
5: 'alert',
6: 'help-circle-outline',
},
washinsa: {
id: 'washinsa',
title: 'screens.proxiwash.washinsa.title',
subtitle: 'screens.proxiwash.washinsa.subtitle',
description: 'screens.proxiwash.washinsa.description',
tarif: 'screens.proxiwash.washinsa.tariff',
paymentMethods: 'screens.proxiwash.washinsa.paymentMethods',
icon: 'school-outline',
url:
'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json',
},
tripodeB: {
id: 'tripodeB',
title: 'screens.proxiwash.tripodeB.title',
subtitle: 'screens.proxiwash.tripodeB.subtitle',
description: 'screens.proxiwash.tripodeB.description',
tarif: 'screens.proxiwash.tripodeB.tariff',
paymentMethods: 'screens.proxiwash.tripodeB.paymentMethods',
icon: 'domain',
url:
'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/tripode_b_data.json',
},
};

View file

@ -6,10 +6,11 @@ import i18n from 'i18n-js';
import {Card, Avatar, Paragraph, Title} from 'react-native-paper';
import CollapsibleScrollView from '../../components/Collapsible/CollapsibleScrollView';
import type {CardTitleIconPropsType} from '../../constants/PaperStyles';
import ProxiwashConstants from '../../constants/ProxiwashConstants';
const LOGO = 'https://etud.insa-toulouse.fr/~amicale_app/images/Proxiwash.png';
export type LaverieType = {
export type LaundromatType = {
id: string,
title: string,
subtitle: string,
@ -20,36 +21,11 @@ export type LaverieType = {
url: string,
};
export const PROXIWASH_DATA = {
washinsa: {
id: 'washinsa',
title: 'screens.proxiwash.washinsa.title',
subtitle: 'screens.proxiwash.washinsa.subtitle',
description: 'screens.proxiwash.washinsa.description',
tarif: 'screens.proxiwash.washinsa.tariff',
paymentMethods: 'screens.proxiwash.washinsa.paymentMethods',
icon: 'school-outline',
url:
'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json',
},
tripodeB: {
id: 'tripodeB',
title: 'screens.proxiwash.tripodeB.title',
subtitle: 'screens.proxiwash.tripodeB.subtitle',
description: 'screens.proxiwash.tripodeB.description',
tarif: 'screens.proxiwash.tripodeB.tariff',
paymentMethods: 'screens.proxiwash.tripodeB.paymentMethods',
icon: 'domain',
url:
'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/tripode_b_data.json',
},
};
/**
* Class defining the proxiwash about screen.
*/
export default class ProxiwashAboutScreen extends React.Component<null> {
static getCardItem(item: LaverieType): React.Node {
static getCardItem(item: LaundromatType): React.Node {
return (
<Card style={{margin: 5}}>
<Card.Title
@ -88,9 +64,9 @@ export default class ProxiwashAboutScreen extends React.Component<null> {
/>
</View>
{ProxiwashAboutScreen.getCardItem(PROXIWASH_DATA.washinsa)}
{ProxiwashAboutScreen.getCardItem(ProxiwashConstants.washinsa)}
{ProxiwashAboutScreen.getCardItem(PROXIWASH_DATA.tripodeB)}
{ProxiwashAboutScreen.getCardItem(ProxiwashConstants.tripodeB)}
<Card style={{margin: 5}}>
<Card.Title

View file

@ -3,7 +3,7 @@
import * as React from 'react';
import {Alert, View} from 'react-native';
import i18n from 'i18n-js';
import {Avatar, Button, Card, List, Text, withTheme} from 'react-native-paper';
import {Avatar, Button, Card, Text, withTheme} from 'react-native-paper';
import {StackNavigationProp} from '@react-navigation/stack';
import {Modalize} from 'react-native-modalize';
import WebSectionList from '../../components/Screens/WebSectionList';
@ -26,8 +26,7 @@ import {
import {MASCOT_STYLE} from '../../components/Mascot/Mascot';
import MascotPopup from '../../components/Mascot/MascotPopup';
import type {SectionListDataType} from '../../components/Screens/WebSectionList';
import type {ListIconPropsType} from '../../constants/PaperStyles';
import {PROXIWASH_DATA} from './ProxiwashAboutScreen';
import type {LaundromatType} from './ProxiwashAboutScreen';
const modalStateStrings = {};
@ -123,6 +122,11 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
navigation.setOptions({
headerRight: (): React.Node => (
<MaterialHeaderButtons>
<Item
title="switch"
iconName="swap-horizontal"
onPress={():void => navigation.navigate('settings')}
/>
<Item
title="information"
iconName="information"
@ -131,6 +135,19 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
</MaterialHeaderButtons>
),
});
navigation.addListener('focus', this.onScreenFocus);
}
onScreenFocus = () => {
const {state} = this;
const selected = AsyncStorageManager.getString(
AsyncStorageManager.PREFERENCES.selectedWash.key,
);
if (selected !== state.selectedWash) {
this.setState({
selectedWash: selected
});
}
}
/**
@ -343,31 +360,6 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
return count;
}
/**
* Gets a chevron icon
*
* @param props
* @return {*}
*/
static getChevronIcon(props: ListIconPropsType): React.Node {
return (
<List.Icon color={props.color} style={props.style} icon="chevron-right" />
);
}
/**
* Gets a custom list item icon
*
* @param item The item to show the icon for
* @param props
* @return {*}
*/
static getItemIcon(item: ListItemType, props: ListIconPropsType): React.Node {
return (
<List.Icon color={props.color} style={props.style} icon={item.icon} />
);
}
/**
* Creates the dataset to be used by the FlatList
*
@ -472,13 +464,13 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
render(): React.Node {
const {state} = this;
const {navigation} = this.props;
let data: LaverieType;
let data: LaundromatType;
switch (state.selectedWash) {
case 'tripodeB':
data = PROXIWASH_DATA.tripodeB;
data = ProxiwashConstants.tripodeB;
break;
default:
data = PROXIWASH_DATA.washinsa;
data = ProxiwashConstants.washinsa;
}
return (
<View