Bug fix: make dismiss during export not fire success toast (#3882)
* Bug fix: make dismiss during export not fire success toast * Fix export fail test, since this failure errors early now * Remove throttling from send side * Move toast.loading out to when first engine command is sent, so it is shown immediately * Use shared, named constants for toast messages * Hook up a couple other error toasts to the `pendingExport.toastId`
This commit is contained in:
@ -4,8 +4,10 @@ import { browserSaveFile } from './browserSaveFile'
|
||||
|
||||
import JSZip from 'jszip'
|
||||
import ModelingAppFile from './modelingAppFile'
|
||||
import toast from 'react-hot-toast'
|
||||
import { EXPORT_TOAST_MESSAGES } from './constants'
|
||||
|
||||
const save_ = async (file: ModelingAppFile) => {
|
||||
const save_ = async (file: ModelingAppFile, toastId: string) => {
|
||||
try {
|
||||
if (isDesktop()) {
|
||||
const extension = file.name.split('.').pop() || null
|
||||
@ -20,6 +22,7 @@ const save_ = async (file: ModelingAppFile) => {
|
||||
file.name,
|
||||
new Uint8Array(file.contents)
|
||||
)
|
||||
toast.success(EXPORT_TOAST_MESSAGES.SUCCESS, { id: toastId })
|
||||
return
|
||||
}
|
||||
|
||||
@ -36,13 +39,17 @@ const save_ = async (file: ModelingAppFile) => {
|
||||
|
||||
// The user canceled the save.
|
||||
// Return early.
|
||||
if (filePathMeta.canceled) return
|
||||
if (filePathMeta.canceled) {
|
||||
toast.dismiss(toastId)
|
||||
return
|
||||
}
|
||||
|
||||
// Write the file.
|
||||
await window.electron.writeFile(
|
||||
filePathMeta.filePath,
|
||||
new Uint8Array(file.contents)
|
||||
)
|
||||
toast.success(EXPORT_TOAST_MESSAGES.SUCCESS, { id: toastId })
|
||||
} else {
|
||||
// Download the file to the user's computer.
|
||||
// Now we need to download the files to the user's downloads folder.
|
||||
@ -51,16 +58,17 @@ const save_ = async (file: ModelingAppFile) => {
|
||||
// Create a new blob.
|
||||
const blob = new Blob([new Uint8Array(file.contents)])
|
||||
// Save the file.
|
||||
await browserSaveFile(blob, file.name)
|
||||
await browserSaveFile(blob, file.name, toastId)
|
||||
}
|
||||
} catch (e) {
|
||||
// TODO: do something real with the error.
|
||||
console.error('export error', e)
|
||||
toast.error(EXPORT_TOAST_MESSAGES.FAILED, { id: toastId })
|
||||
}
|
||||
}
|
||||
|
||||
// Saves files locally from an export call.
|
||||
export async function exportSave(data: ArrayBuffer) {
|
||||
export async function exportSave(data: ArrayBuffer, toastId: string) {
|
||||
// This converts the ArrayBuffer to a Rust equivalent Vec<u8>.
|
||||
let uintArray = new Uint8Array(data)
|
||||
|
||||
@ -72,9 +80,9 @@ export async function exportSave(data: ArrayBuffer) {
|
||||
zip.file(file.name, new Uint8Array(file.contents), { binary: true })
|
||||
}
|
||||
return zip.generateAsync({ type: 'array' }).then((contents) => {
|
||||
return save_({ name: 'output.zip', contents })
|
||||
return save_({ name: 'output.zip', contents }, toastId)
|
||||
})
|
||||
} else {
|
||||
return save_(files[0])
|
||||
return save_(files[0], toastId)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user