Skip to content

Commit

Permalink
bug fixes and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
SagivOnoApps committed Jun 7, 2020
1 parent cc3e18b commit 14dd43b
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 89 deletions.
1 change: 0 additions & 1 deletion src/actions/ExposuresActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const dismissExposures = () => async (dispatch: any, getState: any) => {
const dismissedExposureSet = new Set(exposures.map(({ properties }: Exposure) => properties.BLETimestamp || properties.OBJECTID).concat(parsedDismissedExposures));

await AsyncStorage.setItem(DISMISSED_EXPOSURES, JSON.stringify([...dismissedExposureSet]));

};

export const setExposureSelected = ({ index, wasThere }) => (dispatch: any, getState: any) => {
Expand Down
1 change: 0 additions & 1 deletion src/components/Drawer/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const DrawerStack = ({ navigation, route }) => {
useEffect(() => {
if (initialRouteName !== '' && exposures?.length > 0) {
if (route.state?.routes && !route.state.routes.some(({ name }) => name === 'ExposureDetected')) {

navigation.navigate('ExposureDetected');
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/components/Main/ExposuresHistory/ExposuresHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ const ExposuresHistory = (
const { exposuresHistory: { title, subTitle, wasNotThere, wasThere, wasThereNoExposure, wasNotThereNoExposure, keepInstructions, edit } } = strings;

const [tabIndex, setTabIndex] = useState(1);
const wasThereList = pastExposures.filter(({ properties }: Exposure) => properties?.wasThere)
const wasNotThereList = pastExposures.filter(({ properties }: Exposure) => !properties?.wasThere)
const wasThereList = pastExposures.filter(({ properties }: Exposure) => properties?.wasThere);
const wasNotThereList = pastExposures.filter(({ properties }: Exposure) => !properties?.wasThere);
const showEditBtn = useMemo(() => {
return wasThereList.length + wasNotThereList.length > 0 && pastExposures.some((exposure: Exposure) => exposure.properties.BLETimestamp === null);
return wasThereList.length + wasNotThereList.length > 0 && pastExposures.some((exposure: Exposure) => exposure.properties.BLETimestamp === null);
}, [wasThereList.length, wasNotThereList.length]);
const [tabsLayout, setTabsLayout] = useState({});
const [lineAnimLeft] = useState(new Animated.Value(isRTL ? SCREEN_WIDTH : 0));
const [lineAnimWidth] = useState(new Animated.Value(0));
const [listTranslateAnim] = useState(new Animated.Value(isRTL ? SCREEN_WIDTH : 0));
const [firstLoad, setFirstLoad] = useState(true)
const [firstLoad, setFirstLoad] = useState(true);

useEffect(() => {
// didn't layout yet
Expand All @@ -51,7 +51,7 @@ const ExposuresHistory = (
Animated.parallel([
Animated.timing(lineAnimLeft, {
toValue: tabsLayout[tabIndex].x - LINE_MARGIN + (isRTL ? tabIndex * SCREEN_WIDTH / 2 : SCREEN_WIDTH / 2 * (tabIndex ? 0 : 1)),
duration: firstLoad ? 0 :ANIMATION_DURATION,
duration: firstLoad ? 0 : ANIMATION_DURATION,
}),
Animated.timing(listTranslateAnim, {
toValue: tabIndex ? SCREEN_WIDTH : 0,
Expand All @@ -60,7 +60,7 @@ const ExposuresHistory = (
}),
Animated.timing(lineAnimWidth, {
toValue: tabsLayout[tabIndex].width + (LINE_MARGIN * 2),
duration: firstLoad ? 0 :ANIMATION_DURATION,
duration: firstLoad ? 0 : ANIMATION_DURATION,
})
]).start(() => setFirstLoad(false));
}
Expand Down
124 changes: 68 additions & 56 deletions src/components/Main/ExposuresHistory/ExposuresHistoryEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,26 @@ import React, { useState, useCallback, useRef, useMemo } from 'react';
import { View, StyleSheet, FlatList } from 'react-native';
import { useSelector, useDispatch } from 'react-redux';
import _ from 'lodash';
import { StackActions } from '@react-navigation/native';
import { Icon, Text, TouchableOpacity } from '../../common';
import { Store, ExposuresReducer, LocaleReducer, Exposure } from '../../../types';
import ExposureHistoryListItem from './ExposureHistoryListItem';
import { PADDING_TOP, SCREEN_HEIGHT, SCREEN_WIDTH, IS_SMALL_SCREEN, MAIN_COLOR, HIT_SLOP, WHITE, PADDING_BOTTOM } from '../../../constants/Constants';
import { PADDING_TOP, SCREEN_HEIGHT, SCREEN_WIDTH, IS_SMALL_SCREEN, MAIN_COLOR, WHITE, PADDING_BOTTOM } from '../../../constants/Constants';
import { showMapModal } from '../../../actions/GeneralActions';
import { REPLACE_PAST_EXPOSURES } from '../../../constants/ActionTypes';
import { replacePastExposureSelected } from '../../../actions/ExposuresActions';
import InfoBubble from '../InfoBubble';


const ExposureItem = () => {
return <Text>item</Text>;
};

const ExposuresHistoryEdit = ({ navigation, route }) => {
const ExposuresHistoryEdit = ({ navigation }) => {
const dispatch = useDispatch();
const { isRTL, strings } = useSelector<Store, LocaleReducer>(state => state.locale);
const {
exposuresHistory: { title, subTitle, historyEditFinishBtn, historyEditCancelBtn, BLEWarning },
scanHome: { wasNotMe, wasMe, }
} = strings;
const { pastExposures } = useSelector<Store, ExposuresReducer>(state => state.exposures);
// clone for imutablity purpose
const [newExposureArr, setNewExposureArray] = useState(_.cloneDeep(pastExposures));

const showBLEWarning = useMemo(() => pastExposures.some(({ properties }: Exposure) => properties.BLETimestamp), [pastExposures.length]);
const showBLEWarning = useMemo(() => pastExposures.some(({ properties }: Exposure) => properties.BLETimestamp), [pastExposures]);

const setSelected = (index, wasThere) => {
setNewExposureArray((exposureArrState) => {
Expand All @@ -42,7 +36,7 @@ const ExposuresHistoryEdit = ({ navigation, route }) => {
// check if change at all
const oldExposureState = _.cloneDeep(pastExposures);
// commit changes and check diff from pastExposures
dispatch(replacePastExposureSelected([...newExposureArr]));
dispatch(replacePastExposureSelected(newExposureArr));

// user had at least one exposure detected
const wasChanged = oldExposureState.reduce((dif, exposure, index) => {
Expand Down Expand Up @@ -86,48 +80,6 @@ const ExposuresHistoryEdit = ({ navigation, route }) => {
}
};

const RenderExposure = ({ index, item }) => {
const { wasThere, BLETimestamp, Place } = item.properties;
const [wasThereSelected, wasNotThereSelected] = useMemo(() => {
if (wasThere === null) return [false, false];
return [wasThere, !wasThere];
}, [wasThere]);

return (

<ExposureHistoryListItem
isRTL={isRTL}
strings={strings}
{...item.properties}
style={{ marginHorizontal: 15, marginBottom: 10, opacity: BLETimestamp ? 0.7 : 1 }}
showExposureOnMap={() => dispatch(showMapModal(item))}
>
{!BLETimestamp && Place && (
<View style={{
flexDirection: isRTL ? 'row' : 'row-reverse',
marginTop: 20,

}}
>
<TouchableOpacity
style={[styles.actionBtnTouch, wasNotThereSelected && styles.actionBtnSelected, { marginHorizontal: 12 }]}
onPress={() => setSelected(index, false)}
>
<Text style={[styles.actionBtnText, wasNotThereSelected && styles.actionBtnSelectedText]} bold={wasNotThereSelected}>{wasNotMe}</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.actionBtnTouch, wasThereSelected && styles.actionBtnSelected]}
onPress={() => setSelected(index, true)}
>
<Text style={[styles.actionBtnText, wasThereSelected && styles.actionBtnSelectedText]} bold={wasThereSelected}>{wasMe}</Text>
</TouchableOpacity>

</View>
)}
</ExposureHistoryListItem>

);
};

return (
<View style={styles.container}>
Expand All @@ -140,7 +92,18 @@ const ExposuresHistoryEdit = ({ navigation, route }) => {
if (item?.properties?.BLETimestamp) return item.properties.BLETimestamp.toString();
return item.properties.OBJECTID.toString();
}}
renderItem={({ index, item }) => (<RenderExposure item={item} index={index} />)}
renderItem={({ index, item }) => (
<RenderExposure
item={item}
index={index}
isRTL={isRTL}
strings={strings}
showExposureOnMap={() => dispatch(showMapModal(item))}
setSelected={setSelected}
wasNotMe={wasNotMe}
wasMe={wasMe}
/>
)}
ListHeaderComponent={() => (
<View style={styles.headerContainer}>
<View>
Expand All @@ -165,7 +128,7 @@ const ExposuresHistoryEdit = ({ navigation, route }) => {
[isRTL ? 'marginLeft' : 'marginRight']: 8
}}
/>
<Text
<Text
style={{
fontSize: 13,
color: 'rgb(106,106,106)'
Expand Down Expand Up @@ -197,6 +160,52 @@ const ExposuresHistoryEdit = ({ navigation, route }) => {
);
};


const RenderExposure = ({ index, item, isRTL, strings, showExposureOnMap, setSelected, wasMe, wasNotMe }) => {
const { wasThere, BLETimestamp, Place } = item.properties;

const [wasThereSelected, wasNotThereSelected] = useMemo(() => {
if (wasThere === null) return [false, false];
return [wasThere, !wasThere];
}, [wasThere]);

return (

<ExposureHistoryListItem
isRTL={isRTL}
strings={strings}
{...item.properties}
style={{ marginHorizontal: 15, marginBottom: 10, opacity: BLETimestamp ? 0.7 : 1 }}
showExposureOnMap={showExposureOnMap}
>
{!BLETimestamp && Place && (
<View style={{
flexDirection: isRTL ? 'row' : 'row-reverse',
marginTop: 20,

}}
>
<TouchableOpacity
style={[styles.actionBtnTouch, wasNotThereSelected && styles.actionBtnSelected, { marginHorizontal: 12 }]}
onPress={() => setSelected(index, false)}
>
<Text style={[styles.actionBtnText, wasNotThereSelected && styles.actionBtnSelectedText]} bold={wasNotThereSelected}>{wasNotMe}</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.actionBtnTouch, wasThereSelected && styles.actionBtnSelected]}
onPress={() => setSelected(index, true)}
>
<Text style={[styles.actionBtnText, wasThereSelected && styles.actionBtnSelectedText]} bold={wasThereSelected}>{wasMe}</Text>
</TouchableOpacity>

</View>
)}
</ExposureHistoryListItem>

);
};


const styles = StyleSheet.create({
container: {
flex: 1,
Expand Down Expand Up @@ -240,7 +249,10 @@ const styles = StyleSheet.create({
footerBtnText: {
fontSize: 14,
},
buttonsContainer: { width: SCREEN_WIDTH, height: PADDING_BOTTOM(49) }
buttonsContainer: {
width: SCREEN_WIDTH,
height: PADDING_BOTTOM(49)
}
});

export default ExposuresHistoryEdit;
4 changes: 2 additions & 2 deletions src/components/Main/ScanHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ const ScanHome: FunctionComponent<ScanHomeProps> = (

DeviceEventEmitter.addListener(RNSettings.GPS_PROVIDER_EVENT, handleGPSProviderEvent);

if(exposures.length > 0) {
navigation.navigate('ExposureDetected')
if (exposures.length > 0) {
navigation.navigate('ExposureDetected');
}

return () => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Onboarding/BluetoothOnboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const BluetoothOnboarding: FunctionComponent<Props> = ({ navigation }) => {
<GeneralContainer style={styles.container}>
<OnboardingHeader />
<BluetoothPermission
onEnd={() => {
const androidVersion = parseFloat(DeviceInfo.getSystemVersion().split(',')[0]);
navigation.navigate(androidVersion >= 10 ? 'FilterDrivingOnBoarding' : 'LocationHistoryOnBoarding');
}
onEnd={() => {
const androidVersion = parseFloat(DeviceInfo.getSystemVersion().split(',')[0]);
navigation.navigate(androidVersion >= 10 ? 'FilterDrivingOnBoarding' : 'LocationHistoryOnBoarding');
}
}
/>
</GeneralContainer>
Expand Down
3 changes: 1 addition & 2 deletions src/components/Onboarding/Location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const Location = ({ navigation, isRTL, strings, toggleWebview }: Props) => {

if (IS_IOS) {
navigation.navigate('LocationIOS');

} else if(ENABLE_BLE){
} else if (ENABLE_BLE) {
// got to this only if ble enabled
navigation.navigate('Bluetooth');
} else {
Expand Down
12 changes: 5 additions & 7 deletions src/components/common/GoogleTimeLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ const GoogleTimeLine = ({ strings, toggleWebview, onCompletion }: GoogleTimeLine
});




const onMessage = async ({ nativeEvent: { data } }: WebViewMessageEvent) => {
if (!data) {
return;
Expand Down Expand Up @@ -221,11 +219,11 @@ const GoogleTimeLine = ({ strings, toggleWebview, onCompletion }: GoogleTimeLine

{
state === 'before' && (
<View style={{width: SCREEN_WIDTH * 0.7, alignItems: 'center'}}>
<TouchableOpacity onPress={() => toggleWebview(true, USAGE_PRIVACY)}>
<Text style={{ fontSize: 14 }}>{additionalInfo}</Text>
<View style={styles.bottomBorder} />
</TouchableOpacity>
<View style={{ width: SCREEN_WIDTH * 0.7, alignItems: 'center' }}>
<TouchableOpacity onPress={() => toggleWebview(true, USAGE_PRIVACY)}>
<Text style={{ fontSize: 14 }}>{additionalInfo}</Text>
<View style={styles.bottomBorder} />
</TouchableOpacity>
</View>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/constants/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ export const USAGE_PRIVACY = 'USAGE_PRIVACY';

// BLE
export const USER_AGREE_TO_BLE = 'USER_AGREE_TO_BLE';
export const ENABLE_BLE = false
export const ENABLE_BLE = false;
4 changes: 2 additions & 2 deletions src/services/BLEService.android.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import defaultBleResponse from '../constants/defaultBleResponse.json'
import defaultBleResponse from '../constants/defaultBleResponse.json';

export const initBLETracing = Promise.resolve;

Expand All @@ -7,7 +7,7 @@ export const registerBLEListeners = () => {};
export const fetchInfectionDataByConsent = async () => defaultBleResponse;


export const match = async () => []
export const match = async () => [];

// import { NativeEventEmitter, Clipboard, Alert } from 'react-native';
// import AsyncStorage from '@react-native-community/async-storage';
Expand Down
2 changes: 1 addition & 1 deletion src/services/BLEService.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const registerBLEListeners = () => {};
export const fetchInfectionDataByConsent = async () => [];


export const match = async () => []
export const match = async () => [];
6 changes: 3 additions & 3 deletions src/services/DeepLinkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { queryDB } from './Tracker';
import config from '../config/config';
import { DBLocation } from '../types';
import { IS_IOS } from '../constants/Constants';
import defaultBleResponse from '../constants/defaultBleResponse.json'
import defaultBleResponse from '../constants/defaultBleResponse.json';

export const onOpenedFromDeepLink = (url: string, navigation: StackNavigationProp<any>) => {
const { token } = parseQueryParamsFromUrlScheme(url);
Expand Down Expand Up @@ -52,7 +52,7 @@ export const getUserLocationsReadyForServer = (token: string, userAgreedToBle: b
token,
dataRows: [],
dataBleRows: defaultBleResponse
}
};

const isClusters = config().dataShareClusters;

Expand Down Expand Up @@ -90,4 +90,4 @@ export const getUserLocationsReadyForServer = (token: string, userAgreedToBle: b
} catch (e) {
reject(e);
}
});
});
3 changes: 0 additions & 3 deletions src/services/SigningService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export const downloadAndVerifySigning = (url: string) => new Promise<any>(async
resolve(json);
} else {
reject('invalid ECDSA signature');

}


} catch (error) {
reject(error);
onError({ error });
Expand Down

0 comments on commit 14dd43b

Please sign in to comment.