Export better named files to reduce confusion of state.json

This commit is contained in:
Cole Lawrence 2022-07-20 09:45:50 -04:00
parent 0b09751ada
commit 217f191981

View file

@ -27,6 +27,10 @@ const ProjectDetails: React.FC<{
const project = projects[0] const project = projects[0]
const projectId = project.address.projectId const projectId = project.address.projectId
const slugifiedProjectId = projectId.replace(/[^\w\d'_\-]+/g, ' ').trim()
// const [dateString, _timeString] = new Date().toISOString().split('T')
// e.g. `Butterfly.theatre-project-state.json`
const suggestedFileName = `${slugifiedProjectId}.theatre-project-state.json`
const [downloaded, setDownloaded] = useState(false) const [downloaded, setDownloaded] = useState(false)
@ -36,13 +40,16 @@ const ProjectDetails: React.FC<{
null, null,
2, 2,
) )
const file = new File([str], 'state.json', {type: 'application/json'}) const file = new File([str], suggestedFileName, {
type: 'application/json',
})
const objUrl = URL.createObjectURL(file) const objUrl = URL.createObjectURL(file)
const a = document.createElement('a') const a = Object.assign(document.createElement('a'), {
a.href = objUrl href: objUrl,
a.target = '_blank' target: '_blank',
a.setAttribute('download', 'state.json') rel: 'noopener',
a.rel = 'noopener' })
a.setAttribute('download', suggestedFileName)
a.click() a.click()
setDownloaded(true) setDownloaded(true)