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:
@@ -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()}
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user