From 217f19198108582e2e260e07afa1efc2e25cf380 Mon Sep 17 00:00:00 2001 From: Cole Lawrence Date: Wed, 20 Jul 2022 09:45:50 -0400 Subject: [PATCH] Export better named files to reduce confusion of `state.json` --- .../src/panels/DetailPanel/ProjectDetails.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/theatre/studio/src/panels/DetailPanel/ProjectDetails.tsx b/theatre/studio/src/panels/DetailPanel/ProjectDetails.tsx index aeb347c..cff3fed 100644 --- a/theatre/studio/src/panels/DetailPanel/ProjectDetails.tsx +++ b/theatre/studio/src/panels/DetailPanel/ProjectDetails.tsx @@ -27,6 +27,10 @@ const ProjectDetails: React.FC<{ const project = projects[0] 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) @@ -36,13 +40,16 @@ const ProjectDetails: React.FC<{ null, 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 a = document.createElement('a') - a.href = objUrl - a.target = '_blank' - a.setAttribute('download', 'state.json') - a.rel = 'noopener' + const a = Object.assign(document.createElement('a'), { + href: objUrl, + target: '_blank', + rel: 'noopener', + }) + a.setAttribute('download', suggestedFileName) a.click() setDownloaded(true)