From ae1e2fcdc09d30faad8cce4ecdafc2894bafe7c2 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Thu, 13 May 2021 13:28:34 +0200 Subject: [PATCH] fix typescript errors --- src/screens/About/DebugScreen.tsx | 25 ++++++------------- .../Planning/PlanningDisplayScreen.tsx | 23 ++++++++++------- .../Services/Proximo/ProximoListScreen.tsx | 8 +++--- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/screens/About/DebugScreen.tsx b/src/screens/About/DebugScreen.tsx index ab8d07f..c66a7a4 100644 --- a/src/screens/About/DebugScreen.tsx +++ b/src/screens/About/DebugScreen.tsx @@ -63,7 +63,7 @@ const styles = StyleSheet.create({ * This screen allows the user to get and modify information on the app/device. */ class DebugScreen extends React.Component { - modalRef: Modalize | null; + modalRef: { current: Modalize | null }; modalInputValue: string; @@ -74,7 +74,7 @@ class DebugScreen extends React.Component { */ constructor(props: PropsType) { super(props); - this.modalRef = null; + this.modalRef = React.createRef(); this.modalInputValue = ''; const currentPreferences: Array = []; Object.values(AsyncStorageManager.PREFERENCES).forEach((object: any) => { @@ -154,15 +154,6 @@ class DebugScreen extends React.Component { ); }; - /** - * Callback used when receiving the modal ref - * - * @param ref - */ - onModalRef = (ref: Modalize) => { - this.modalRef = ref; - }; - /** * Shows the edit modal * @@ -172,8 +163,8 @@ class DebugScreen extends React.Component { this.setState({ modalCurrentDisplayItem: item, }); - if (this.modalRef) { - this.modalRef.open(); + if (this.modalRef.current) { + this.modalRef.current.open(); } } @@ -210,8 +201,8 @@ class DebugScreen extends React.Component { return { currentPreferences }; }); AsyncStorageManager.set(key, value); - if (this.modalRef) { - this.modalRef.close(); + if (this.modalRef.current) { + this.modalRef.current.close(); } } @@ -219,9 +210,7 @@ class DebugScreen extends React.Component { const { state } = this; return ( - - {this.getModalContent()} - + {this.getModalContent()} ; @@ -67,7 +68,7 @@ class PlanningDisplayScreen extends React.Component { eventId: number; - errorCode: number; + error: ApiRejectType; /** * Generates data depending on whether the screen was opened from the planning or from a link @@ -81,7 +82,7 @@ class PlanningDisplayScreen extends React.Component { this.displayData = props.route.params.data; this.eventId = this.displayData.id; this.shouldFetchData = false; - this.errorCode = 0; + this.error = { status: REQUEST_STATUS.SUCCESS }; this.state = { loading: false, }; @@ -89,7 +90,7 @@ class PlanningDisplayScreen extends React.Component { this.displayData = null; this.eventId = props.route.params.eventId; this.shouldFetchData = true; - this.errorCode = 0; + this.error = { status: REQUEST_STATUS.SUCCESS }; this.state = { loading: true, }; @@ -112,8 +113,8 @@ class PlanningDisplayScreen extends React.Component { * * @param error */ - onFetchError = (error: number) => { - this.errorCode = error; + onFetchError = (error: ApiRejectType) => { + this.error = error; this.setState({ loading: false }); }; @@ -161,7 +162,7 @@ class PlanningDisplayScreen extends React.Component { * @returns {*} */ getErrorView() { - if (this.errorCode === ERROR_TYPE.BAD_INPUT) { + if (this.error.code === API_REQUEST_CODES.BAD_INPUT) { return ( { } return ( { if (loading) { return ; } - if (this.errorCode === 0) { + if ( + this.error.status === REQUEST_STATUS.SUCCESS && + this.error.code === undefined + ) { return this.getContent(); } return this.getErrorView(); diff --git a/src/screens/Services/Proximo/ProximoListScreen.tsx b/src/screens/Services/Proximo/ProximoListScreen.tsx index 195d4b7..cdd4f90 100644 --- a/src/screens/Services/Proximo/ProximoListScreen.tsx +++ b/src/screens/Services/Proximo/ProximoListScreen.tsx @@ -119,12 +119,12 @@ function ProximoListScreen(props: Props) { const navigation = useNavigation(); const theme = useTheme(); const { articles, setArticles } = useCachedProximoArticles(); - const modalRef = useRef(); + const modalRef = useRef(null); const [currentSearchString, setCurrentSearchString] = useState(''); const [currentSortMode, setCurrentSortMode] = useState(2); const [modalCurrentDisplayItem, setModalCurrentDisplayItem] = useState< - React.ReactNode | undefined + React.ReactChild | undefined >(); const sortModes = [sortPrice, sortPriceReverse, sortName, sortNameReverse]; @@ -361,9 +361,7 @@ function ProximoListScreen(props: Props) { return ( - (modalRef.current = ref)}> - {modalCurrentDisplayItem} - + {modalCurrentDisplayItem} readData(Urls.proximo.articles)} createDataset={createDataset}