From 8be8e80471e9a8c3ef26d1079ff7d5e343030de3 Mon Sep 17 00:00:00 2001 From: Mrudul Patil <91871222+mrudulpatil18@users.noreply.github.com> Date: Fri, 11 Oct 2024 05:29:11 +0530 Subject: [PATCH 1/3] persist onboarding tips visibility (#43) * persist onboarding tips visibility * using a selector with the global store * fixed formatting oversight --------- Co-authored-by: seveibar --- bun.lockb | Bin 316124 -> 316124 bytes src/components/LandingHero.tsx | 20 +++++++++++++------- src/hooks/use-global-store.ts | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/bun.lockb b/bun.lockb index d6a5ad9e97b4a5d69059e89902f50c20cfd3c4e8..34b171d56f41229f42f7381b5805164ac5ba498b 100755 GIT binary patch delta 50 zcmcb!RQS$P;f5B*7N#xC?%JG;aRzz@dWHs;+XJ+jZ?keh_+}RE#)iz>jSX2=E(8FO C;trSq delta 50 zcmcb!RQS$P;f5B*7N#xC?%JG8If*5y#U%_3+XJ+jZ?kg1`0d7q%-f9(SynCt0J{DV AcmMzZ diff --git a/src/components/LandingHero.tsx b/src/components/LandingHero.tsx index 451c7eb0..e94d1cb8 100644 --- a/src/components/LandingHero.tsx +++ b/src/components/LandingHero.tsx @@ -1,18 +1,22 @@ -import { useState } from "react" -import { useLocation, Link } from "wouter" -import { TypeBadge } from "./TypeBadge" import { Button } from "@/components/ui/button" -import { CreateNewSnippetHero } from "./CreateNewSnippetHero" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" +import { Link, useLocation } from "wouter" +import { useGlobalStore } from "../hooks/use-global-store" +import { CreateNewSnippetHero } from "./CreateNewSnippetHero" +import { TypeBadge } from "./TypeBadge" export const LandingHero = () => { - const [visible, setVisible] = useState(true) + const { should_onboarding_tips_be_closed, setOnboardingTipsClosed } = + useGlobalStore((state) => ({ + should_onboarding_tips_be_closed: state.should_onboarding_tips_be_closed, + setOnboardingTipsClosed: state.setOnboardingTipsClosed, + })) const [, setLocation] = useLocation() return (
- {visible && ( + {!should_onboarding_tips_be_closed && ( @@ -20,7 +24,9 @@ export const LandingHero = () => { diff --git a/src/hooks/use-global-store.ts b/src/hooks/use-global-store.ts index 0c8fd81c..2d34fed5 100644 --- a/src/hooks/use-global-store.ts +++ b/src/hooks/use-global-store.ts @@ -9,6 +9,8 @@ export type Store = { github_username: string } | null setSession: (session: Store["session"]) => any + should_onboarding_tips_be_closed: boolean + setOnboardingTipsClosed: (closed: boolean) => any } export const useGlobalStore = create()( @@ -16,6 +18,9 @@ export const useGlobalStore = create()( (set) => ({ session: null, setSession: (session) => set({ session }), + should_onboarding_tips_be_closed: false, + setOnboardingTipsClosed: (closed) => + set({ should_onboarding_tips_be_closed: closed }), }), { name: "session_store", From 4f9539d754067dedb1bc45904f4b6dc261c74a94 Mon Sep 17 00:00:00 2001 From: Severin Ibarluzea Date: Fri, 11 Oct 2024 07:44:53 -0700 Subject: [PATCH 2/3] fix code editor scrolling (#51) --- src/components/CodeEditor.tsx | 12 +++++++++++- src/hooks/use-run-tsx/index.tsx | 10 +++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/CodeEditor.tsx b/src/components/CodeEditor.tsx index 80b19041..17d11587 100644 --- a/src/components/CodeEditor.tsx +++ b/src/components/CodeEditor.tsx @@ -90,6 +90,7 @@ export const CodeEditor = ({ ata(` import React from "@types/react/jsx-runtime" import { Circuit } from "@tscircuit/core" +import type { CommonLayoutProps } from "@tscircuit/props" ${code} `) @@ -140,5 +141,14 @@ ${code} return
{code}
} - return
+ return ( +
+ ) } diff --git a/src/hooks/use-run-tsx/index.tsx b/src/hooks/use-run-tsx/index.tsx index e9721cdc..e84cbbbd 100644 --- a/src/hooks/use-run-tsx/index.tsx +++ b/src/hooks/use-run-tsx/index.tsx @@ -104,13 +104,17 @@ export const useRunTsx = ({ const module = evalCompiledJs(compiledJs!) - if (Object.keys(module.exports).length > 1) { + const componentExportKeys = Object.keys(module.exports).filter( + (key) => !key.startsWith("use"), + ) + + if (componentExportKeys.length > 1) { throw new Error( - `Too many exports, only export one thing. You exported: ${JSON.stringify(Object.keys(module.exports))}`, + `Too many exports, only export one component. You exported: ${JSON.stringify(Object.keys(module.exports))}`, ) } - const primaryKey = Object.keys(module.exports)[0] + const primaryKey = componentExportKeys[0] const UserElm = (props: any) => React.createElement(module.exports[primaryKey], props) From 6a340a8ff5e36852436ebaaf5f0b05c657f76448 Mon Sep 17 00:00:00 2001 From: Abdoaslam Allawlabi Date: Fri, 11 Oct 2024 22:18:23 +0200 Subject: [PATCH 3/3] Implemented a download function for the circuitJson download button. (#49) * Implemented circuitJson download button and function * fixed type error * passed down circuitJson to download componant * fixed bun.locb conflict * applied requested changes * formated --------- Co-authored-by: Your Name --- bun.lockb | Bin package.json | 2 ++ src/components/CodeAndPreview.tsx | 1 + src/components/DownloadButtonAndMenu.tsx | 30 ++++++++++++------ src/components/EditorNav.tsx | 9 +++++- src/lib/download-fns/createBlobURL.ts | 4 +++ .../download-fns/download-circuit-json-fn.ts | 7 ++++ src/pages/view-snippet.tsx | 6 +++- 8 files changed, 48 insertions(+), 11 deletions(-) mode change 100755 => 100644 bun.lockb create mode 100644 src/lib/download-fns/createBlobURL.ts create mode 100644 src/lib/download-fns/download-circuit-json-fn.ts diff --git a/bun.lockb b/bun.lockb old mode 100755 new mode 100644 diff --git a/package.json b/package.json index a8956340..a02170e4 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@tscircuit/3d-viewer": "^0.0.32", "@tscircuit/footprinter": "^0.0.68", "@tscircuit/pcb-viewer": "^1.10.5", + "@types/file-saver": "^2.0.7", "@types/ms": "^0.7.34", "@typescript/ata": "^0.9.7", "@valtown/codemirror-ts": "^2.2.0", @@ -66,6 +67,7 @@ "easyeda": "^0.0.32", "embla-carousel-react": "^8.3.0", "fflate": "^0.8.2", + "file-saver": "^2.0.5", "immer": "^10.1.1", "input-otp": "^1.2.4", "jose": "^5.9.3", diff --git a/src/components/CodeAndPreview.tsx b/src/components/CodeAndPreview.tsx index d4c44c98..3c7b9ff6 100644 --- a/src/components/CodeAndPreview.tsx +++ b/src/components/CodeAndPreview.tsx @@ -98,6 +98,7 @@ export function CodeAndPreview({ snippet }: Props) { return (
@@ -20,14 +31,15 @@ export function DownloadButtonAndMenu({ className }: { className?: string }) { - - - Download TSX - - tsx - - - + + downloadCircuitJson( + circuitJson, + snippetUnscopedName || "circuit" + ".json", + ) + } + > Download Circuit JSON diff --git a/src/components/EditorNav.tsx b/src/components/EditorNav.tsx index 07872924..8fda04a4 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" @@ -34,6 +35,7 @@ import { TypeBadge } from "./TypeBadge" import { SnippetLink } from "./SnippetLink" export default function EditorNav({ + circuitJson, snippet, code, hasUnsavedChanges, @@ -42,6 +44,7 @@ export default function EditorNav({ onSave, isSaving, }: { + circuitJson: any snippet: Snippet code: string hasUnsavedChanges: boolean @@ -111,7 +114,11 @@ export default function EditorNav({ Edit with AI - + - +
Code