Skip to content
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

Fix GetLink-Tutorial-Playground-state issue 1558 #1855

Merged
merged 7 commits into from
Aug 27, 2024
12 changes: 6 additions & 6 deletions playground/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@ export function Editor(props: {
try {
const encodedCode = await codeToCompressedBase64(code);
const escapedCode = encodeURIComponent(encodedCode);
// Get current URL without query parameters to use as the base URL
const newUrl = `${
window.location.href.split("?")[0]
}?code=${escapedCode}&profile=${profile}`;
// Update or add the current URL parameters 'code' and 'profile'
const newURL = new URL(window.location.href);
newURL.searchParams.set("code", escapedCode);
newURL.searchParams.set("profile", profile);

// Copy link to clipboard and update url without reloading the page
navigator.clipboard.writeText(newUrl);
navigator.clipboard.writeText(newURL.toString());

window.history.pushState({}, "", newUrl);
window.history.pushState({}, "", newURL.toString());
messageText = "Link was copied to the clipboard";
} finally {
const popup = document.getElementById("popup") as HTMLDivElement;
Expand Down
11 changes: 6 additions & 5 deletions playground/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ function App(props: { katas: Kata[]; linkedCode?: string }) {

function onNavItemSelected(name: string) {
// If there was a ?code link on the URL before, clear it out
const params = new URLSearchParams(window.location.search);
if (params.get("code")) {
// Get current URL without query parameters to use as the URL
const newUrl = `${window.location.href.split("?")[0]}`;
window.history.pushState({}, "", newUrl);
const newURL = new URL(window.location.href);
if (newURL.searchParams.get("code")) {
newURL.searchParams.delete("code");
newURL.searchParams.delete("profile");
window.history.pushState({}, "", newURL.toString());
props.linkedCode = undefined;
}
setCurrentNavItem(name);
}
Expand Down
Loading