Export better named files to reduce confusion of state.json
This commit is contained in:
parent
0b09751ada
commit
217f191981
1 changed files with 13 additions and 6 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue