-
Notifications
You must be signed in to change notification settings - Fork 2
feat: improve examples and move routing logic #31
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
||
return parsedData.output; | ||
} catch (e) { | ||
console.error(`Failed to load playground with id ${id}: ${e}`); |
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.
What about displaying a user facing error if there is an issue with getting the share data?
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.
Yeah good call. There isn't really any actionable items the user could take, but looking at what other playgrounds do it seems like it's common to show a 404 page which I think would work well enough
src/server/index.tsx
Outdated
} | ||
|
||
return examples.find((e) => e.slug === example)?.code; | ||
return examples[example] ?? null; |
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.
Maybe not necessary for this PR but you could add some validation to check if the example slug is valid
src/server/routes/api.ts
Outdated
const bytes = new TextEncoder().encode(JSON.stringify(data)); | ||
|
||
// Check if the data is larger than 1mb | ||
if (bytes.length > 1024 * 1000) { |
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.
you could self document this with a const, const MAX_DATA_SIZE = 1024 * 1000;
|
||
const href = `${window.location.origin}/parameters?${params.toString()}`; | ||
{Object.entries(examples).map(([ slug, title ]) => { | ||
const href = `${window.location.origin}/parameters/example/${slug}`; | ||
return ( | ||
<DropdownMenuItem key={slug} asChild={true}> | ||
<a href={href} target="_blank" rel="noreferrer"> |
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.
It could be useful to show external link icons when opening external links
src/server/index.tsx
Outdated
@@ -54,9 +64,7 @@ app.get("*", (c) => { | |||
? "/assets/wasm_exec.js" |
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.
You could simplify these paths a bit with something like this,
const getAssetPath = (filename: string) =>
import.meta.env.PROD ? `/assets/${filename}` : `/${filename}`;
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.
Let a few of small comments but nothing blocking merging this.
Improves the code for handling examples, and moves the routing logic/code share loading from the frontend to the backend.
I also cleaned up the copy a little while I was there