Merge branch 'fix-2-csv-files' into 'master'
Fixes the 2 csv files being created on export, in Downloads Closes #195 See merge request bloodyhealth/drip!134
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.drip">
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.drip"
|
||||
>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
@@ -36,9 +39,11 @@
|
||||
android:grantUriPermissions="true"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
tools:replace="android:resource"
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/filepaths" />
|
||||
</provider>
|
||||
|
||||
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
|
||||
android:value="drip-notification"/>
|
||||
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="Downloads" path="Download/" />
|
||||
<root-path name="root" path="" />
|
||||
<files-path
|
||||
name="files-path"
|
||||
path="." /> <!-- Used to access into application data files -->
|
||||
</paths>
|
||||
@@ -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)
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
import objectPath from 'object-path'
|
||||
import { Base64 } from 'js-base64'
|
||||
import { getCycleDaysSortedByDate } from '../../db'
|
||||
import getColumnNamesForCsv from './get-csv-column-names'
|
||||
|
||||
export default function makeDataURI() {
|
||||
const cycleDaysSortedByDate = getCycleDaysSortedByDate()
|
||||
if (!cycleDaysSortedByDate.length) return null
|
||||
|
||||
const csv = transformToCsv(cycleDaysSortedByDate)
|
||||
const encoded = Base64.encodeURI(csv)
|
||||
// this is the MIME type android/libcore/MimeUtils expects, so we oblige
|
||||
return `data:text/comma-separated-values;base64,${encoded}`
|
||||
}
|
||||
|
||||
function transformToCsv(cycleDays) {
|
||||
export default function transformToCsv(cycleDays) {
|
||||
const columnNames = getColumnNamesForCsv()
|
||||
const rows = cycleDays
|
||||
.map(day => {
|
||||
@@ -23,7 +12,6 @@ function transformToCsv(cycleDays) {
|
||||
})
|
||||
})
|
||||
.map(row => row.join(','))
|
||||
|
||||
rows.unshift(columnNames.join(','))
|
||||
return rows.join('\n')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user