-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented a download function for the circuitJson download button. #49
Conversation
@Abse2001 is attempting to deploy a commit to the tscircuit Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment, useRunTsx is pretty expensive, i would also recommend the file-saver
module from @DhairyaMajmudar PR, you could also implement a different download format to avoid conflicts
src/components/EditorNav.tsx
Outdated
@@ -51,6 +52,7 @@ export default function EditorNav({ | |||
onSave: () => void | |||
}) { | |||
const [, navigate] = useLocation() | |||
const { circuitJson } = useRunTsx(code, snippet?.snippet_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you avoid using useRunTsx
? It's a very expensive hook and the circuitJson should be computed elsewhere
src/components/EditorNav.tsx
Outdated
@@ -111,7 +114,11 @@ export default function EditorNav({ | |||
<Sparkles className="mr-1 h-3 w-3" /> | |||
Edit with AI | |||
</Button> | |||
<DownloadButtonAndMenu className="hidden md:flex" /> | |||
<DownloadButtonAndMenu | |||
fileName={snippet.unscoped_name} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
important concept: "variable transarency" means you keep the same variable name as it is passed around. Don't rename variables if you don't have to. When I read this code, i was surprised that fileName was the same as the unscoped name, i expected it to have an extension. Naming is hard, renaming makes you have to do it more often
fileName={snippet.unscoped_name} | |
snippetUnscopedName={snippet.unscoped_name} |
try { | ||
const circuitJson = JSON.stringify(content, null, 2) | ||
const blob = new Blob([circuitJson], { type: "application/json" }) | ||
saveAs(blob, fileName) | ||
} catch (error) { | ||
throw error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anti-pattern: useless try catch (it doesn't do anything here)
try { | |
const circuitJson = JSON.stringify(content, null, 2) | |
const blob = new Blob([circuitJson], { type: "application/json" }) | |
saveAs(blob, fileName) | |
} catch (error) { | |
throw error | |
} | |
const circuitJson = JSON.stringify(content, null, 2) | |
const blob = new Blob([circuitJson], { type: "application/json" }) | |
saveAs(blob, fileName) |
@@ -45,7 +44,6 @@ export const ViewSnippetPage = () => { | |||
<Share className="mr-1 h-3 w-3" /> | |||
Copy URL | |||
</Button> | |||
<DownloadButtonAndMenu /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove from this page? can't we give it the props?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
It seems like I've already implemented this feature here #26 |
@DhairyaMajmudar for small features like this it's just whoever gets it right first, I don't do assignment unless it's a big feature. In open-source a project can be completely stalled when people don't fix PRs quickly etc. so we won't operate where people can work on things first The best way to get issues assigned exclusively to you is to get familiar with the codebase and work on hard issues that people don't generally want, or find bugs and create your own issues. |
Issue #17