Skip to content

Commit

Permalink
Implement download experiment button
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Aug 8, 2024
1 parent b6a4dd9 commit 36cb2c5
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions apps/class-solid/src/components/Experiment.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 (
<a
class={buttonVariants({ variant: "outline" })}
href={downloadUrl()}
download={filename}
type="application/json"
>
<MdiDownload />
</a>
);
}

export function ExperimentCard(experiment: Experiment) {
return (
<Card class="w-[380px]">
Expand All @@ -111,10 +143,7 @@ export function ExperimentCard(experiment: Experiment) {
</CardContent>
<CardFooter>
<Show when={!experiment.running} fallback={<RunningIndicator />}>
{/* TODO: implement download functionality */}
<Button variant="outline">
<MdiDownload />
</Button>
<DownloadExperiment experiment={experiment} />
<ExperimentSettingsDialog {...experiment} />
<Button variant="outline">
<MdiContentCopy
Expand Down

0 comments on commit 36cb2c5

Please sign in to comment.