From bc709f06cfcd66209c8a6406655e40cbb54c1a2f Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 10 Oct 2024 18:00:44 +0200 Subject: [PATCH 1/6] Implemented circuitJson download button and function --- bun.lockb | Bin 309139 -> 309139 bytes src/components/DownloadButtonAndMenu.tsx | 27 ++++++++++++------ src/components/EditorNav.tsx | 8 +++++- .../download-fns/download-circuit-json-fn.ts | 12 ++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 src/lib/download-fns/download-circuit-json-fn.ts diff --git a/bun.lockb b/bun.lockb index 1deb6200df9932d5e4cbbcf2755035f27c5ece7f..c7934fe85522bf34ee74c73626920fa24f030f67 100755 GIT binary patch delta 34 qcmbRIUTE@rp@tU57N#xCo>Cl)aRzz@dWI(Lfl|!d1EpA;<^llBtqM>8 delta 34 qcmbRIUTE@rp@tU57N#xCo>Cl4If*5y#U%{wfl|!d1EpA;<^llRCJSEx diff --git a/src/components/DownloadButtonAndMenu.tsx b/src/components/DownloadButtonAndMenu.tsx index 73c6f90b..9b72c6c4 100644 --- a/src/components/DownloadButtonAndMenu.tsx +++ b/src/components/DownloadButtonAndMenu.tsx @@ -7,8 +7,19 @@ import { } from "@/components/ui/dropdown-menu" import { Button } from "@/components/ui/button" import { Download, ChevronDown } from "lucide-react" +import { downloadCircuitJson } from "@/lib/download-fns/download-circuit-json-fn" -export function DownloadButtonAndMenu({ className }: { className?: string }) { +interface DownloadButtonAndMenuProps { + className?: string + fileName: string + circuitJson: string +} + +export function DownloadButtonAndMenu({ + className, + fileName, + circuitJson, +}: DownloadButtonAndMenuProps) { return (
@@ -20,14 +31,12 @@ export function DownloadButtonAndMenu({ className }: { className?: string }) { - - - Download TSX - - tsx - - - + + downloadCircuitJson(circuitJson, fileName + ".json") + } + > Download Circuit JSON diff --git a/src/components/EditorNav.tsx b/src/components/EditorNav.tsx index 07872924..617610f9 100644 --- a/src/components/EditorNav.tsx +++ b/src/components/EditorNav.tsx @@ -24,6 +24,7 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" +import { useRunTsx } from "@/hooks/use-run-tsx" import { OpenInNewWindowIcon } from "@radix-ui/react-icons" import { encodeTextToUrlHash } from "@/lib/encodeTextToUrlHash" import { Snippet } from "fake-snippets-api/lib/db/schema" @@ -51,6 +52,7 @@ export default function EditorNav({ onSave: () => void }) { const [, navigate] = useLocation() + const { circuitJson } = useRunTsx(code, snippet?.snippet_type) return (