Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Feature/proximity dates (#1562)
Browse files Browse the repository at this point in the history
* changed the matching logic to just use the timestamp

* remove header from proximity exposed details screen
  • Loading branch information
smcmurtry authored May 3, 2021
1 parent 6a94c20 commit dc97dd1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/navigation/MainNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface MainStackParamList extends Record<string, object | undefined> {
Tutorial: undefined;
QROnboard: undefined;
RegionSelectExposedNoPT: {drawerMenu: boolean} | undefined;
RecentExposureScreen: {id: string; exposureType: ExposureType};
RecentExposureScreen: {timestamp: number; exposureType: ExposureType};
}
const LandingScreenWithNavBar = withDarkNav(LandingScreen);
const HomeScreenWithNavBar = withDarkNav(HomeScreen);
Expand Down
18 changes: 8 additions & 10 deletions src/screens/exposureHistory/ExposureHistoryScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,25 @@ const toOutbreakExposureHistoryData = ({
}): CombinedExposureHistoryData[] => {
return history.map(outbreak => {
return {
id: outbreak.locationId,
type: ExposureType.Outbreak,
exposureType: ExposureType.Outbreak,
subtitle: severityText({severity: Number(outbreak.severity), i18n}),
timestamp: outbreak.checkInTimestamp,
};
});
};

const toProximityExposureHistoryData = ({
history,
proximityExposureTimestamps,
i18n,
}: {
history: number[];
proximityExposureTimestamps: number[];
i18n: I18n;
}): CombinedExposureHistoryData[] => {
return history.map(outbreak => {
return proximityExposureTimestamps.map(timestamp => {
return {
id: outbreak,
type: ExposureType.Proximity,
exposureType: ExposureType.Proximity,
subtitle: i18n.translate('QRCode.ProximityExposure'),
timestamp: outbreak,
timestamp,
};
});
};
Expand All @@ -74,10 +72,10 @@ export const ExposureHistoryScreen = () => {
const outbreaks = useOutbreakService();
const [clearExposedStatus] = useClearExposedStatus();
const currentOutbreakHistory = getCurrentOutbreakHistory(outbreaks.outbreakHistory);
const proximityExposure = useExposureHistory();
const proximityExposureTimestamps = useExposureHistory();
const mergedArray = [
...toOutbreakExposureHistoryData({history: currentOutbreakHistory, i18n}),
...toProximityExposureHistoryData({history: proximityExposure, i18n}),
...toProximityExposureHistoryData({proximityExposureTimestamps, i18n}),
];
const clearProximityExposure = useCallback(() => {
clearExposedStatus();
Expand Down
8 changes: 2 additions & 6 deletions src/screens/exposureHistory/RecentExposureView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ type RecentExposureScreenProps = RouteProp<MainStackParamList, 'RecentExposureSc

const ExposureView = () => {
const route = useRoute<RecentExposureScreenProps>();
if (!route.params?.id || !route.params?.exposureType) {
return null;
}
const id = route.params.id;
if (route.params.exposureType === ExposureType.Outbreak) {
return <OutbreakExposedView id={id} />;
return <OutbreakExposedView timestamp={route.params.timestamp} />;
}
if (route.params.exposureType === ExposureType.Proximity) {
return <ProximityExposureView />;
return <ProximityExposureView timestamp={route.params.timestamp} />;
}
return null;
};
Expand Down
6 changes: 3 additions & 3 deletions src/screens/exposureHistory/views/ExposureList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const ExposureList = ({exposureHistoryData}: {exposureHistoryData: Combin
const dateLocale = i18n.locale === 'fr' ? 'fr-CA' : 'en-CA';
const navigation = useNavigation();
const onDetails = useCallback(
({id, exposureType}) => navigation.navigate('RecentExposureScreen', {id, exposureType}),
({timestamp, exposureType}) => navigation.navigate('RecentExposureScreen', {timestamp, exposureType}),
[navigation],
);
exposureHistoryData.sort(function (first, second) {
Expand All @@ -28,14 +28,14 @@ export const ExposureList = ({exposureHistoryData}: {exposureHistoryData: Combin
<TouchableOpacity
style={styles.chevronIcon}
onPress={() => {
onDetails({id: `${item.id}-${item.timestamp}`, exposureType: item.type});
onDetails({timestamp: item.timestamp, exposureType: item.exposureType});
}}
>
<Box paddingVertical="m" style={styles.exposureList}>
<Box style={styles.typeIconBox}>
<Icon
size={20}
name={item.type === ExposureType.Proximity ? 'exposure-proximity' : 'exposure-outbreak'}
name={item.exposureType === ExposureType.Proximity ? 'exposure-proximity' : 'exposure-outbreak'}
/>
</Box>
<Box style={styles.boxFlex}>
Expand Down
7 changes: 5 additions & 2 deletions src/screens/home/views/ExposureDateView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ForceScreen} from 'shared/ForceScreen';
import {useCachedStorage} from 'services/StorageService';
import {log} from 'shared/logging/config';

export const ExposureDateView = () => {
export const ExposureDateView = ({timestamp}: {timestamp?: number}) => {
const i18n = useI18n();
const dateLocale = i18n.locale === 'fr' ? 'fr-CA' : 'en-CA';
const {forceScreen} = useCachedStorage();
Expand All @@ -18,10 +18,13 @@ export const ExposureDateView = () => {
if (forceScreen && forceScreen !== ForceScreen.None) {
return [getCurrentDate()];
}
if (timestamp) {
return [new Date(timestamp)];
}
const _dates = exposureNotificationService.getExposureDetectedAt();
log.debug({message: '_dates', payload: {_dates}});
return _dates;
}, [exposureNotificationService, forceScreen]);
}, [exposureNotificationService, forceScreen, timestamp]);

const formattedDates = dates.map(date => {
return formatExposedDate(date, dateLocale);
Expand Down
12 changes: 4 additions & 8 deletions src/screens/home/views/OutbreakExposedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,25 @@ import {HomeScreenTitle} from '../components/HomeScreenTitle';

import {NegativeOutbreakTestButton} from './ClearOutbreakExposureView';

export const OutbreakExposedView = ({id}: {id?: string}) => {
export const OutbreakExposedView = ({timestamp}: {timestamp?: number}) => {
const i18n = useI18n();
const {outbreakHistory} = useOutbreakService();
const currentOutbreakHistory = getCurrentOutbreakHistory(outbreakHistory);
const dateLocale = i18n.locale === 'fr' ? 'fr-CA' : 'en-CA';

let historyItem: OutbreakHistoryItem = currentOutbreakHistory[0];

if (id) {
if (timestamp) {
currentOutbreakHistory.forEach(item => {
if (item.outbreakId === id) {
if (item.checkInTimestamp === timestamp) {
historyItem = item;
}
});
}

const severity = historyItem?.severity;
const exposureDate = formatExposedDate(new Date(historyItem?.checkInTimestamp), dateLocale);
let props = {};

if (id) {
props = {header: false};
}
const props = timestamp ? {header: false} : {};

return (
<BaseHomeView iconName="hand-caution-yellow" testID="outbreakExposure" {...props}>
Expand Down
11 changes: 6 additions & 5 deletions src/screens/home/views/ProximityExposureView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ActiveContent = ({text}: {text: string}) => {
return <Text marginBottom="m">{text}</Text>;
};

const ExposureText = () => {
const ExposureText = ({timestamp}: {timestamp?: number}) => {
const {region} = useCachedStorage();
const regionalI18n = useRegionalI18n();
const regionActive = isRegionActive(region, regionalI18n.activeRegions);
Expand All @@ -32,7 +32,7 @@ const ExposureText = () => {
<Text testID="bodyText" marginBottom="m">
{i18n.translate('Home.ExposureDetected.Body1')}
</Text>
<ExposureDateView />
<ExposureDateView timestamp={timestamp} />
</RoundedBox>

<RoundedBox isFirstBox={false}>
Expand All @@ -53,10 +53,11 @@ const ExposureText = () => {
);
};

export const ProximityExposureView = () => {
export const ProximityExposureView = ({timestamp}: {timestamp?: number}) => {
const props = timestamp ? {header: false} : {};
return (
<BaseHomeView iconName="hand-caution" testID="exposure">
<ExposureText />
<BaseHomeView iconName="hand-caution" testID="exposure" {...props}>
<ExposureText timestamp={timestamp} />
</BaseHomeView>
);
};
3 changes: 1 addition & 2 deletions src/shared/qr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ export interface OutbreakHistoryItem {
}

export interface CombinedExposureHistoryData {
id?: string | number;
timestamp: number;
type: ExposureType;
exposureType: ExposureType;
subtitle: string;
}

Expand Down

0 comments on commit dc97dd1

Please sign in to comment.