fix: bring back download prompt after fetching event data

This commit is contained in:
Ondřej Synáček 2020-12-20 14:51:28 +01:00
parent df853d39af
commit a5b9887fec
2 changed files with 12 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import { postURL } from '../services' import { postURL } from '../services'
import { eventStore, parseStatusStore, requestStore } from '../stores' import { eventStore, parseStatusStore, requestStore } from '../stores'
import { Request } from '../records' import { Request } from '../records'
import { uuidv4, parseStartTimeFromiCalString } from '../utils' import { uuidv4, parseStartTimeFromiCalString, promptDownload } from '../utils'
import { extractEventDataFromHTML } from '../../../lib/services/ics-retriever' import { extractEventDataFromHTML } from '../../../lib/services/ics-retriever'
import generateICS from '../../../lib/services/ics-generator' import generateICS from '../../../lib/services/ics-generator'
@ -38,13 +38,6 @@ const createICS = async (html, url, { logger }) => {
const dataUri = encodeURIComponent(text) const dataUri = encodeURIComponent(text)
const uri = `data:text/calendar;charset=utf-8,${dataUri}` const uri = `data:text/calendar;charset=utf-8,${dataUri}`
// TODO: create download link
// link.setAttribute('href', uri)
// link.setAttribute('download', 'download.ics')
// link.click()
// input.value = ''
const summaryMatch = text.match(/SUMMARY:.*/)[0] const summaryMatch = text.match(/SUMMARY:.*/)[0]
const summary = summaryMatch ? summaryMatch.replace(/SUMMARY:/, '') : '' const summary = summaryMatch ? summaryMatch.replace(/SUMMARY:/, '') : ''
const startTimeMatches = text.match(/DTSTART:.*/) const startTimeMatches = text.match(/DTSTART:.*/)
@ -62,6 +55,8 @@ const createICS = async (html, url, { logger }) => {
}) })
parseStatusStore.set(null) parseStatusStore.set(null)
promptDownload(uri)
} catch (err) { } catch (err) {
parseStatusStore.set(err) parseStatusStore.set(err)
} }

View File

@ -46,3 +46,12 @@ export const parseStartTimeFromiCalString = (text = '') => {
return parsedDate.toString() return parsedDate.toString()
} }
export const promptDownload = (uri) => {
const link = document.getElementById('current-download')
link.setAttribute('href', uri)
link.setAttribute('download', 'download.ics')
link.click()
link.setAttribute('href', '')
}