Fix errors induced by refactoring

This commit is contained in:
Arnaud Vergnet 2020-09-22 23:20:16 +02:00
parent fde9a12ef9
commit c5287611c4
4 changed files with 34 additions and 53 deletions

View file

@ -27,7 +27,7 @@ type PropsType = {
theme: ReactNativePaper.Theme; theme: ReactNativePaper.Theme;
title: string; title: string;
subtitle?: string; subtitle?: string;
style: ViewStyle; style?: ViewStyle;
left?: (props: { left?: (props: {
color: string; color: string;
style?: { style?: {

View file

@ -22,6 +22,7 @@ import {List, TouchableRipple, withTheme} from 'react-native-paper';
import * as Animatable from 'react-native-animatable'; import * as Animatable from 'react-native-animatable';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import type {PlanexGroupType} from '../../../screens/Planex/GroupSelectionScreen'; import type {PlanexGroupType} from '../../../screens/Planex/GroupSelectionScreen';
import {View} from 'react-native';
type PropsType = { type PropsType = {
theme: ReactNativePaper.Theme; theme: ReactNativePaper.Theme;
@ -37,11 +38,11 @@ const REPLACE_REGEX = /_/g;
class GroupListItem extends React.Component<PropsType> { class GroupListItem extends React.Component<PropsType> {
isFav: boolean; isFav: boolean;
starRef: {current: null | Animatable.View}; starRef: {current: null | (Animatable.View & View)};
constructor(props: PropsType) { constructor(props: PropsType) {
super(props); super(props);
this.starRef = React.createRef<Animatable.View>(); this.starRef = React.createRef();
this.isFav = this.isGroupInFavorites(props.favorites); this.isFav = this.isGroupInFavorites(props.favorites);
} }
@ -60,7 +61,7 @@ class GroupListItem extends React.Component<PropsType> {
onStarPress = () => { onStarPress = () => {
const {props} = this; const {props} = this;
const ref = this.starRef; const ref = this.starRef;
if (ref.current) { if (ref.current && ref.current.rubberBand && ref.current.swing) {
if (this.isFav) { if (this.isFav) {
ref.current.rubberBand(); ref.current.rubberBand();
} else { } else {

View file

@ -30,7 +30,9 @@ import {
import {StyleSheet, View} from 'react-native'; import {StyleSheet, View} from 'react-native';
import i18n from 'i18n-js'; import i18n from 'i18n-js';
import * as Animatable from 'react-native-animatable'; import * as Animatable from 'react-native-animatable';
import ProxiwashConstants from '../../../constants/ProxiwashConstants'; import ProxiwashConstants, {
MachineStates,
} from '../../../constants/ProxiwashConstants';
import AprilFoolsManager from '../../../managers/AprilFoolsManager'; import AprilFoolsManager from '../../../managers/AprilFoolsManager';
import type {ProxiwashMachineType} from '../../../screens/Proxiwash/ProxiwashScreen'; import type {ProxiwashMachineType} from '../../../screens/Proxiwash/ProxiwashScreen';
@ -65,14 +67,24 @@ const styles = StyleSheet.create({
}, },
}); });
const stateStrings: {[key in MachineStates]: string} = {
[MachineStates.AVAILABLE]: i18n.t('screens.proxiwash.states.ready'),
[MachineStates.RUNNING]: i18n.t('screens.proxiwash.states.running'),
[MachineStates.RUNNING_NOT_STARTED]: i18n.t(
'screens.proxiwash.states.runningNotStarted',
),
[MachineStates.FINISHED]: i18n.t('screens.proxiwash.states.finished'),
[MachineStates.UNAVAILABLE]: i18n.t('screens.proxiwash.states.broken'),
[MachineStates.ERROR]: i18n.t('screens.proxiwash.states.error'),
[MachineStates.UNKNOWN]: i18n.t('screens.proxiwash.states.unknown'),
};
/** /**
* Component used to display a proxiwash item, showing machine progression and state * Component used to display a proxiwash item, showing machine progression and state
*/ */
class ProxiwashListItem extends React.Component<PropsType> { class ProxiwashListItem extends React.Component<PropsType> {
stateColors: {[key: string]: string}; stateColors: {[key: string]: string};
stateStrings: {[key: string]: string};
title: string; title: string;
titlePopUp: string; titlePopUp: string;
@ -80,9 +92,6 @@ class ProxiwashListItem extends React.Component<PropsType> {
constructor(props: PropsType) { constructor(props: PropsType) {
super(props); super(props);
this.stateColors = {}; this.stateColors = {};
this.stateStrings = {};
this.updateStateStrings();
let displayNumber = props.item.number; let displayNumber = props.item.number;
const displayMaxWeight = props.item.maxWeight; const displayMaxWeight = props.item.maxWeight;
@ -114,60 +123,30 @@ class ProxiwashListItem extends React.Component<PropsType> {
props.onPress(this.titlePopUp, props.item, props.isDryer); props.onPress(this.titlePopUp, props.item, props.isDryer);
}; };
updateStateStrings() {
this.stateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t(
'screens.proxiwash.states.ready',
);
this.stateStrings[ProxiwashConstants.machineStates.RUNNING] = i18n.t(
'screens.proxiwash.states.running',
);
this.stateStrings[
ProxiwashConstants.machineStates.RUNNING_NOT_STARTED
] = i18n.t('screens.proxiwash.states.runningNotStarted');
this.stateStrings[ProxiwashConstants.machineStates.FINISHED] = i18n.t(
'screens.proxiwash.states.finished',
);
this.stateStrings[ProxiwashConstants.machineStates.UNAVAILABLE] = i18n.t(
'screens.proxiwash.states.broken',
);
this.stateStrings[ProxiwashConstants.machineStates.ERROR] = i18n.t(
'screens.proxiwash.states.error',
);
this.stateStrings[ProxiwashConstants.machineStates.UNKNOWN] = i18n.t(
'screens.proxiwash.states.unknown',
);
}
updateStateColors() { updateStateColors() {
const {props} = this; const {props} = this;
const {colors} = props.theme; const {colors} = props.theme;
this.stateColors[ProxiwashConstants.machineStates.AVAILABLE] = this.stateColors[MachineStates.AVAILABLE] = colors.proxiwashReadyColor;
colors.proxiwashReadyColor; this.stateColors[MachineStates.RUNNING] = colors.proxiwashRunningColor;
this.stateColors[ProxiwashConstants.machineStates.RUNNING] = this.stateColors[MachineStates.RUNNING_NOT_STARTED] =
colors.proxiwashRunningColor;
this.stateColors[ProxiwashConstants.machineStates.RUNNING_NOT_STARTED] =
colors.proxiwashRunningNotStartedColor; colors.proxiwashRunningNotStartedColor;
this.stateColors[ProxiwashConstants.machineStates.FINISHED] = this.stateColors[MachineStates.FINISHED] = colors.proxiwashFinishedColor;
colors.proxiwashFinishedColor; this.stateColors[MachineStates.UNAVAILABLE] = colors.proxiwashBrokenColor;
this.stateColors[ProxiwashConstants.machineStates.UNAVAILABLE] = this.stateColors[MachineStates.ERROR] = colors.proxiwashErrorColor;
colors.proxiwashBrokenColor; this.stateColors[MachineStates.UNKNOWN] = colors.proxiwashUnknownColor;
this.stateColors[ProxiwashConstants.machineStates.ERROR] =
colors.proxiwashErrorColor;
this.stateColors[ProxiwashConstants.machineStates.UNKNOWN] =
colors.proxiwashUnknownColor;
} }
render() { render() {
const {props} = this; const {props} = this;
const {colors} = props.theme; const {colors} = props.theme;
const machineState = parseInt(props.item.state, 10); const machineState = props.item.state;
const isRunning = machineState === ProxiwashConstants.machineStates.RUNNING; const isRunning = machineState === MachineStates.RUNNING;
const isReady = machineState === ProxiwashConstants.machineStates.AVAILABLE; const isReady = machineState === MachineStates.AVAILABLE;
const description = isRunning const description = isRunning
? `${props.item.startTime}/${props.item.endTime}` ? `${props.item.startTime}/${props.item.endTime}`
: ''; : '';
const stateIcon = ProxiwashConstants.stateIcons[machineState]; const stateIcon = ProxiwashConstants.stateIcons[machineState];
const stateString = this.stateStrings[machineState]; const stateString = stateStrings[machineState];
let progress; let progress;
if (isRunning && props.item.donePercent !== '') { if (isRunning && props.item.donePercent !== '') {
progress = parseFloat(props.item.donePercent) / 100; progress = parseFloat(props.item.donePercent) / 100;
@ -231,13 +210,13 @@ class ProxiwashListItem extends React.Component<PropsType> {
<View style={{justifyContent: 'center'}}> <View style={{justifyContent: 'center'}}>
<Text <Text
style={ style={
machineState === ProxiwashConstants.machineStates.FINISHED machineState === MachineStates.FINISHED
? {fontWeight: 'bold'} ? {fontWeight: 'bold'}
: {} : {}
}> }>
{stateString} {stateString}
</Text> </Text>
{machineState === ProxiwashConstants.machineStates.RUNNING ? ( {machineState === MachineStates.RUNNING ? (
<Caption>{props.item.remainingTime} min</Caption> <Caption>{props.item.remainingTime} min</Caption>
) : null} ) : null}
</View> </View>

View file

@ -115,6 +115,7 @@ class ClubListScreen extends React.Component<PropsType, StateType> {
*/ */
getSearchBar = () => { getSearchBar = () => {
return ( return (
// @ts-ignore
<Searchbar <Searchbar
placeholder={i18n.t('screens.proximo.search')} placeholder={i18n.t('screens.proximo.search')}
onChangeText={this.onSearchStringChange} onChangeText={this.onSearchStringChange}