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
+1 -13
View File
@@ -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')
}