Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions packages/sandcastle/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,34 +505,27 @@ function App() {
hidden={leftPanel !== "gallery"}
galleryItems={galleryItems}
loadDemo={(item, switchToCode) => {
// Load the gallery item every time it's clicked
loadGalleryItem(item.id);

const searchParams = new URLSearchParams(window.location.search);
if (
!searchParams.has("id") ||
(searchParams.has("id") && searchParams.get("id") !== item.id)
) {
const isAlreadyActive =
searchParams.has("id") && searchParams.get("id") === item.id;

if (!isAlreadyActive) {
// only push state if it's not the current url to prevent duplicated in history
window.history.pushState(
{},
"",
`${getBaseUrl()}?id=${item.id}`,
);
if (
!searchParams.has("id") ||
(searchParams.has("id") && searchParams.get("id") !== item.id)
) {
// only push state if it's not the current url to prevent duplicated in history
window.history.pushState(
{},
"",
`${getBaseUrl()}?id=${item.id}`,
);
}
if (switchToCode) {
setLeftPanel("editor");
}

if (switchToCode) {
if (!isAlreadyActive) {
loadGalleryItem(item.id);
}
setLeftPanel("editor");
} else {
// Load the gallery item every time it's clicked ro act as a "rerun" button
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Load the gallery item every time it's clicked ro act as a "rerun" button
// Load the gallery item every time it's clicked to act as a "rerun" button

But moreover, I agree with Luke that this seems like confusing behavior.

This was intentional to keep the behavior consistent. If you click the card for a gallery item it will load it even if it is already loaded. I meant this to be a way to "re-run" without switching to the code panel. I think this is good.

Why do we need to rerun from the gallery list at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this behavior there is (currently) no way to "re-run" or reset a sandcastle without first switching to the code view. I don't know about others but I personally find I often want to reset sandcastles if I've moved the camera or edited values and just want a quick way to get back to the "start". Maybe we need to move the Run button or duplicate it but for now this solution felt like a good compromise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ggetz did you have thoughts around this?

loadGalleryItem(item.id);
}
}}
/>
Expand Down
5 changes: 4 additions & 1 deletion packages/sandcastle/src/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ export function GalleryCard({
<IconButton
icon={script}
label="Open code"
onClick={() => {
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
loadDemo(item, true);
return false;
}}
className="open-code-btn"
/>
Expand Down