Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions web/packages/demo/src/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export function Navbar({
onSelectUrl(url, {});
setSelectedFilename(null);
setSelectedSample(null);
window.history.replaceState(
null,
"",
`${window.location.pathname}${window.location.hash}`,
);
if (sampleSelectionInput.current) {
sampleSelectionInput.current.selectedIndex = -1;
}
Expand All @@ -62,6 +67,7 @@ export function Navbar({
onSelectFile(file);
setSelectedSample(null);
setSelectedFilename(file.name);
window.history.replaceState(null, "", window.location.pathname);
if (sampleSelectionInput.current) {
sampleSelectionInput.current.selectedIndex = -1;
}
Expand Down
34 changes: 31 additions & 3 deletions web/packages/demo/src/navbar/samples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export function SampleSelection({
const index = parseInt(eventTarget.value, 10);
if (availableSamples[index]) {
loadSample(availableSamples[index]);
window.history.replaceState(
null,
"",
`${window.location.pathname}?file=${availableSamples[index].location}`,
);
}
};

Expand All @@ -63,15 +68,38 @@ export function SampleSelection({
const response = await fetch("swfs.json");

if (response.ok) {
const data: { swfs: [DemoSwf] } = await response.json();
const data: { swfs: DemoSwf[] } = await response.json();
setAvailableSamples(data.swfs);

if (data.swfs.length > 0) {
loadSample(data.swfs[0]);
const params = new URLSearchParams(window.location.search);
const fileParam = params.get("file");

let sampleIndex = 0;

if (fileParam) {
sampleIndex = data.swfs.findIndex(
(swf) =>
swf.location === fileParam ||
swf.location.replace(/^swfs\//, "") ===
fileParam,
Comment on lines +83 to +85
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have this duality here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if we'd want ?file=bitey1.swf, this lets it work. That was the real path to the SWF 5 years ago, but now it's swfs/bitey1.swf

Copy link
Member

Choose a reason for hiding this comment

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

Can't we just remove the swfs/ prefix and make it work the same way as before?

);
if (sampleIndex === -1) {
sampleIndex = 0;
}
}

loadSample(data.swfs[sampleIndex]);
requestAnimationFrame(() => {
if (sampleSelectionInput.current) {
sampleSelectionInput.current.selectedIndex =
sampleIndex;
}
});
}
}
})();
}, [loadSample]);
}, [loadSample, sampleSelectionInput]);

return (
<div
Expand Down