-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Solidify new Sandcastle React structure #12639
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
base: nested-gallery
Are you sure you want to change the base?
Conversation
Thank you for the pull request, @jjspace! ✅ We can confirm we have a CLA on file for you. |
@aruniverse or maybe @angrycat9000, would one (or both?) of you have some free time to take a look at this PR and review the React usage? No need to analyze the Sandcastle structure or "business logic". I haven't done much React dev in a while and I'm trying to get used to the mental paradigms again. I just want to make sure I'm not doing anything really horrible. |
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.
I'm certainly not an expert, but the react updates here are looking good to me. The reducer looks like the right level of state management we're looking for at this stage.
Depending on how deep we go with components, we may need to look into incorporating contexts, but that seem to be excessive for the current state of things.
background-color: white; | ||
background-image: var(--_rings), var(--_gradient); | ||
|
||
/* TODO: these should pull from the stratakit directly somehow eventually */ |
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 we remove the TODO's please and get them documented in a GitHub comment?
packages/sandcastle/src/App.tsx
Outdated
// TODO: I like this method for history but we need to actually react to the user | ||
// hitting forward or back, right now it does nothing. Need to look into how that works | ||
// Might need to involve React-Router but I'd like to try and avoid if we don't need 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.
What the plan here?
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.
I thought this would be more complicated than it was but I've hooked up to the browser popstate
events to listen and respond to navigation which makes it work nicely.
Did a read through of the code. The sandcastle v2 link didn't work for me so I wasn't sure how to run it. The DOM manipulation in Otherwise looks pretty standard. Would also recommend breaking stuff down into smaller components for readability. The App component is a bit hefty and has a lot of logic that could probably be better isolated. Eg the editor set/teardown could be in its own Editor component. The gallery loading could be in its own component that uses "onGallerySelected" to communicate back to the main app. |
Thanks for the review @angrycat9000
The only DOM manipulation we're still doing is to modify/control the contents of the iframe, ie the "bucket", to load the sandcastle code. AFAIK there's not a way to do that more directly using React. I moved all that code into the |
@ggetz this PR has been cleaned up a bunch and should be good for another look |
Description
When I originally threw this together for the hackathon I tried to reuse a lot of the existing code for current sandcastle to speed up development. This meant a lot of the logic was very "imperative" oriented and was not playing nicely with React. This worked fine for a while but started to really get in the way in #12631, specifically with multiple loading methods.
This PR restructures the application to be much more "React" oriented
getValue
andsetValue
access I was doing beforeiframe
wrapper logic has been pulled out to it's ownBucket
props
on theBucket
using thecomittedCode
andrunNumber
stateEditor
instance using multiple Models. It is now a controlled component and the contents are tracked and stored in stateThis code builds off of #12631 and should be merged after that
Issue number and link
Part of #12566
Testing plan
npm run dev
from insidepackages/sandcastle
http://localhost:5173/
New
resets both the JS and HTML code, refreshes the viewer and updates the URL to the base routeid
Add button
and others work but do not refresh the viewer untilRun
is clickedF8
while focusing inside the code actually reloads the viewerRun
orF8
multiple times in a row with no code changes refreshes the viewer every timerunNumber
state, this is a workflow that must workAuthor checklist
CONTRIBUTORS.md
CHANGES.md
with a short summary of my change