Fixes the 2 csv files being created on export, in Downloads

This commit is contained in:
Sofiya Tepikin
2018-12-11 23:06:10 +01:00
parent 4a1f0ccbdd
commit 3641f0b1a1
4 changed files with 26 additions and 18 deletions
+14 -3
View File
@@ -1,13 +1,20 @@
import Share from 'react-native-share'
import { getCycleDaysSortedByDate } from '../../db'
import getDataAsCsvDataUri from '../../lib/import-export/export-to-csv'
import alertError from './alert-error'
import { settings } from '../../i18n/en/settings'
import RNFS from 'react-native-fs'
export default async function openShareDialogAndExport() {
export default async function exportData() {
let data
const labels = settings.export
const cycleDaysByDate = getCycleDaysSortedByDate()
if (!cycleDaysByDate.length) return alertError(labels.errors.noData)
try {
data = getDataAsCsvDataUri()
data = getDataAsCsvDataUri(cycleDaysByDate)
if (!data) {
return alertError(labels.errors.noData)
}
@@ -17,13 +24,17 @@ export default async function openShareDialogAndExport() {
}
try {
const path = RNFS.DocumentDirectoryPath + '/data.csv'
await RNFS.writeFile(path, data)
await Share.open({
title: labels.title,
url: data,
url: `file://${path}`,
subject: labels.subject,
type: 'text/csv',
showAppsToView: true
})
} catch (err) {
console.error(err)
return alertError(labels.errors.problemSharing)