Skip to content

Commit b81911a

Browse files
committed
don't rerun sandcastle when switching to code
1 parent ca5cc21 commit b81911a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

packages/sandcastle/src/App.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,11 @@ function App() {
505505
hidden={leftPanel !== "gallery"}
506506
galleryItems={galleryItems}
507507
loadDemo={(item, switchToCode) => {
508-
// Load the gallery item every time it's clicked
509-
loadGalleryItem(item.id);
510-
511508
const searchParams = new URLSearchParams(window.location.search);
512-
if (
513-
!searchParams.has("id") ||
514-
(searchParams.has("id") && searchParams.get("id") !== item.id)
515-
) {
509+
const isAlreadyActive =
510+
searchParams.has("id") && searchParams.get("id") === item.id;
511+
512+
if (!isAlreadyActive) {
516513
// only push state if it's not the current url to prevent duplicated in history
517514
window.history.pushState(
518515
{},
@@ -522,7 +519,13 @@ function App() {
522519
}
523520

524521
if (switchToCode) {
522+
if (!isAlreadyActive) {
523+
loadGalleryItem(item.id);
524+
}
525525
setLeftPanel("editor");
526+
} else {
527+
// Load the gallery item every time it's clicked ro act as a "rerun" button
528+
loadGalleryItem(item.id);
526529
}
527530
}}
528531
/>

packages/sandcastle/src/Gallery.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,11 @@ export function GalleryCard({
206206
<IconButton
207207
icon={script}
208208
label="Open code"
209-
onClick={() => {
209+
onClick={(e) => {
210+
e.preventDefault();
211+
e.stopPropagation();
210212
loadDemo(item, true);
213+
return false;
211214
}}
212215
className="open-code-btn"
213216
/>

0 commit comments

Comments
 (0)