Browse Source

fix typescript errors

Arnaud Vergnet 2 years ago
parent
commit
ae1e2fcdc0

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

63
  * This screen allows the user to get and modify information on the app/device.
63
  * This screen allows the user to get and modify information on the app/device.
64
  */
64
  */
65
 class DebugScreen extends React.Component<PropsType, StateType> {
65
 class DebugScreen extends React.Component<PropsType, StateType> {
66
-  modalRef: Modalize | null;
66
+  modalRef: { current: Modalize | null };
67
 
67
 
68
   modalInputValue: string;
68
   modalInputValue: string;
69
 
69
 
74
    */
74
    */
75
   constructor(props: PropsType) {
75
   constructor(props: PropsType) {
76
     super(props);
76
     super(props);
77
-    this.modalRef = null;
77
+    this.modalRef = React.createRef<Modalize>();
78
     this.modalInputValue = '';
78
     this.modalInputValue = '';
79
     const currentPreferences: Array<PreferenceItemType> = [];
79
     const currentPreferences: Array<PreferenceItemType> = [];
80
     Object.values(AsyncStorageManager.PREFERENCES).forEach((object: any) => {
80
     Object.values(AsyncStorageManager.PREFERENCES).forEach((object: any) => {
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
    * Shows the edit modal
158
    * Shows the edit modal
168
    *
159
    *
169
    * @param item
160
    * @param item
172
     this.setState({
163
     this.setState({
173
       modalCurrentDisplayItem: item,
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
       return { currentPreferences };
201
       return { currentPreferences };
211
     });
202
     });
212
     AsyncStorageManager.set(key, value);
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
     const { state } = this;
210
     const { state } = this;
220
     return (
211
     return (
221
       <View>
212
       <View>
222
-        <CustomModal onRef={this.onModalRef}>
223
-          {this.getModalContent()}
224
-        </CustomModal>
213
+        <CustomModal ref={this.modalRef}>{this.getModalContent()}</CustomModal>
225
         <CollapsibleFlatList
214
         <CollapsibleFlatList
226
           data={state.currentPreferences}
215
           data={state.currentPreferences}
227
           extraData={state.currentPreferences}
216
           extraData={state.currentPreferences}

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

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

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

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

Loading…
Cancel
Save