-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move addToURL to client side code
- Loading branch information
Showing
4 changed files
with
28 additions
and
23 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,25 @@ | ||
'use client'; | ||
|
||
export const addToUrl = (key: string, value: string) => { | ||
try { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
searchParams.set(key, value); | ||
const newUrl = `${window.location.pathname}?${searchParams.toString()}`; | ||
window.history.pushState({}, '', newUrl); | ||
} catch (error) { | ||
console.log('Error adding to url', error); | ||
} | ||
}; | ||
|
||
export const copyToClipboard = async (textToCopy: string) => { | ||
if ('clipboard' in navigator) { | ||
return await navigator.clipboard.writeText(textToCopy); | ||
} else { | ||
return document.execCommand('copy', true, textToCopy); | ||
} | ||
}; | ||
|
||
export const getFromUrl = (key: string) => { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
return searchParams.get(key); | ||
}; |
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