From 0f7e9d1ca99e0554dce0721d4b2b1b81c397ec22 Mon Sep 17 00:00:00 2001 From: "Andrew W. Hill" Date: Wed, 21 Aug 2019 22:45:31 -0700 Subject: [PATCH] handful of fixes (#1314) * handful of fixes --- App/Containers/FeedList/Alerts.tsx | 37 +++++++++---- App/Containers/FeedList/index.tsx | 7 ++- App/features/updates/actions.ts | 7 --- App/features/updates/sagas.ts | 83 ++++++++++++------------------ 4 files changed, 66 insertions(+), 68 deletions(-) diff --git a/App/Containers/FeedList/Alerts.tsx b/App/Containers/FeedList/Alerts.tsx index 92df6eb0a..4343e075b 100644 --- a/App/Containers/FeedList/Alerts.tsx +++ b/App/Containers/FeedList/Alerts.tsx @@ -5,13 +5,12 @@ import { RootAction } from '../../Redux/Types' import { View, Text, - FlatList, Image, - ListRenderItemInfo, StyleSheet, TouchableOpacity, ViewStyle, - TextStyle + TextStyle, + Linking } from 'react-native' import { updatesActions } from '../../features/updates' import { LocalAlert, LocalAlertType } from '../../features/updates/models' @@ -41,10 +40,12 @@ const ALERT_BLURB: TextStyle = { interface ScreenProps { alerts: LocalAlert[] + // @ts-ignore + navigate: any } interface DispatchProps { - routeAlertEngagement: (type: LocalAlertType) => void + removeAlert: (type: LocalAlertType) => void } type Props = ScreenProps & DispatchProps @@ -137,9 +138,23 @@ class Alerts extends React.Component { ) } - touchAlert = (type: LocalAlertType) => { - return () => { - this.props.routeAlertEngagement(type) + routeAlertEngagement = (type: LocalAlertType) => { + switch (type) { + case LocalAlertType.NoStorageBot: { + return () => { + this.props.navigate('RegisterCafe', { + backTo: 'Notifications' + }) + } + } + case LocalAlertType.UpgradeNeeded: { + return () => { + this.props.removeAlert(LocalAlertType.UpgradeNeeded) + Linking.openURL( + 'https://itunes.apple.com/us/app/textile-photos/id1366428460' + ) + } + } } } @@ -165,7 +180,7 @@ class Alerts extends React.Component { {this.renderAlertCategory(linkText)} @@ -216,7 +231,7 @@ class Alerts extends React.Component { {this.renderAlertCategory(linkText)} @@ -270,8 +285,8 @@ class Alerts extends React.Component { } const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ - routeAlertEngagement: (type: LocalAlertType) => - dispatch(updatesActions.routeAlertEngagement(type)) + removeAlert: (type: LocalAlertType) => + dispatch(updatesActions.removeAlert(type)) }) export default connect( diff --git a/App/Containers/FeedList/index.tsx b/App/Containers/FeedList/index.tsx index 74bfc6b8c..f4c2e3a55 100644 --- a/App/Containers/FeedList/index.tsx +++ b/App/Containers/FeedList/index.tsx @@ -192,7 +192,12 @@ class Notifications extends React.Component { if (!this.props.alerts.length) { return } - return + return ( + + ) } _renderItems() { return ( diff --git a/App/features/updates/actions.ts b/App/features/updates/actions.ts index 5be7e2af7..6089a6b44 100644 --- a/App/features/updates/actions.ts +++ b/App/features/updates/actions.ts @@ -72,13 +72,6 @@ export const reviewNotificationThreadInvite = createAction( } ) -export const routeAlertEngagement = createAction( - 'ROUTE_ALERT_ENGAGEMENT', - resolve => { - return (type: LocalAlertType) => resolve({ type }) - } -) - export const insertAlert = createAction('INSERT_ALERT', resolve => { return (type: LocalAlertType, weight?: number) => resolve({ type, weight }) }) diff --git a/App/features/updates/sagas.ts b/App/features/updates/sagas.ts index dac6af953..eb3235454 100644 --- a/App/features/updates/sagas.ts +++ b/App/features/updates/sagas.ts @@ -258,30 +258,6 @@ export function* reviewThreadInvite( } } -export function* routeAlertEngagement() { - while (true) { - const action: ActionType = yield take( - getType(actions.routeAlertEngagement) - ) - const { type } = action.payload - switch (type) { - case LocalAlertType.NoStorageBot: { - yield call(NavigationService.navigate, 'RegisterCafe', { - backTo: 'Notifications' - }) - return - } - case LocalAlertType.UpgradeNeeded: { - yield put(actions.removeAlert(LocalAlertType.UpgradeNeeded)) - Linking.openURL( - 'https://itunes.apple.com/us/app/textile-photos/id1366428460' - ) - return - } - } - } -} - export function* updateCafeAlert() { const cafes = yield select((state: RootState) => cafeSelectors.registeredCafes(state.cafes) @@ -301,7 +277,7 @@ export function* updateReleasesAlert() { // Compares a semver, returns True of a < b function outOfDate(a: string, b: string) { let i - const regExStrip0 = /(\.0+)+$/ + const regExStrip0 = /(\.+)+$/ const segmentsA = a .replace('v', '') .replace(regExStrip0, '') @@ -312,35 +288,45 @@ export function* updateReleasesAlert() { .split('.') const l = Math.min(segmentsA.length, segmentsB.length) for (i = 0; i < l; i++) { - if (parseInt(segmentsA[i], 10) < parseInt(segmentsB[i], 10)) { - return true + const semA = parseInt(segmentsA[i], 10) + const semB = parseInt(segmentsB[i], 10) + if (semA === semB) { + continue + } else { + return semA < semB } } return segmentsA.length < segmentsB.length } - // Attempt to check latest releasae in the user's region - const locale = NativeModules.SettingsManager.settings.AppleLocale // "fr_FR" - const iso = locale - .split('_') - .reverse()[0] - .toLowerCase() - const country = iso && iso.length === 2 ? `&country=${iso}` : '' - const query = yield call( - fetch, - `https://itunes.apple.com/lookup?id=1366428460${country}` - ) - const result = yield call([query, query.json]) - // Continue only if data returned - if (result.results && result.results.length > 0) { - const version = yield call(Textile.version) - const needUpgrade = outOfDate(version, result.results[0].version) - // Check app store version against local API version - if (needUpgrade) { - yield put(actions.insertAlert(LocalAlertType.UpgradeNeeded, 1)) - return + try { + // Attempt to check latest releasae in the user's region + const locale = NativeModules.SettingsManager.settings.AppleLocale // "fr_FR" + const iso = locale + .split('_') + .reverse()[0] + .toLowerCase() + const country = iso && iso.length === 2 ? `&country=${iso}` : '' + const query = yield call( + fetch, + `https://itunes.apple.com/lookup?id=1366428460${country}` + ) + const result = yield call([query, query.json]) + // Continue only if data returned + if (result.results && result.results.length > 0) { + const version = yield call(Textile.version) + const needUpgrade = outOfDate(version, result.results[0].version) + // Check app store version against local API version + if (needUpgrade) { + yield put(actions.insertAlert(LocalAlertType.UpgradeNeeded, 1)) + return + } else { + yield put(actions.removeAlert(LocalAlertType.UpgradeNeeded)) + } } + } catch (err) { + // Default no alert + yield put(actions.removeAlert(LocalAlertType.UpgradeNeeded)) } - yield put(actions.removeAlert(LocalAlertType.UpgradeNeeded)) } export function* refreshAlerts() { @@ -349,7 +335,6 @@ export function* refreshAlerts() { export default function*() { yield all([ - routeAlertEngagement(), takeEvery(getType(cafesActions.getCafeSessions.success), refreshAlerts), takeEvery(getType(actions.newNotificationRequest), handleNewNotification), takeEvery(getType(actions.notificationEngagement), handleEngagement),