Skip to content
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

Merged
merged 7 commits into from
Oct 11, 2024

Conversation

Abse2001
Copy link
Contributor

@Abse2001 Abse2001 commented Oct 10, 2024

Issue #17

Copy link

vercel bot commented Oct 10, 2024

@Abse2001 is attempting to deploy a commit to the tscircuit Team on Vercel.

A member of the Team first needs to authorize it.

@Abse2001 Abse2001 changed the title I implemented a Download circuitJson button and the corresponding download function. implemented a Download circuitJson button and the corresponding download function. Oct 10, 2024
@Abse2001 Abse2001 changed the title implemented a Download circuitJson button and the corresponding download function. Implemented a download function for the circuitjson download button. Oct 10, 2024
@Abse2001 Abse2001 changed the title Implemented a download function for the circuitjson download button. Implemented a download function for the circuitJson download button. Oct 10, 2024
Copy link
Contributor

@seveibar seveibar left a 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

@@ -51,6 +52,7 @@ export default function EditorNav({
onSave: () => void
}) {
const [, navigate] = useLocation()
const { circuitJson } = useRunTsx(code, snippet?.snippet_type)
Copy link
Contributor

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

@@ -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}
Copy link
Contributor

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

Suggested change
fileName={snippet.unscoped_name}
snippetUnscopedName={snippet.unscoped_name}

Comment on lines 4 to 10
try {
const circuitJson = JSON.stringify(content, null, 2)
const blob = new Blob([circuitJson], { type: "application/json" })
saveAs(blob, fileName)
} catch (error) {
throw error
}
Copy link
Contributor

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)

Suggested change
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 />
Copy link
Contributor

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?

Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

@DhairyaMajmudar
Copy link
Contributor

It seems like I've already implemented this feature here #26

@seveibar
Copy link
Contributor

@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.

@seveibar seveibar merged commit 6a340a8 into tscircuit:main Oct 11, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants