pleroma-fe/src/components/exporter/exporter.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

import { library } from '@fortawesome/fontawesome-svg-core'
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:22:52 +02:00
library.add(faCircleNotch)
2019-03-30 08:03:40 -04:00
const Exporter = {
props: {
getContent: {
type: Function,
2026-01-06 16:22:52 +02:00
required: true,
2019-03-30 08:03:40 -04:00
},
filename: {
type: String,
2026-01-06 16:22:52 +02:00
default: 'export.csv',
2019-03-30 08:03:40 -04:00
},
2021-04-25 14:12:34 +03:00
exportButtonLabel: { type: String },
2026-01-06 16:22:52 +02:00
processingMessage: { type: String },
2019-03-30 08:03:40 -04:00
},
2026-01-06 16:22:52 +02:00
data() {
2019-03-30 08:03:40 -04:00
return {
2026-01-06 16:22:52 +02:00
processing: false,
2019-03-30 08:03:40 -04:00
}
},
methods: {
2026-01-06 16:22:52 +02:00
process() {
2019-03-30 08:03:40 -04:00
this.processing = true
2026-01-06 16:22:52 +02:00
this.getContent().then((content) => {
const fileToDownload = document.createElement('a')
fileToDownload.setAttribute(
'href',
'data:text/plain;charset=utf-8,' + encodeURIComponent(content),
)
fileToDownload.setAttribute('download', this.filename)
fileToDownload.style.display = 'none'
document.body.appendChild(fileToDownload)
fileToDownload.click()
document.body.removeChild(fileToDownload)
// Add delay before hiding processing state since browser takes some time to handle file download
setTimeout(() => {
this.processing = false
}, 2000)
})
},
},
2019-03-30 08:03:40 -04:00
}
export default Exporter