-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from edgeandnode/piotr/copy-url
Copy query ID to URL on "Share" click
- Loading branch information
Showing
6 changed files
with
78 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const QUERY_SEARCH_PARAMS_KEY = 'playgroundQuery' | ||
|
||
export function createQuerySharingURL(queryId: string | number): string { | ||
const url = new URL(window.location.href) | ||
url.searchParams.set(QUERY_SEARCH_PARAMS_KEY, queryId.toString()) | ||
return url.toString() | ||
} | ||
|
||
export function pluckQueryIdFromUrl(): string | null { | ||
const url = new URL(window.location.href) | ||
const queryId = url.searchParams.get(QUERY_SEARCH_PARAMS_KEY) | ||
|
||
if (queryId) { | ||
// This is in `setTimeout` because React runs `useEffect` twice in dev mode. | ||
setTimeout(() => { | ||
if (window.location.href === url.toString()) { | ||
url.searchParams.delete(QUERY_SEARCH_PARAMS_KEY) | ||
window.history.replaceState({}, '', url.toString()) | ||
} | ||
}, 50) | ||
|
||
return queryId | ||
} | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters