Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
handful of fixes (#1314)
Browse files Browse the repository at this point in the history
* handful of fixes
  • Loading branch information
andrewxhill authored Aug 22, 2019
1 parent 9c07c34 commit 0f7e9d1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 68 deletions.
37 changes: 26 additions & 11 deletions App/Containers/FeedList/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -137,9 +138,23 @@ class Alerts extends React.Component<Props, State> {
)
}

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'
)
}
}
}
}

Expand All @@ -165,7 +180,7 @@ class Alerts extends React.Component<Props, State> {
<TouchableOpacity
activeOpacity={0.9}
style={ALERT_CONTAINER}
onPress={this.touchAlert(type)}
onPress={this.routeAlertEngagement(type)}
>
<View style={ALERT_CONTENT}>
{this.renderAlertCategory(linkText)}
Expand Down Expand Up @@ -216,7 +231,7 @@ class Alerts extends React.Component<Props, State> {
<TouchableOpacity
activeOpacity={0.9}
style={ALERT_CONTAINER}
onPress={this.touchAlert(type)}
onPress={this.routeAlertEngagement(type)}
>
<View style={ALERT_CONTENT}>
{this.renderAlertCategory(linkText)}
Expand Down Expand Up @@ -270,8 +285,8 @@ class Alerts extends React.Component<Props, State> {
}

const mapDispatchToProps = (dispatch: Dispatch<RootAction>): DispatchProps => ({
routeAlertEngagement: (type: LocalAlertType) =>
dispatch(updatesActions.routeAlertEngagement(type))
removeAlert: (type: LocalAlertType) =>
dispatch(updatesActions.removeAlert(type))
})

export default connect(
Expand Down
7 changes: 6 additions & 1 deletion App/Containers/FeedList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ class Notifications extends React.Component<Props, State> {
if (!this.props.alerts.length) {
return
}
return <Alerts alerts={this.props.alerts} />
return (
<Alerts
alerts={this.props.alerts}
navigate={this.props.navigation.navigate}
/>
)
}
_renderItems() {
return (
Expand Down
7 changes: 0 additions & 7 deletions App/features/updates/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
})
Expand Down
83 changes: 34 additions & 49 deletions App/features/updates/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,30 +258,6 @@ export function* reviewThreadInvite(
}
}

export function* routeAlertEngagement() {
while (true) {
const action: ActionType<typeof actions.routeAlertEngagement> = 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)
Expand All @@ -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, '')
Expand All @@ -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() {
Expand All @@ -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),
Expand Down

0 comments on commit 0f7e9d1

Please sign in to comment.