Browse Source

fix typescript errors

Arnaud Vergnet 2 years ago
parent
commit
ae1e2fcdc0

+ 7
- 18
src/screens/About/DebugScreen.tsx View File

@@ -63,7 +63,7 @@ const styles = StyleSheet.create({
63 63
  * This screen allows the user to get and modify information on the app/device.
64 64
  */
65 65
 class DebugScreen extends React.Component<PropsType, StateType> {
66
-  modalRef: Modalize | null;
66
+  modalRef: { current: Modalize | null };
67 67
 
68 68
   modalInputValue: string;
69 69
 
@@ -74,7 +74,7 @@ class DebugScreen extends React.Component<PropsType, StateType> {
74 74
    */
75 75
   constructor(props: PropsType) {
76 76
     super(props);
77
-    this.modalRef = null;
77
+    this.modalRef = React.createRef<Modalize>();
78 78
     this.modalInputValue = '';
79 79
     const currentPreferences: Array<PreferenceItemType> = [];
80 80
     Object.values(AsyncStorageManager.PREFERENCES).forEach((object: any) => {
@@ -155,15 +155,6 @@ class DebugScreen extends React.Component<PropsType, StateType> {
155 155
   };
156 156
 
157 157
   /**
158
-   * Callback used when receiving the modal ref
159
-   *
160
-   * @param ref
161
-   */
162
-  onModalRef = (ref: Modalize) => {
163
-    this.modalRef = ref;
164
-  };
165
-
166
-  /**
167 158
    * Shows the edit modal
168 159
    *
169 160
    * @param item
@@ -172,8 +163,8 @@ class DebugScreen extends React.Component<PropsType, StateType> {
172 163
     this.setState({
173 164
       modalCurrentDisplayItem: item,
174 165
     });
175
-    if (this.modalRef) {
176
-      this.modalRef.open();
166
+    if (this.modalRef.current) {
167
+      this.modalRef.current.open();
177 168
     }
178 169
   }
179 170
 
@@ -210,8 +201,8 @@ class DebugScreen extends React.Component<PropsType, StateType> {
210 201
       return { currentPreferences };
211 202
     });
212 203
     AsyncStorageManager.set(key, value);
213
-    if (this.modalRef) {
214
-      this.modalRef.close();
204
+    if (this.modalRef.current) {
205
+      this.modalRef.current.close();
215 206
     }
216 207
   }
217 208
 
@@ -219,9 +210,7 @@ class DebugScreen extends React.Component<PropsType, StateType> {
219 210
     const { state } = this;
220 211
     return (
221 212
       <View>
222
-        <CustomModal onRef={this.onModalRef}>
223
-          {this.getModalContent()}
224
-        </CustomModal>
213
+        <CustomModal ref={this.modalRef}>{this.getModalContent()}</CustomModal>
225 214
         <CollapsibleFlatList
226 215
           data={state.currentPreferences}
227 216
           extraData={state.currentPreferences}

+ 14
- 9
src/screens/Planning/PlanningDisplayScreen.tsx View File

@@ -25,13 +25,14 @@ import { StackNavigationProp } from '@react-navigation/stack';
25 25
 import { getDateOnlyString, getTimeOnlyString } from '../../utils/Planning';
26 26
 import DateManager from '../../managers/DateManager';
27 27
 import BasicLoadingScreen from '../../components/Screens/BasicLoadingScreen';
28
-import { apiRequest, ERROR_TYPE } from '../../utils/WebData';
28
+import { ApiRejectType, apiRequest } from '../../utils/WebData';
29 29
 import ErrorView from '../../components/Screens/ErrorView';
30 30
 import CustomHTML from '../../components/Overrides/CustomHTML';
31 31
 import { TAB_BAR_HEIGHT } from '../../components/Tabbar/CustomTabBar';
32 32
 import CollapsibleScrollView from '../../components/Collapsible/CollapsibleScrollView';
33 33
 import type { PlanningEventType } from '../../utils/Planning';
34 34
 import ImageGalleryButton from '../../components/Media/ImageGalleryButton';
35
+import { API_REQUEST_CODES, REQUEST_STATUS } from '../../utils/Requests';
35 36
 
36 37
 type PropsType = {
37 38
   navigation: StackNavigationProp<any>;
@@ -67,7 +68,7 @@ class PlanningDisplayScreen extends React.Component<PropsType, StateType> {
67 68
 
68 69
   eventId: number;
69 70
 
70
-  errorCode: number;
71
+  error: ApiRejectType;
71 72
 
72 73
   /**
73 74
    * 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<PropsType, StateType> {
81 82
       this.displayData = props.route.params.data;
82 83
       this.eventId = this.displayData.id;
83 84
       this.shouldFetchData = false;
84
-      this.errorCode = 0;
85
+      this.error = { status: REQUEST_STATUS.SUCCESS };
85 86
       this.state = {
86 87
         loading: false,
87 88
       };
@@ -89,7 +90,7 @@ class PlanningDisplayScreen extends React.Component<PropsType, StateType> {
89 90
       this.displayData = null;
90 91
       this.eventId = props.route.params.eventId;
91 92
       this.shouldFetchData = true;
92
-      this.errorCode = 0;
93
+      this.error = { status: REQUEST_STATUS.SUCCESS };
93 94
       this.state = {
94 95
         loading: true,
95 96
       };
@@ -112,8 +113,8 @@ class PlanningDisplayScreen extends React.Component<PropsType, StateType> {
112 113
    *
113 114
    * @param error
114 115
    */
115
-  onFetchError = (error: number) => {
116
-    this.errorCode = error;
116
+  onFetchError = (error: ApiRejectType) => {
117
+    this.error = error;
117 118
     this.setState({ loading: false });
118 119
   };
119 120
 
@@ -161,7 +162,7 @@ class PlanningDisplayScreen extends React.Component<PropsType, StateType> {
161 162
    * @returns {*}
162 163
    */
163 164
   getErrorView() {
164
-    if (this.errorCode === ERROR_TYPE.BAD_INPUT) {
165
+    if (this.error.code === API_REQUEST_CODES.BAD_INPUT) {
165 166
       return (
166 167
         <ErrorView
167 168
           message={i18n.t('screens.planning.invalidEvent')}
@@ -171,7 +172,8 @@ class PlanningDisplayScreen extends React.Component<PropsType, StateType> {
171 172
     }
172 173
     return (
173 174
       <ErrorView
174
-        status={this.errorCode}
175
+        status={this.error.status}
176
+        code={this.error.code}
175 177
         button={{
176 178
           icon: 'refresh',
177 179
           text: i18n.t('general.retry'),
@@ -196,7 +198,10 @@ class PlanningDisplayScreen extends React.Component<PropsType, StateType> {
196 198
     if (loading) {
197 199
       return <BasicLoadingScreen />;
198 200
     }
199
-    if (this.errorCode === 0) {
201
+    if (
202
+      this.error.status === REQUEST_STATUS.SUCCESS &&
203
+      this.error.code === undefined
204
+    ) {
200 205
       return this.getContent();
201 206
     }
202 207
     return this.getErrorView();

+ 3
- 5
src/screens/Services/Proximo/ProximoListScreen.tsx View File

@@ -119,12 +119,12 @@ function ProximoListScreen(props: Props) {
119 119
   const navigation = useNavigation();
120 120
   const theme = useTheme();
121 121
   const { articles, setArticles } = useCachedProximoArticles();
122
-  const modalRef = useRef<Modalize>();
122
+  const modalRef = useRef<Modalize>(null);
123 123
 
124 124
   const [currentSearchString, setCurrentSearchString] = useState('');
125 125
   const [currentSortMode, setCurrentSortMode] = useState(2);
126 126
   const [modalCurrentDisplayItem, setModalCurrentDisplayItem] = useState<
127
-    React.ReactNode | undefined
127
+    React.ReactChild | undefined
128 128
   >();
129 129
 
130 130
   const sortModes = [sortPrice, sortPriceReverse, sortName, sortNameReverse];
@@ -361,9 +361,7 @@ function ProximoListScreen(props: Props) {
361 361
 
362 362
   return (
363 363
     <View style={GENERAL_STYLES.flex}>
364
-      <CustomModal onRef={(ref) => (modalRef.current = ref)}>
365
-        {modalCurrentDisplayItem}
366
-      </CustomModal>
364
+      <CustomModal ref={modalRef}>{modalCurrentDisplayItem}</CustomModal>
367 365
       <WebSectionList
368 366
         request={() => readData<ArticlesType>(Urls.proximo.articles)}
369 367
         createDataset={createDataset}

Loading…
Cancel
Save