From a94dfa48efe219029ef4b112dad38bff92e08771 Mon Sep 17 00:00:00 2001 From: ochafik Date: Sun, 26 Mar 2023 08:33:49 +0100 Subject: [PATCH] Warn user before they download a preview --- src/App.tsx | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 4089b00..7839c93 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -17,6 +17,7 @@ import { TabMenu } from 'primereact/tabmenu'; import { Badge } from 'primereact/badge'; import { Menu } from 'primereact/menu'; import { ToggleButton } from 'primereact/togglebutton'; +import { ConfirmDialog, confirmDialog } from 'primereact/confirmdialog'; import { getParentDir } from './filesystem'; import { BreadCrumb } from 'primereact/breadcrumb'; import { ScrollPanel } from 'primereact/scrollpanel'; @@ -242,12 +243,31 @@ export function ViewerPanel({className, style}: {className?: string, style?: CSS function downloadOutput(state: State) { if (!state.output) return; - const a = document.createElement('a') - a.href = state.output.stlFileURL - a.download = state.output.isPreview ? 'preview.stl' : 'render.stl'; - document.body.appendChild(a) - a.click() - document.body.removeChild(a) + + const fileName = state.output!.isPreview ? 'preview.stl' : 'render.stl'; + const doDownload = () => { + const a = document.createElement('a') + a.href = state.output!.stlFileURL + a.download = fileName; + document.body.appendChild(a) + a.click() + document.body.removeChild(a) + }; + + if (state.output.isPreview && state.params.source.indexOf('$preview') >= 0) { + confirmDialog({ + message: "This model references the $preview variable but hasn't been rendered (F6), or its rendering is stale. You're about to download the preview result itself, which may not have the intended refinement of the render. Sure you want to proceed?", + header: 'Preview vs. Render', + icon: 'pi pi-exclamation-triangle', + accept: () => doDownload, + acceptLabel: `Download ${fileName}`, + rejectLabel: 'Cancel' + // reject: () => {} + }); + } else { + doDownload(); + } + } @@ -333,6 +353,8 @@ function Footer({style}: {style?: CSSProperties}) { + + {state.output && (