@@ -19,44 +19,40 @@ interface dismissedExposures {
19
19
}
20
20
21
21
22
-
23
22
export const setExposures = ( exposures : Exposure [ ] ) => async ( dispatch : any ) => {
24
23
const dismissedExposures = await AsyncStorage . getItem ( DISMISSED_EXPOSURES ) ;
25
24
26
25
let filteredExposures ;
27
- let pastExposures : Exposure [ ] = exposures
26
+ let pastExposures : Exposure [ ] = exposures ;
28
27
29
28
if ( dismissedExposures ) {
30
29
const parsedDismissedExposures : number [ ] | dismissedExposures [ ] = JSON . parse ( dismissedExposures ) ;
31
30
filteredExposures = exposures . filter ( ( exposure : Exposure ) => parsedDismissedExposures . some ( ( item : number | dismissedExposures ) => {
32
- if ( typeof item === 'number' ) {
33
- return item !== exposure . properties . OBJECTID
34
- } else {
35
- return item . OBJECTID !== exposure . properties . OBJECTID
36
- }
37
- } )
38
- )
31
+ if ( typeof item === 'number' ) {
32
+ return item !== exposure . properties . OBJECTID ;
33
+ }
34
+ return item . OBJECTID !== exposure . properties . OBJECTID ;
35
+ } ) ) ;
39
36
pastExposures = exposures . map ( ( expo ) => {
40
37
if ( parsedDismissedExposures . some ( ( item : number | dismissedExposures ) => {
41
38
if ( typeof item === 'number' ) {
42
- return item === expo . properties . OBJECTID
43
- } else {
44
- return item . OBJECTID === expo . properties . OBJECTID
39
+ return item === expo . properties . OBJECTID ;
45
40
}
41
+ return item . OBJECTID === expo . properties . OBJECTID ;
46
42
} ) ) {
47
43
if ( typeof parsedDismissedExposures === 'number' ) {
48
- expo . properties . wasThere = parsedDismissedExposures ? true : false
44
+ expo . properties . wasThere = ! ! parsedDismissedExposures ;
49
45
} else {
50
- const { wasThere} = parsedDismissedExposures . find ( ( { OBJECTID } ) => expo . properties . OBJECTID === OBJECTID )
51
- expo . properties . wasThere = wasThere ?? false
46
+ const { wasThere } = parsedDismissedExposures . find ( ( { OBJECTID } ) => expo . properties . OBJECTID === OBJECTID ) ;
47
+ expo . properties . wasThere = wasThere ?? false ;
52
48
}
53
49
}
54
- return expo
55
- } )
50
+ return expo ;
51
+ } ) ;
56
52
}
57
53
58
- console . log ( " length" , filteredExposures ?. length , pastExposures . length ) ;
59
-
54
+ console . log ( ' length' , filteredExposures ?. length , pastExposures . length ) ;
55
+
60
56
dispatch ( { type : UPDATE_EXPOSURES , payload : { exposures : filteredExposures || exposures } } ) ;
61
57
dispatch ( { type : UPDATE_PAST_EXPOSURES , payload : { pastExposures } } ) ;
62
58
@@ -65,17 +61,17 @@ export const setExposures = (exposures: Exposure[]) => async (dispatch: any) =>
65
61
// check if first item in array is number
66
62
if ( typeof parsedDismissedExposures [ 0 ] === 'number' ) {
67
63
const convertExposureToString : string = JSON . stringify ( parsedDismissedExposures . map ( ( OBJECTID : number ) => {
68
- if ( typeof OBJECTID !== 'number' ) return OBJECTID
64
+ if ( typeof OBJECTID !== 'number' ) return OBJECTID ;
69
65
return ( {
70
66
OBJECTID ,
71
67
wasThere : false
72
- } )
73
- } ) )
68
+ } ) ;
69
+ } ) ) ;
74
70
75
- await AsyncStorage . setItem ( DISMISSED_EXPOSURES , convertExposureToString )
71
+ await AsyncStorage . setItem ( DISMISSED_EXPOSURES , convertExposureToString ) ;
76
72
}
77
73
}
78
- }
74
+ } ;
79
75
80
76
export const setValidExposure = ( exposure : Exposure ) => async ( dispatch : any ) => {
81
77
try {
@@ -109,44 +105,40 @@ export const dismissExposure = (exposureId: number) => async (dispatch: any) =>
109
105
} ;
110
106
111
107
export const setExposureSelected = ( { index, wasThere } ) => async ( dispatch : any , getState : any ) => {
108
+ const exposures = [ ...getState ( ) . exposures . exposures ] ;
109
+ exposures [ index ] . properties . wasThere = wasThere ;
112
110
113
- const exposures = [ ...getState ( ) . exposures . exposures ]
114
- exposures [ index ] . properties . wasThere = wasThere
115
-
116
- dispatch ( { type : REPLACE_EXPOSURES , payload : { exposures } } )
111
+ dispatch ( { type : REPLACE_EXPOSURES , payload : { exposures } } ) ;
117
112
const dismissedExposures = await AsyncStorage . getItem ( DISMISSED_EXPOSURES ) ;
118
113
if ( dismissedExposures ) {
119
114
const parsedDismissedExposures : number [ ] | dismissedExposures [ ] = JSON . parse ( dismissedExposures ) ;
120
115
// avoid duplicates
121
116
const idx : number = parsedDismissedExposures . findIndex ( ( item : number | dismissedExposures ) => {
122
- if ( typeof item === 'number' ) {
123
- return exposures [ index ] . properties . OBJECTID === item
124
- } else {
125
- return exposures [ index ] . properties . OBJECTID === item . OBJECTID
126
- }
127
- } )
128
- if ( idx > - 1 ) {
129
- if ( typeof parsedDismissedExposures [ idx ] === 'number' ) {
130
- parsedDismissedExposures [ idx ] = { OBJECTID : exposures [ index ] . properties . OBJECTID , wasThere }
117
+ if ( typeof item === 'number' ) {
118
+ return exposures [ index ] . properties . OBJECTID === item ;
119
+ }
120
+ return exposures [ index ] . properties . OBJECTID === item . OBJECTID ;
121
+ } ) ;
122
+ if ( idx > - 1 ) {
123
+ if ( typeof parsedDismissedExposures [ idx ] === 'number' ) {
124
+ parsedDismissedExposures [ idx ] = { OBJECTID : exposures [ index ] . properties . OBJECTID , wasThere } ;
131
125
} else {
132
-
133
- parsedDismissedExposures [ idx ] . wasThere = wasThere
126
+ parsedDismissedExposures [ idx ] . wasThere = wasThere ;
134
127
}
135
128
} else {
136
- parsedDismissedExposures . push ( { OBJECTID : exposures [ index ] . properties . OBJECTID , wasThere } )
129
+ parsedDismissedExposures . push ( { OBJECTID : exposures [ index ] . properties . OBJECTID , wasThere } ) ;
137
130
}
138
131
await AsyncStorage . setItem ( DISMISSED_EXPOSURES , JSON . stringify ( parsedDismissedExposures ) ) ;
139
132
} else {
140
133
await AsyncStorage . setItem ( DISMISSED_EXPOSURES , JSON . stringify ( [ { OBJECTID : exposures [ index ] . properties . OBJECTID , wasThere } ] ) ) ;
141
134
}
142
- }
135
+ } ;
143
136
144
137
export const replacePastExposureSelected = ( payload : Exposure [ ] ) => async ( dispatch : any ) => {
145
-
146
- dispatch ( { type : REPLACE_PAST_EXPOSURES , payload } )
138
+ dispatch ( { type : REPLACE_PAST_EXPOSURES , payload } ) ;
147
139
148
140
await AsyncStorage . setItem ( DISMISSED_EXPOSURES , JSON . stringify ( payload . map ( ( exposure : Exposure ) => ( {
149
141
OBJECTID : exposure . properties . OBJECTID ,
150
142
wasThere : exposure . properties . wasThere
151
143
} ) ) ) ) ;
152
- }
144
+ } ;
0 commit comments