Skip to content

Commit

Permalink
Allows user to download data as csv
Browse files Browse the repository at this point in the history
  • Loading branch information
jonty-terrence committed Nov 18, 2020
1 parent 21313b5 commit 90d072f
Show file tree
Hide file tree
Showing 5 changed files with 25,468 additions and 18,538 deletions.
18 changes: 17 additions & 1 deletion client/components/LowerSect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react'

import db from '../firebase'

import jsonexport from 'jsonexport'

const deleteButton = () => {
deleteUserData()
}
Expand All @@ -10,12 +12,26 @@ function deleteUserData () {
db.database().ref('metaData').set(null)
}

function downloadData () {
const leadsRef = db.database().ref('metaData')

leadsRef.on('value', function (snapshot) {
snapshot.forEach(function (childSnapshot) {
const childData = childSnapshot.val()
jsonexport(childData, function (err, csv) {
if (err) return console.error(err)
console.log(csv)
})
})
})
}

class LowerSect extends React.Component {
render () {
return (
<div className="lower-sect">
<button className="delete-button" onClick={() => deleteButton()}>Clear data</button>
<button className="download-button">Download data</button>
<button className="download-button" onClick={() => downloadData()}>Download data</button>
</div>
)
}
Expand Down
51 changes: 51 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"express": "^4.17.1",
"firebase": "^8.0.0",
"heroku": "^7.42.13",
"json-2-csv": "^3.7.8",
"json2csv": "^5.0.5",
"jsonexport": "^3.0.1",
"knex": "^0.21.5",
"react-copy-to-clipboard": "^5.0.2",
"reactjs-popup": "^2.0.4",
Expand Down
Loading

0 comments on commit 90d072f

Please sign in to comment.