feat: show toast on some errors

This commit is contained in:
2026-05-07 17:19:08 +02:00
parent f415edab57
commit 4aff3874d3
3 changed files with 19 additions and 8 deletions
+2
View File
@@ -1,5 +1,6 @@
import type { createKeyMap } from '$lib/helpers/createKeyMap'; import type { createKeyMap } from '$lib/helpers/createKeyMap';
import { panelState } from '$lib/sidebar/PanelState.svelte'; import { panelState } from '$lib/sidebar/PanelState.svelte';
import { toast } from '@nodarium/ui';
import FileSaver from 'file-saver'; import FileSaver from 'file-saver';
import type { GraphManager } from './graph-manager.svelte'; import type { GraphManager } from './graph-manager.svelte';
import type { GraphState } from './graph-state.svelte'; import type { GraphState } from './graph-state.svelte';
@@ -146,6 +147,7 @@ export function setupKeymaps(keymap: Keymap, graph: GraphManager, graphState: Gr
type: 'application/json;charset=utf-8' type: 'application/json;charset=utf-8'
}); });
FileSaver.saveAs(blob, 'nodarium-graph.json'); FileSaver.saveAs(blob, 'nodarium-graph.json');
toast('Graph downloaded', 'success', 1500);
} }
}); });
@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { Button } from '@nodarium/ui'; import { Button, toast } from '@nodarium/ui';
import FileSaver from 'file-saver'; import FileSaver from 'file-saver';
import type { Group } from 'three'; import type { Group } from 'three';
import type { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js'; import type { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';
@@ -29,11 +29,12 @@
exporter.parse( exporter.parse(
scene, scene,
(gltf) => { (gltf) => {
// download .gltf file
download(gltf as ArrayBuffer, 'plant', 'text/plain', 'gltf'); download(gltf as ArrayBuffer, 'plant', 'text/plain', 'gltf');
toast('Exported as GLTF', 'success');
}, },
(err) => { (err) => {
console.log(err); const msg = err instanceof Error ? err.message : String(err);
toast(`GLTF export failed: ${msg}`, 'error');
} }
); );
} }
@@ -46,9 +47,14 @@
objExporter = new m.OBJExporter(); objExporter = new m.OBJExporter();
return objExporter; return objExporter;
})); }));
const result = exporter.parse(scene); try {
// download .obj file const result = exporter.parse(scene);
download(result, 'plant', 'text/plain', 'obj'); download(result, 'plant', 'text/plain', 'obj');
toast('Exported as OBJ', 'success');
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
toast(`OBJ export failed: ${msg}`, 'error');
}
} }
</script> </script>
+5 -2
View File
@@ -29,7 +29,7 @@
import { tutorialConfig } from '$lib/tutorial/tutorial-config'; import { tutorialConfig } from '$lib/tutorial/tutorial-config';
import { Planty } from '@nodarium/planty'; import { Planty } from '@nodarium/planty';
import type { Graph, NodeInstance } from '@nodarium/types'; import type { Graph, NodeInstance } from '@nodarium/types';
import { Spinner } from '@nodarium/ui'; import { Spinner, Toast, toast } from '@nodarium/ui';
import { createPerformanceStore } from '@nodarium/utils'; import { createPerformanceStore } from '@nodarium/utils';
import type { Group } from 'three'; import type { Group } from 'three';
@@ -135,7 +135,8 @@
} }
viewerComponent?.update(graphResult); viewerComponent?.update(graphResult);
} catch (error) { } catch (error) {
console.log('errors', error); const msg = error instanceof Error ? error.message : String(error);
toast(`Execution failed: ${msg}`, 'error');
} finally { } finally {
clearTimeout(timeout); clearTimeout(timeout);
isExecuting = false; isExecuting = false;
@@ -384,6 +385,8 @@
</Grid.Row> </Grid.Row>
</div> </div>
<Toast />
<style> <style>
header { header {
background-color: var(--color-layer-1); background-color: var(--color-layer-1);