From c5287611c499078e5b55ae069b68bcd32232d35a Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Tue, 22 Sep 2020 23:20:16 +0200 Subject: [PATCH] Fix errors induced by refactoring --- .../Animations/AnimatedAccordion.tsx | 2 +- .../Lists/PlanexGroups/GroupListItem.tsx | 7 +- .../Lists/Proxiwash/ProxiwashListItem.tsx | 77 +++++++------------ src/screens/Amicale/Clubs/ClubListScreen.tsx | 1 + 4 files changed, 34 insertions(+), 53 deletions(-) diff --git a/src/components/Animations/AnimatedAccordion.tsx b/src/components/Animations/AnimatedAccordion.tsx index e0cb5a9..c4daea1 100644 --- a/src/components/Animations/AnimatedAccordion.tsx +++ b/src/components/Animations/AnimatedAccordion.tsx @@ -27,7 +27,7 @@ type PropsType = { theme: ReactNativePaper.Theme; title: string; subtitle?: string; - style: ViewStyle; + style?: ViewStyle; left?: (props: { color: string; style?: { diff --git a/src/components/Lists/PlanexGroups/GroupListItem.tsx b/src/components/Lists/PlanexGroups/GroupListItem.tsx index eef672f..07a7af3 100644 --- a/src/components/Lists/PlanexGroups/GroupListItem.tsx +++ b/src/components/Lists/PlanexGroups/GroupListItem.tsx @@ -22,6 +22,7 @@ import {List, TouchableRipple, withTheme} from 'react-native-paper'; import * as Animatable from 'react-native-animatable'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import type {PlanexGroupType} from '../../../screens/Planex/GroupSelectionScreen'; +import {View} from 'react-native'; type PropsType = { theme: ReactNativePaper.Theme; @@ -37,11 +38,11 @@ const REPLACE_REGEX = /_/g; class GroupListItem extends React.Component { isFav: boolean; - starRef: {current: null | Animatable.View}; + starRef: {current: null | (Animatable.View & View)}; constructor(props: PropsType) { super(props); - this.starRef = React.createRef(); + this.starRef = React.createRef(); this.isFav = this.isGroupInFavorites(props.favorites); } @@ -60,7 +61,7 @@ class GroupListItem extends React.Component { onStarPress = () => { const {props} = this; const ref = this.starRef; - if (ref.current) { + if (ref.current && ref.current.rubberBand && ref.current.swing) { if (this.isFav) { ref.current.rubberBand(); } else { diff --git a/src/components/Lists/Proxiwash/ProxiwashListItem.tsx b/src/components/Lists/Proxiwash/ProxiwashListItem.tsx index 9b64a59..0845128 100644 --- a/src/components/Lists/Proxiwash/ProxiwashListItem.tsx +++ b/src/components/Lists/Proxiwash/ProxiwashListItem.tsx @@ -30,7 +30,9 @@ import { import {StyleSheet, View} from 'react-native'; import i18n from 'i18n-js'; import * as Animatable from 'react-native-animatable'; -import ProxiwashConstants from '../../../constants/ProxiwashConstants'; +import ProxiwashConstants, { + MachineStates, +} from '../../../constants/ProxiwashConstants'; import AprilFoolsManager from '../../../managers/AprilFoolsManager'; 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 */ class ProxiwashListItem extends React.Component { stateColors: {[key: string]: string}; - stateStrings: {[key: string]: string}; - title: string; titlePopUp: string; @@ -80,9 +92,6 @@ class ProxiwashListItem extends React.Component { constructor(props: PropsType) { super(props); this.stateColors = {}; - this.stateStrings = {}; - - this.updateStateStrings(); let displayNumber = props.item.number; const displayMaxWeight = props.item.maxWeight; @@ -114,60 +123,30 @@ class ProxiwashListItem extends React.Component { 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() { const {props} = this; const {colors} = props.theme; - this.stateColors[ProxiwashConstants.machineStates.AVAILABLE] = - colors.proxiwashReadyColor; - this.stateColors[ProxiwashConstants.machineStates.RUNNING] = - colors.proxiwashRunningColor; - this.stateColors[ProxiwashConstants.machineStates.RUNNING_NOT_STARTED] = + this.stateColors[MachineStates.AVAILABLE] = colors.proxiwashReadyColor; + this.stateColors[MachineStates.RUNNING] = colors.proxiwashRunningColor; + this.stateColors[MachineStates.RUNNING_NOT_STARTED] = colors.proxiwashRunningNotStartedColor; - this.stateColors[ProxiwashConstants.machineStates.FINISHED] = - colors.proxiwashFinishedColor; - this.stateColors[ProxiwashConstants.machineStates.UNAVAILABLE] = - colors.proxiwashBrokenColor; - this.stateColors[ProxiwashConstants.machineStates.ERROR] = - colors.proxiwashErrorColor; - this.stateColors[ProxiwashConstants.machineStates.UNKNOWN] = - colors.proxiwashUnknownColor; + this.stateColors[MachineStates.FINISHED] = colors.proxiwashFinishedColor; + this.stateColors[MachineStates.UNAVAILABLE] = colors.proxiwashBrokenColor; + this.stateColors[MachineStates.ERROR] = colors.proxiwashErrorColor; + this.stateColors[MachineStates.UNKNOWN] = colors.proxiwashUnknownColor; } render() { const {props} = this; const {colors} = props.theme; - const machineState = parseInt(props.item.state, 10); - const isRunning = machineState === ProxiwashConstants.machineStates.RUNNING; - const isReady = machineState === ProxiwashConstants.machineStates.AVAILABLE; + const machineState = props.item.state; + const isRunning = machineState === MachineStates.RUNNING; + const isReady = machineState === MachineStates.AVAILABLE; const description = isRunning ? `${props.item.startTime}/${props.item.endTime}` : ''; const stateIcon = ProxiwashConstants.stateIcons[machineState]; - const stateString = this.stateStrings[machineState]; + const stateString = stateStrings[machineState]; let progress; if (isRunning && props.item.donePercent !== '') { progress = parseFloat(props.item.donePercent) / 100; @@ -231,13 +210,13 @@ class ProxiwashListItem extends React.Component { {stateString} - {machineState === ProxiwashConstants.machineStates.RUNNING ? ( + {machineState === MachineStates.RUNNING ? ( {props.item.remainingTime} min ) : null} diff --git a/src/screens/Amicale/Clubs/ClubListScreen.tsx b/src/screens/Amicale/Clubs/ClubListScreen.tsx index 7663bac..f5a46ef 100644 --- a/src/screens/Amicale/Clubs/ClubListScreen.tsx +++ b/src/screens/Amicale/Clubs/ClubListScreen.tsx @@ -115,6 +115,7 @@ class ClubListScreen extends React.Component { */ getSearchBar = () => { return ( + // @ts-ignore