From cef64e708810186eaaf6b77604a0ba4ad452e5d6 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Mon, 29 Sep 2025 16:58:25 +0530 Subject: [PATCH 1/2] Set sharing URL in notebooks on first share --- src/index.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/index.ts b/src/index.ts index 2d13bd17..1bc13ed0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,6 +44,19 @@ function generateShareURL(notebookID: string): string { return `${baseUrl}?notebook=${notebookID}`; } +/** + * Sets or updates the 'notebook' query parameter in the current URL to the given notebookID. + * If the parameter already exists with the same value, no change is made. + * @param notebookID - The ID of the notebook to set in the URL. + */ +function setNotebookParamInUrl(notebookID: string): void { + const url = new URL(window.location.href); + if (url.searchParams.get('notebook') !== notebookID) { + url.searchParams.set('notebook', notebookID); + window.history.replaceState({}, '', url.toString()); + } +} + const manuallySharing = new WeakSet(); /** @@ -134,6 +147,17 @@ async function handleNotebookSharing( notebookPanel.context.model.fromJSON(notebookContent); await notebookPanel.context.save(); + + try { + const newReadable = + (notebookContent.metadata?.readableId as string | undefined) ?? + (notebookContent.metadata?.sharedId as string | undefined); + if (newReadable) { + setNotebookParamInUrl(newReadable); + } + } catch (e) { + console.warn('Failed to update URL with shareable notebook ID:', e); + } } if (manual) { From f3c1b6e1413c2d1ddbc341d9c77396374ce048d9 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Mon, 29 Sep 2025 17:58:27 +0530 Subject: [PATCH 2/2] Change variable name `newReadable` to `notebookID` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MichaƂ Krassowski <5832902+krassowski@users.noreply.github.com> --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1bc13ed0..58d87b3d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -149,11 +149,11 @@ async function handleNotebookSharing( await notebookPanel.context.save(); try { - const newReadable = + const notebookID = (notebookContent.metadata?.readableId as string | undefined) ?? (notebookContent.metadata?.sharedId as string | undefined); - if (newReadable) { - setNotebookParamInUrl(newReadable); + if (notebookID) { + setNotebookParamInUrl(notebookID); } } catch (e) { console.warn('Failed to update URL with shareable notebook ID:', e);