add encode/decode uri component

This commit is contained in:
lamacchinadesiderante 2023-01-11 13:02:28 +01:00
parent 5272e13f45
commit 9f01f63326
1 changed files with 4 additions and 3 deletions

View File

@ -49,7 +49,7 @@ const Search: React.FC<SearchProps> = ({ setBooks }) => {
const [showLanguageDropdown, setShowLanguageDropdown] = useState<boolean>(true) const [showLanguageDropdown, setShowLanguageDropdown] = useState<boolean>(true)
useEffect(() => { useEffect(() => {
const params = new Proxy(new URLSearchParams(window.location.search), { const params = new Proxy(new URLSearchParams(decodeURIComponent(window.location.search)), {
//@ts-ignore //@ts-ignore
get: (searchParams, prop) => searchParams.get(prop), get: (searchParams, prop) => searchParams.get(prop),
}); });
@ -94,9 +94,10 @@ const Search: React.FC<SearchProps> = ({ setBooks }) => {
} }
const copyToClipboard = () => { const copyToClipboard = () => {
const searchQuery = `${window.location.host}?title=${title}&author=${author}&language=${language}&publisher=${publisher}&isbn=${isbn}&extension=${extension}`; const searchBase = `${window.location.host}/?`;
const searchQuery = encodeURIComponent(`title=${title}&author=${author}&language=${language}&publisher=${publisher}&isbn=${isbn}&extension=${extension}`)
navigator.clipboard.writeText(searchQuery).then(() => { navigator.clipboard.writeText(`${searchBase}${searchQuery}`).then(() => {
//console.log('Async: Copying to clipboard was successful!'); //console.log('Async: Copying to clipboard was successful!');
}, (err) => { }, (err) => {
//console.error('Async: Could not copy text: ', err); //console.error('Async: Could not copy text: ', err);