Merge branch '113-add-button-to-export-to-settings-page' into 'master'

Resolve "Add button to export to settings page"

Closes #113

See merge request bloodyhealth/drip!46
This commit is contained in:
Julia Friesel
2018-08-06 12:49:44 +00:00
14 changed files with 556 additions and 287 deletions
+6
View File
@@ -69,6 +69,12 @@ export default class Home extends Component {
title="Go to chart">
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={() => navigate('settings')}
title="Go to settings">
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={() => fillWithDummyData()}
+10
View File
@@ -0,0 +1,10 @@
export const settings = {
errors: {
noData: 'There is no data to export',
couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
},
exportTitle: 'My Drip data export',
exportSubject: 'My Drip data export',
buttonLabel: 'Export data'
}
+62
View File
@@ -0,0 +1,62 @@
import React, { Component } from 'react'
import {
View,
Button,
Text,
ScrollView,
Alert
} from 'react-native'
import Share from 'react-native-share'
import getDataAsCsvDataUri from '../lib/export-to-csv'
import styles from '../styles/index'
import { settings as labels } from './labels'
export default class Settings extends Component {
constructor(props) {
super(props)
this.state = {
pickerVisible: false
}
}
render() {
return (
<ScrollView>
<Text style={styles.welcome}>{this.state.welcomeText}</Text>
<View style={styles.homeButtons}>
<View style={styles.homeButton}>
<Button
onPress={async () => {
let data
try {
data = getDataAsCsvDataUri()
if (!data) {
return Alert.alert(labels.errors.noData)
}
} catch (err) {
console.error(err)
return Alert.alert(labels.errors.couldNotConvert)
}
try {
await Share.open({
title: labels.exportTitle,
url: data,
subject: labels.exportSubject,
type: 'text/csv',
showAppsToView: true
})
} catch (err) {
console.error(err)
return Alert.alert(labels.errors.problemSharing)
}
}}
title={labels.buttonLabel}>
</Button>
</View>
</View>
</ScrollView>
)
}
}