From 36cb2c5951c3eca9f0c2ec9a6c4aecd2e620729a Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Thu, 8 Aug 2024 16:09:09 +0200 Subject: [PATCH] Implement download experiment button --- .../class-solid/src/components/Experiment.tsx | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/apps/class-solid/src/components/Experiment.tsx b/apps/class-solid/src/components/Experiment.tsx index 9a2b452..f01feac 100644 --- a/apps/class-solid/src/components/Experiment.tsx +++ b/apps/class-solid/src/components/Experiment.tsx @@ -1,5 +1,5 @@ -import { Show, createSignal } from "solid-js"; -import { Button } from "~/components/ui/button"; +import { Show, createMemo, createSignal, onCleanup } from "solid-js"; +import { Button, buttonVariants } from "~/components/ui/button"; import { type Experiment, deleteExperiment, @@ -89,6 +89,38 @@ function RunningIndicator() { ); } +function DownloadExperiment(props: { experiment: Experiment }) { + const downloadUrl = createMemo(() => { + // Drop id and running + const data = { + name: props.experiment.name, + description: props.experiment.description, + config: props.experiment.config, + output: props.experiment.output, + }; + return URL.createObjectURL( + new Blob([JSON.stringify(data, undefined, 2)], { type: "application/json" }), + ); + }); + + onCleanup(() => { + URL.revokeObjectURL(downloadUrl()); + }); + + const filename = `class-${props.experiment.id}.json`; + + return ( + + + + ); +} + export function ExperimentCard(experiment: Experiment) { return ( @@ -111,10 +143,7 @@ export function ExperimentCard(experiment: Experiment) { }> - {/* TODO: implement download functionality */} - +